Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 8, 2020 19:20
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/51af34cddde668155d3680025a8302e5 to your computer and use it in GitHub Desktop.
Save parzibyte/51af34cddde668155d3680025a8302e5 to your computer and use it in GitHub Desktop.
// Devuelve el número de minas que hay cercanas en determinada coordenada
int obtenerMinasCercanas(int fila, int columna, char tablero[FILAS][COLUMNAS]) {
int conteo = 0, filaInicio, filaFin, columnaInicio, columnaFin;
if (fila <= 0) {
filaInicio = 0;
} else {
filaInicio = fila - 1;
}
if (fila + 1 >= FILAS) {
filaFin = FILAS - 1;
} else {
filaFin = fila + 1;
}
if (columna <= 0) {
columnaInicio = 0;
} else {
columnaInicio = columna - 1;
}
if (columna + 1 >= COLUMNAS) {
columnaFin = COLUMNAS - 1;
} else {
columnaFin = columna + 1;
}
int m;
for (m = filaInicio; m <= filaFin; m++) {
int l;
for (l = columnaInicio; l <= columnaFin; l++) {
if (tablero[m][l] == MINA) {
conteo++;
}
}
}
return conteo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment