Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 8, 2020 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/954a5dc4b3199a70b033de4c7f2c8944 to your computer and use it in GitHub Desktop.
Save parzibyte/954a5dc4b3199a70b033de4c7f2c8944 to your computer and use it in GitHub Desktop.
// Recibe la fila, columna y tablero. La fila y columna deben ser tal y como las
// proporciona el usuario. Es decir, la columna debe comenzar en 1 (no en cero
// como si fuera un índice) y la fila debe ser una letra
int abrirCasilla(char filaLetra, int columna, char tablero[FILAS][COLUMNAS]) {
// Convertir a mayúscula
filaLetra = toupper(filaLetra);
// Restamos 1 porque usamos la columna como índice
columna--;
// Convertimos la letra a índice
int fila = filaLetra - 'A';
assert(columna < COLUMNAS && columna >= 0);
assert(fila < FILAS && fila >= 0);
if (tablero[fila][columna] == MINA) {
return ERROR_MINA_ENCONTRADA;
}
if (tablero[fila][columna] == ESPACIO_DESCUBIERTO) {
return ERROR_ESPACIO_YA_DESCUBIERTO;
}
// Si no hay error, colocamos el espacio descubierto
tablero[fila][columna] = ESPACIO_DESCUBIERTO;
return ERROR_NINGUNO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment