-
-
Save parzibyte/193514e1de871a40ca4b444509da238e 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
/* | |
Funciones de conteo. Simplemente cuentan cuántas piezas del mismo jugador están | |
alineadas | |
*/ | |
static int contarHaciaArriba(int x, int y, char jugador, char[][] tablero) { | |
int yInicio = (y - CONTEO_PARA_GANAR >= 0) ? y - CONTEO_PARA_GANAR + 1 : 0; | |
int contador = 0; | |
for (; yInicio <= y; yInicio++) { | |
if (tablero[yInicio][x] == jugador) { | |
contador++; | |
} else { | |
contador = 0; | |
} | |
} | |
return contador; | |
} | |
static int contarHaciaDerecha(int x, int y, char jugador, char[][] tablero) { | |
int xFin = (x + CONTEO_PARA_GANAR < COLUMNAS) ? x + CONTEO_PARA_GANAR - 1 : COLUMNAS - 1; | |
int contador = 0; | |
for (; x <= xFin; x++) { | |
if (tablero[y][x] == jugador) { | |
contador++; | |
} else { | |
contador = 0; | |
} | |
} | |
return contador; | |
} | |
static int contarHaciaArribaDerecha(int x, int y, char jugador, char[][] tablero) { | |
int xFin = (x + CONTEO_PARA_GANAR < COLUMNAS) ? x + CONTEO_PARA_GANAR - 1 : COLUMNAS - 1; | |
int yInicio = (y - CONTEO_PARA_GANAR >= 0) ? y - CONTEO_PARA_GANAR + 1 : 0; | |
int contador = 0; | |
while (x <= xFin && yInicio <= y) { | |
if (tablero[y][x] == jugador) { | |
contador++; | |
} else { | |
contador = 0; | |
} | |
x++; | |
y--; | |
} | |
return contador; | |
} | |
static int contarHaciaAbajoDerecha(int x, int y, char jugador, char[][] tablero) { | |
int xFin = (x + CONTEO_PARA_GANAR < COLUMNAS) ? x + CONTEO_PARA_GANAR - 1 : COLUMNAS - 1; | |
int yFin = (y + CONTEO_PARA_GANAR < FILAS) ? y + CONTEO_PARA_GANAR - 1 : FILAS - 1; | |
int contador = 0; | |
while (x <= xFin && y <= yFin) { | |
if (tablero[y][x] == jugador) { | |
contador++; | |
} else { | |
contador = 0; | |
} | |
x++; | |
y++; | |
} | |
return contador; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment