Example #1
0
 /** Decides whether the {@link #getCurrentPlayer()} is defeated or not. */
 void checkIfCurrentPlayerIsDefeated() {
   Client client = getCurrentPlayer();
   if (client.isDefeated()) return;
   // If the king is checked, go through all active figures and check if we can do any moves.
   // If we can't do any moves the player is defeated
   if (isKingChecked(client.getId())
       && getFigures()
               .stream()
               // Just the players figures
               .filter(hexagonFigure -> hexagonFigure.getClient().getId().equals(client.getId()))
               // Just non removed figures
               .filter(hexagonFigure -> !hexagonFigure.isRemoved())
               // Change type to a list of hexagon
               .map(hexagonFigure -> hexagonFigure.getPossibleMovements(this))
               // Convert list of list of hexagon to list of hexagon
               .flatMap(Collection::stream)
               .count()
           == 0) client.setDefeated(true);
 }