bool Board::IsCheck(Color side) { Moves* moves = new Moves(); int j = 0; for (int i = 0; i < BoardSize * BoardSize; i++) { if (this->Chesses[i] != NULL && this->Chesses[i]->GetPlayer()->GetSide() == side) this->Chesses[i]->GetAvailableMoves(this, moves, true); for (; j < moves->GetLength(); j++) { Move* move = moves->GetMove(j); Chess* captured = move->GetChessCaptured(); if (captured != NULL && captured->GetChessType() == King) { delete moves; return true; } } } delete moves; return false; }
bool Board::HasMove(Color side) { Moves* moves = this->GetAllAvailableMoves(side); bool has_move = moves->GetLength() > 0; delete moves; return has_move; }
bool Board::IsCheckmate(Color side) { if (!this->IsCheck(side)) { return false; } Color opponent = side == White ? Black : White; Moves* moves = this->GetAllAvailableMoves(opponent); bool checkmate = moves->GetLength() == 0; delete moves; return checkmate; }
void PlayerAI1::RequestMove() { Moves* moves = this->Game->CurrentBoard->GetAllAvailableMoves(this->Side); srand (time(NULL)); int index = rand() % moves->GetLength(); Move* move = moves->GetMove(index); Chess* before = move->GetChessBeforeMove(); Chess* after = move->GetChessAfterMove(); this->Game->MakeMove(before->GetX(), before->GetY(), after->GetX(), after->GetY(), after->GetChessType()); delete moves; CheckDraw(); }