コード例 #1
0
 public String getInfo() {
   chessboard.evaluateBoard();
   info =
       "W:"
           + String.valueOf(chessboard.whiteTotalValue)
           + " B: "
           + String.valueOf(chessboard.blackTotalValue);
   return info;
 }
コード例 #2
0
 public boolean isLegalTarget(int row, int column) {
   if (!blackIsTop) {
     row = 7 - row;
     column = 7 - column;
   }
   if (startOpponentsMove) return false;
   if (!isPieceSelected) return false;
   if (selectedPieceColumn == column && selectedPieceRow == row) return false;
   if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column)) return true;
   return false;
 }
コード例 #3
0
 public String getOpacity(int row, int column) {
   if (!blackIsTop) {
     row = 7 - row;
     column = 7 - column;
   }
   if (startOpponentsMove) return "opacity:0.7";
   if (!isPieceSelected) return "opacity:1.0";
   if (selectedPieceColumn == column && selectedPieceRow == row) return "opacity:1.0";
   if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column))
     return "opacity:1.0";
   return "opacity:1.0";
 }
コード例 #4
0
 public String getBorder(int row, int column) {
   if (!blackIsTop) {
     row = 7 - row;
     column = 7 - column;
   }
   if (startOpponentsMove) return "border:1px solid black";
   if (!isPieceSelected) return "border:1px solid black";
   if (selectedPieceColumn == column && selectedPieceRow == row) return "border: 2px solid blue;";
   if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column))
     return "border: 2px solid red;";
   return "border: 1px solid black";
 }
コード例 #5
0
  public void onclick(int row, int column) {
    if (endOfGame) {
      FacesMessage fm =
          new FacesMessage(FacesMessage.SEVERITY_INFO, "", "The game is already over.");
      FacesContext.getCurrentInstance().addMessage(null, fm);
    } else {
      if (!blackIsTop) {
        row = 7 - row;
        column = 7 - column;
      }
      if (isPieceSelected) {
        isPieceSelected = false;
        // chessboard.findLegalMovesIgnoringCheck(); // debug
        if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column)) {
          int piece = chessboard.getChessPiece(selectedPieceRow, selectedPieceColumn);
          int capturedPiece = chessboard.getChessPiece(row, column);

          chessboard =
              chessboard.moveChessPiece(
                  selectedPieceRow, selectedPieceColumn, row, column, ChessConstants.W_QUEEN);
          boolean chess = chessboard.isWhiteKingThreatened || chessboard.isBlackKingThreatened;
          Move m =
              new Move(
                  piece,
                  selectedPieceRow,
                  selectedPieceColumn,
                  row,
                  column,
                  Chessboard.s_MATERIAL_VALUE[1] - Chessboard.s_MATERIAL_VALUE[0],
                  chess,
                  capturedPiece > ChessConstants.W_EMPTY,
                  capturedPiece);
          info = m.toString();
          String move = m.getNotation();
          if (history.size() % 2 == 0) {
            move = String.valueOf((history.size() / 2) + 1) + ". " + move;
          }
          history.add(move);
          selectedPieceRow = 0;
          selectedPieceColumn = 0;
          // opponentsMove();
          startOpponentsMove = true;
        }

      } else {
        int piece = chessboard.getChessPiece(row, column);
        if (piece != ChessConstants.B_EMPTY && piece != ChessConstants.W_EMPTY) {
          if (chessboard.isActivePlayersPiece(piece)) {
            isPieceSelected = true;
            selectedPieceRow = row;
            selectedPieceColumn = column;
          }
        }
      }
    }
    redraw();
  }
コード例 #6
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();
 }