示例#1
0
 public String getTitle() {
   if (endOfGame) {
     if (gameOverException instanceof WhiteIsCheckMateException) return "White is checkmate!";
     if (gameOverException instanceof BlackIsCheckMateException) return "Black is checkmate!";
     if (gameOverException instanceof StaleMateException) return "Stalemate!";
     return "Game over. " + gameOverException.getClass().getSimpleName();
   } else if (startOpponentsMove) return "Calculating next move...";
   else return "Waiting for your move";
 }
示例#2
0
 public void opponentsMove(ActionEvent event) {
   if (endOfGame) {
     FacesMessage fm =
         new FacesMessage(FacesMessage.SEVERITY_INFO, "", "The game is already over.");
     FacesContext.getCurrentInstance().addMessage(null, fm);
     startOpponentsMove = false;
   } else {
     if (startOpponentsMove) {
       startOpponentsMove = false;
       try {
         Move m = chessboard.findBestMove();
         String move = m.getNotation();
         if (history.size() % 2 == 0) {
           move = String.valueOf((history.size() / 2) + 1) + ". " + move;
         }
         history.add(move);
         info = move.toString();
         chessboard =
             chessboard.moveChessPiece(
                 m.fromRow, m.fromColumn, m.toRow, m.toColumn, ChessConstants.W_QUEEN);
       } catch (EndOfGameException e) {
         FacesMessage fm =
             new FacesMessage(FacesMessage.SEVERITY_INFO, "", "The game is already over.");
         FacesContext.getCurrentInstance().addMessage(null, fm);
         endOfGame = true;
         gameOverException = e;
         info = e.getClass().getSimpleName();
       }
       elapsedTime = ((Chessboard.realTimeOfCalculation / 1000) / 1000.0d) + "ms";
       cpuTime = ((Chessboard.totalTime / 1000) / 1000) + " ms";
       evaluatedMoves = NumberFormat.getInstance().format(Chessboard.evaluatedPositions);
       averageEvaluation = Chessboard.totalTime / chessboard.evaluatedPositions + " ns";
     }
   }
   redraw();
 }