示例#1
0
文件: Board.cpp 项目: Martin1994/pp9k
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;
}
示例#2
0
文件: Board.cpp 项目: Martin1994/pp9k
bool Board::HasMove(Color side)
{
    Moves* moves = this->GetAllAvailableMoves(side);
    
    bool has_move = moves->GetLength() > 0;
    
    delete moves;
    
    return has_move;
}
示例#3
0
文件: Board.cpp 项目: Martin1994/pp9k
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;
}
示例#4
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();
}