Hi, I am currently working on a chess game, and I am almost done, but all I need to do at the moment is to check my board to see if there are two kings left on the board, so if there is only 1 king left on the board the game is over. I currently have this:
bool Board::stillTwoKings () const
{
for (int col = 0; col < BOARD_HEIGHT; col++)
{
for (int row = 0; row < BOARD_WIDTH; row++)
{
if(board[col][row] == 'K' && board[col][row] == 'k')
cout << "YOUR GAME HAS ENDED" << endl;
}
}
return true;
But it is not working.. I keep trying different things, and I don't know how to cast the thing right... I was wondering if anyone could lead me to the right way? Thank you :)
The easiest way is to count the number of kings on the board. After the loops, if the count is less than 2, then
the game is over. A square has a king iff the square is 'K' OR the square is 'k'.
As Helios said, the King doesn't get taken anyway. Checkmate occurs by one player surrounding the enemy King such that he can't, again as Helios said, move without entering check.