Created
July 12, 2020 01:00
-
-
Save parzibyte/2d9b3c8c86d3f49a22e3518154b9d441 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
/* | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
____________________________________ | |
/ Si necesitas ayuda, contáctame en \ | |
\ https://parzibyte.me / | |
------------------------------------ | |
\ ^__^ | |
\ (oo)\_______ | |
(__)\ )\/\ | |
||----w | | |
|| || | |
Creado por Parzibyte (https://parzibyte.me). Este encabezado debe mantenerse intacto, | |
excepto si este es un proyecto de un estudiante. | |
*/ | |
#include "conecta4.h" | |
#include <stdio.h> | |
int obtenerFilaDesocupada(int columna, char tablero[FILAS][COLUMNAS]) { | |
int i; | |
for (i = FILAS - 1; i >= 0; i--) { | |
if (tablero[i][columna] == ESPACIO_VACIO) { | |
return i; | |
} | |
} | |
return FILA_NO_ENCONTRADA; | |
} | |
int colocarPieza(char jugador, int columna, char tablero[FILAS][COLUMNAS]) { | |
if (columna < 0 || columna >= COLUMNAS) { | |
return ERROR_FILA_INVALIDA; | |
} | |
int fila = obtenerFilaDesocupada(columna, tablero); | |
if (fila == FILA_NO_ENCONTRADA) { | |
return ERROR_COLUMNA_LLENA; | |
} | |
tablero[fila][columna] = jugador; | |
return ERROR_NINGUNO; | |
} | |
void limpiarTablero(char tablero[FILAS][COLUMNAS]) { | |
int i; | |
for (i = 0; i < FILAS; ++i) { | |
int j; | |
for (j = 0; j < COLUMNAS; ++j) { | |
tablero[i][j] = ESPACIO_VACIO; | |
} | |
} | |
} | |
void dibujarEncabezado(int columnas) { | |
printf("\n"); | |
int i; | |
for (i = 0; i < columnas; ++i) { | |
printf("|%d", i + 1); | |
if (i + 1 >= columnas) { | |
printf("|"); | |
} | |
} | |
} | |
int dibujarTablero(char tablero[FILAS][COLUMNAS]) { | |
dibujarEncabezado(COLUMNAS); | |
printf("\n"); | |
int i; | |
for (i = 0; i < FILAS; ++i) { | |
int j; | |
for (j = 0; j < COLUMNAS; ++j) { | |
printf("|%c", tablero[i][j]); | |
if (j + 1 >= COLUMNAS) { | |
printf("|"); | |
} | |
} | |
printf("\n"); | |
} | |
return 0; | |
} | |
int esEmpate(char tablero[FILAS][COLUMNAS]) { | |
int i; | |
for (i = 0; i < COLUMNAS; ++i) { | |
int resultado = obtenerFilaDesocupada(i, tablero); | |
if (resultado != FILA_NO_ENCONTRADA) { | |
return 0; | |
} | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment