Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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();
}