After a move has been made, the Gamemaster checks all pieces to see if both players have legal moves. If either player has no legal moves, the opponent wins.
``
for(int file = 0; file < 8; file++) {
for (int rank = 0; rank < 8; rank++) {
Piece temp = board[rank][file]; //Gets piece at location
if (temp == null) {continue;} //No piece here
//Stops redundant checks, only one legal move needs to be found
if (temp.white && whiteLegalMove) {continue;}
if (!temp.white && blackLegalMove) {continue;}
if (temp.white) { whiteLegalMove = !temp.getLegalMoves(board).isEmpty();}
else {blackLegalMove = !temp.getLegalMoves(board).isEmpty();}
if (whiteLegalMove && blackLegalMove) {break;} //stops searching when legal moves have been found
}
if (whiteLegalMove && blackLegalMove) {break;} //Can only break one loop at a time, and there is two. Forgive the repetition
}
``
There are plenty of checks to ensure this only repeats as far as it needs to.
When a player is found to have won, all connected clients are sent the WIN packet. This packet contains the winning player.
Players can now win the game.
After a move has been made, the Gamemaster checks all pieces to see if both players have legal moves. If either player has no legal moves, the opponent wins.
``
``
There are plenty of checks to ensure this only repeats as far as it needs to.
When a player is found to have won, all connected clients are sent the WIN packet. This packet contains the winning player.