Created
June 8, 2020 19:20
-
-
Save parzibyte/51af34cddde668155d3680025a8302e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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