Finding 2 Kings in the Chess Game

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 :)
Your && is incorrect, assuming board is a 2d array of chars, then it can't possibly be 'k' *and* 'K' at the same time.
Kings are never captured. The game ends when the king can't move in any direction without entering check.
helios: Well in my case we don't have to check if it is in check we have to capture the king for the game to end.. so I don't know what to do..

firedraco: would it make a difference if I used ||?
Last edited on
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.
cannot move without entering check = stalemate (tie)
cannot move without ESCAPING check = checkmate (lose)
Topic archived. No new replies allowed.