Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active February 2, 2021 05:17
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/a6f7c721f4bff2f957d917d633a5078e to your computer and use it in GitHub Desktop.
Save parzibyte/a6f7c721f4bff2f957d917d633a5078e to your computer and use it in GitHub Desktop.
static int contarArriba(int x, int y, string jugador, string[,] tablero)
{
int yInicio = (y - CONECTA >= 0) ? y - CONECTA + 1 : 0;
int contador = 0;
for (; yInicio <= y; yInicio++)
{
if (tablero[yInicio, x] == jugador)
{
contador++;
}
else
{
contador = 0;
}
}
return contador;
}
static int contarDerecha(int x, int y, string jugador, string[,] tablero)
{
int xFin = (x + CONECTA < COLUMNAS) ? x + CONECTA - 1 : COLUMNAS - 1;
int contador = 0;
for (; x <= xFin; x++)
{
if (tablero[y, x] == jugador)
{
contador++;
}
else
{
contador = 0;
}
}
return contador;
}
static int contarArribaDerecha(int x, int y, string jugador, string[,] tablero)
{
int xFin = (x + CONECTA < COLUMNAS) ? x + CONECTA - 1 : COLUMNAS - 1;
int yInicio = (y - CONECTA >= 0) ? y - CONECTA + 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 contarAbajoDerecha(int x, int y, string jugador, string[,] tablero)
{
int xFin = (x + CONECTA < COLUMNAS) ? x + CONECTA - 1 : COLUMNAS - 1;
int yFin = (y + CONECTA < FILAS) ? y + CONECTA - 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