Examen TPOO 3
unknown
c_cpp
2 months ago
4.5 kB
4
Indexable
#include <iostream> using namespace std; void Desplegar(char F [8][8]){ int A = 8; for (int i = 0; i<8; i++){ cout << A<< " "; A--; for(int j = 0; j<8; j++){ cout<<F[i][j]<< " "; } cout<<endl; } cout<<" A B C D E F G H"<< endl; } bool Final (char F [8][8],char C [8][8]){ int Rey = 0; for (int i = 0; i<8; i++){ for(int j = 0; j<8; j++){ if (F[i][j]=='R' && C[i][j]=='N') Rey++; if (F[i][j]=='R' && C[i][j]=='B') Rey++; } } cout<< "Reysss: "<<Rey<<endl; if (Rey == 2) return true; else return false; } void Trans(char& x1, char& x2, char& y1, char& y2){ char Letras[8]= {'A','B','C','D','E','F','G','H'}; int Num [8]= {'8','7','6','5','4','3','2','1'}; cout << x1 << y1 << x2 << y2 << endl; for(int i = 0; i<8; i++){ if(x1 == Letras[i]){ x1 = i + 48; break; } } for(int i = 0; i<8; i++){ if(x2 == Letras[i]){ x2 = i + 48; break; } } for(int i = 0; i<8; i++){ if(y1 == Num[i]){ y1 = i + 48; break; } } for(int i = 0; i<8; i++){ if(y2 == Num[i]){ y2 = i + 48; break; } } cout << x1 << y1 <<" "<< x2 << y2 << endl; return; } void Mover(char F [8][8],char C [8][8], bool B){ char x1, x2, y1, y2; while (true){ do{ cout << "Ingrese el valor (A al H) de la ficha que quiere mover"<<endl; cin>> x1; cout << "Ingrese el valor (8 al 1) de la ficha que quiere mover"<<endl; cin>> y1; cout << "Ingrese el valor (A al H) de la posicion a donde va la ficha"<<endl; cin>> x2; cout << "Ingrese el valor (8 al 1) de la posicion a donde va la ficha"<<endl; cin>> y2; }while('A'>x1 || x1>'H' || '1'>y1 || y1>'8' || 'A'>x2 || x2>'H' || '1'>y2 || y2>'8' ); Trans(x1,x2,y1,y2); int X1 = x1 - 48, X2 = x2 - 48, Y1 = y1 - 48, Y2 = y2 - 48; if (B){ cout << Y1 << X1 <<" "<< Y2 << X2 << endl; cout<<F[Y1][X1]<<C[Y1][X1]<<" "<< F[Y2][X2]<< C[Y2][X2]<< endl; if(C[Y1][X1] == 'B'){ cout<< "Si era una Blanca"<<endl; if (C[Y2][X2]!='B'){ cout<< "Se puede mover"<<endl; F[Y2][X2] = F[Y1][X1]; F[Y1][X1] = ' '; C[Y2][X2] = C[Y1][X1]; C[Y1][X1] = 'O'; break; } } } else{ if(C[Y1][X1] == 'N'){ cout<< "Si era Negra"<<endl; if (C[Y2][X2]!='N'){ cout<< "Se puede mover"<<endl; F[Y2][X2] = F[Y1][X1]; F[Y1][X1] = ' '; C[Y2][X2] = C[Y1][X1]; C[Y1][X1] = 'O'; break; } } } } return; } int main() { char Figura [8][8]={{'T','C','A','M','R','A','C','T'}, {'P','P','P','P','P','P','P','P'}, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' '}, {'P','P','P','P','P','P','P','P'}, {'T','C','A','M','R','A','C','T'}}; char Color [8][8] ={{'N','N','N','N','N','N','N','N'}, {'N','N','N','N','N','N','N','N'}, {'O','O','O','O','O','O','O','O'}, {'O','O','O','O','O','O','O','O'}, {'O','O','O','O','O','O','O','O'}, {'O','O','O','O','O','O','O','O'}, {'B','B','B','B','B','B','B','B'}, {'B','B','B','B','B','B','B','B'}}; Desplegar(Figura); bool Blanco = true; bool final = true; while(final){ Mover(Figura,Color,Blanco); Desplegar(Figura); Blanco = !Blanco; final = Final(Figura,Color); } return 0; }
Editor is loading...
Leave a Comment