#include "./include/chessboard.h" ChessBoard::ChessBoard() { for (int rank=0; rank<8; rank++){ /*populate all the pawns on the white side *by going into a loop as long as the rank *value is 1 */ while (rank==1){ pieces[file][rank]->new Pawn(rank, file, &this, WHITE, 0); } /*populate all the pieces of the white side that go in the * first rank by entering a loop as long as the rank value * is 0 */ while (rank==0){ pieces[0][rank]->new Rook(rank,file,&this,WHITE,0); pieces[1][rank]->new Knight(rank,file,&this,WHITE,0); pieces[2][rank]->new Bishop(rank,file,&this,WHITE,0); pieces[3][rank]->new Queen(rank,file,&this,WHITE,0); pieces[4][rank]->new King(rank,file,&this,WHITE,0); pieces[5][rank]->new Bishop(rank,file,&this,WHITE,0); pieces[6][rank]->new Knight(rank,file,&this,WHITE,0); pieces[7][rank]->new Rook(rank,file,&this,WHITE,0); } /*populate all the pawns on the black side *by going into a loop as long as the rank *value is 1 */ while (rank==6) { pieces[file][rank]->new Pawn(rank,file,&this,BLACK,0); } /*populate all the pieces of the black side that go in the * first rank by entering a loop as long as the rank value * is 0 */ while (rank==7){ pieces[0][rank]->new Rook(rank,file,&this,BLACK,0); pieces[1][rank]->new Knight(rank,file,&this,BLACK,0); pieces[2][rank]->new Bishop(rank,file,&this,BLACK,0); pieces[3][rank]->new Queen(rank,file,&this,BLACK,0); pieces[4][rank]->new King(rank,file,&this,BLACK,0); pieces[5][rank]->new Bishop(rank,file,&this,BLACK,0); pieces[6][rank]->new Knight(rank,file,&this,BLACK,0); pieces[7][rank]->new Rook(rank,file,&this,BLACK,0); } } ChessBoard::ChessBoard(ChessBoard *b){ } ChessBoard::~ChessBoard() { //start a loop to sweep the whole board for(int file=0; file < Chess::BOARD_FILES; file++) { for(int rank=0; rank(*old_pos).transpose(m.getx2(), m.gety2()); lastMove = m; //save last move return true; } /*if the new position is not empty then: check if each piece is from *oposing sides if they are, move the pice if they are not, * throw an error */ if(new_pos!=NULL) { //check if each piece is from oposite side if(new_pos.getSide() != old_pos.getSide()){ delete pieces[m.gety1()][m.getx1()]; //delete old ChessPiece pieces[m.gety1()][m.getx1()] = NULL; //set old square to an empty value //make new square point no the modified ChessPiece object (pieces[m.gety2()][m.getx2()])->(*old_pos).transpose(m.getx2(), m.gety2()); lastMove = m; //save last move return true; } } //if all of the above fail then the move failes return false; } bool ChessBoard::inCheck (uint side) { } void ChessBoard::promote(uint rank, uint file) { ChessPiece *promot_piece = *pieces[file][rank]; //check that a pieces is actually in that square if(promote_piece == NULL) { return false;} //check that promoteType is a valide type if ((promoteType!= KING)||(promoteType!= QUEEN)||(promoteType!= BISHOP) ||(promoteType!= ROOK)||(promoteType!= KNIGHT)){ return false;} //check that it's actaully the right square if ( (rank !=0) || (rank !=7)){ return false;} //check that it's a valid piece to promote if ( promote_piece.getType() != Pawn) {return false;} //cast the current ChessPiece to a new subtype delete pieces[file][rank]; pieces[file][rank]->(promotoType)(promote_piece); return true; }