diff --git a/a.out b/a.out new file mode 100755 index 0000000..82e358f Binary files /dev/null and b/a.out differ diff --git a/tateti.cpp b/tateti.cpp index 93f7338..e9ac010 100644 --- a/tateti.cpp +++ b/tateti.cpp @@ -7,11 +7,17 @@ using namespace std; void imprimir_tateti(char matriz[N][N]); void marcar(char matriz[N][N], int x, int y, char marca); char comprobar_ganador(char m[N][N]); +void jugar(char tateti[N][N], char marca); + +int i = 0; +char turno = 97; int main(){ bool error_jugada = false; bool jugada_acabada = false; + char ficha[2] = {'X', 'O'}; + int bandera = false; @@ -22,138 +28,34 @@ int main(){ {' ', ' ', ' '} }; - //imprimir_tateti(tateti); - + cout << "Bienvenidos al TA-TE-TI de Pedro del Bootcamp 004 de Roshka" << endl; + + + while(i < 9){ - int i = 0; - char turno = 97; - while(i < 9){ - do{ - - cout << turno <<". X -> Ingrese jugada: "; - cin >> jugada; - - int a = jugada[0]; - int b = jugada[1]; - - a = a-64; //Para mapear a numeros del tablero - b = b-48; //Para lo mismo de arriba xd - //cout << a << endl; - //cout << b << endl; - - //Comprobación de la entrada - if((a<1 or a>3) and (b<1 or b>3)){ - error_jugada = true; - cout <<"> ERR: Jugada Inválida - Fila y Columna Inválidas" << endl; - }else if(a<1 or a>3){ - error_jugada = true; - cout <<"> ERR: Jugada Inválida - Fila Inválida" << endl; - } - else if(b<1 or b>3){ - error_jugada = true; - cout << "> ERR: Jugada Inválida - Columna Inválida" << endl; - }else if(tateti[a-1][b-1] != ' '){ - cout << "> ERR: Jugada Inválida - Casilla Ocupada" << endl; - error_jugada = true; - } - else{ - error_jugada = false; - marcar(tateti, a-1, b-1, 'X'); - cout << "> OK" << endl; - imprimir_tateti(tateti); - i++; - turno++; - } - - }while(error_jugada); + jugar(tateti, ficha[bandera]); + bandera = !bandera; char ganador = comprobar_ganador(tateti); - if(ganador != ' '){ - //cout << "GANADOR " << ganador << endl; - //cout << "FIN DEL JUEGO"; - break; - } - if(i == 9){ - cout << "> EMPATE" << endl; - break; - } - - do{ - - cout << turno <<". O -> Ingrese jugada: "; - cin >> jugada; - - int a = jugada[0]; - int b = jugada[1]; - - a = a-64; //Para mapear a numeros del tablero - b = b-48; //Para lo mismo de arriba xd - - //cout << a << endl; - //cout << b << endl; - - //Comprobación de la entrada - if((a<1 or a>3) and (b<1 or b>3)){ - error_jugada = true; - cout <<"> ERR: Jugada Inválida - Fila y Columna Inválidas" << endl; - }else if(a<1 or a>3){ - error_jugada = true; - cout <<"> ERR: Jugada Inválida - Fila Inválida" << endl; - } - else if(b<1 or b>3){ - error_jugada = true; - cout << "> ERR: Jugada Inválida - Columna Inválida" << endl; - }else if(tateti[a-1][b-1] != ' '){ - cout << "> ERR: Jugada Inválida - Casilla Ocupada" << endl; - error_jugada = true; - } - else{ - error_jugada = false; - marcar(tateti, a-1, b-1, 'O'); - cout << "> OK" << endl; - imprimir_tateti(tateti); - i++; - turno++; - } - - - }while(error_jugada); - - ganador = comprobar_ganador(tateti); - - if(ganador != ' '){ - //cout << "GANADOR " << ganador << endl; - //cout << "FIN DEL JUEGO"; break; } if(i == 9){ cout << "> EMPATE" << endl; break; - } - - + } } - - - //cout << "> EMPATE" << endl; + cout << "> FIN DEL JUEGO\n"; - - - - return 0; } - - - //Función que imprime en consola el tablero del tateti //Recibe como parámetro las coordenadas nuevas, si las hay //y la ficha que debe colocar @@ -256,7 +158,50 @@ char comprobar_ganador(char m[N][N]){ return m[2][0]; } - return ' '; + return ' '; +} + + + +void jugar(char tateti[N][N], char marca ){ + + string jugada; + bool error_jugada=false; + do{ + + cout << turno <<". " << marca <<" -> Ingrese jugada: "; + cin >> jugada; + + int a = jugada[0]; + int b = jugada[1]; + + a = a-64; //Para mapear a numeros del tablero + b = b-48; //Para lo mismo de arriba xd + + //Comprobación de la entrada + if((a<1 or a>3) and (b<1 or b>3)){ + error_jugada = true; + cout <<"> ERR: Jugada Inválida - Fila y Columna Inválidas" << endl; + }else if(a<1 or a>3){ + error_jugada = true; + cout <<"> ERR: Jugada Inválida - Fila Inválida" << endl; + } + else if(b<1 or b>3){ + error_jugada = true; + cout << "> ERR: Jugada Inválida - Columna Inválida" << endl; + }else if(tateti[a-1][b-1] != ' '){ + cout << "> ERR: Jugada Inválida - Casilla Ocupada" << endl; + error_jugada = true; + } + else{ + error_jugada = false; + marcar(tateti, a-1, b-1, marca); + cout << "> OK" << endl; + imprimir_tateti(tateti); + i++; + turno++; + } + + }while(error_jugada); - }