예제 #1
0
 /*
  * evalHigh
  *
  * This function evaluates the board according to the above spec. It
  * loops through all the pieces on the board and assigns two sums:
  * whiteSum and blackSum, for the value of white's and black's pieces,
  * respectively. Then it adds them and sets the sign according to whose
  * turn it is.
  */
 private int evalHigh(ArrayBoard board, int color) {
   if (color == ArrayBoard.WHITE) {
     int whiteSum = 0;
     if (board.hasCastled[ArrayBoard.WHITE]) whiteSum += CASTLE_BONUS;
     for (ArrayPiece p : board.allPiecesOfColor(ArrayBoard.WHITE)) {
       switch (p.type()) {
         case ArrayPiece.KING:
           whiteSum += kingval;
           break;
         case ArrayPiece.QUEEN:
           whiteSum += queenval;
           break;
         case ArrayPiece.ROOK:
           whiteSum += rookval;
           break;
         case ArrayPiece.BISHOP:
           whiteSum += bishoppos[p.row()][p.col()] + bishopval;
           break;
         case ArrayPiece.KNIGHT:
           whiteSum += knightpos[p.row()][p.col()] + knightval;
           break;
         case ArrayPiece.PAWN:
           whiteSum += pawnpos[p.row()][p.col()] + pawnval;
           break;
       }
     }
     return whiteSum;
   } else {
     int blackSum = 0;
     for (ArrayPiece p : board.allPiecesOfColor(ArrayBoard.BLACK)) {
       switch (p.type()) {
         case ArrayPiece.KING:
           blackSum += kingval;
           break;
         case ArrayPiece.QUEEN:
           blackSum += queenval;
           break;
         case ArrayPiece.ROOK:
           blackSum += rookval;
           break;
         case ArrayPiece.BISHOP:
           blackSum += bishoppos[7 - p.row()][p.col()] + bishopval;
           break;
         case ArrayPiece.KNIGHT:
           blackSum += knightpos[7 - p.row()][p.col()] + knightval;
           break;
         case ArrayPiece.PAWN:
           blackSum += pawnpos[7 - p.row()][p.col()] + pawnval;
           break;
       }
     }
     return blackSum;
   }
 }
예제 #2
0
  /*
   * evalLow
   *
   * This function evaluates the board according to the above spec,
   * but makes pieces more valuable. It also uses the kingpos array to
   * encourage the king to move towards the middle of the board.
   */
  private int evalLow(ArrayBoard board, int color) {

    if (color == ArrayBoard.WHITE) {
      int whiteSum = 0;
      if (board.hasCastled[ArrayBoard.WHITE]) whiteSum += CASTLE_BONUS;

      for (ArrayPiece p : board.allPiecesOfColor(ArrayBoard.WHITE)) {
        switch (p.type()) {
          case ArrayPiece.KING:
            whiteSum +=
                4
                    * (calculateWhiteKingWeight(
                        p,
                        board.countOfColor(ArrayBoard.WHITE),
                        board.countOfColor(ArrayBoard.BLACK)));
            break;
          case ArrayPiece.QUEEN:
            whiteSum += 2 * queenval;
            break;
          case ArrayPiece.ROOK:
            whiteSum += 2 * rookval;
            break;
          case ArrayPiece.BISHOP:
            whiteSum += 2 * (bishoppos[p.row()][p.col()] + bishopval);
            break;
          case ArrayPiece.KNIGHT:
            whiteSum += 2 * (knightpos[p.row()][p.col()] + knightval);
            break;
          case ArrayPiece.PAWN:
            whiteSum += 2 * (pawnpos[p.row()][p.col()] + pawnval);
            break;
        }
      }
      return whiteSum;
    } else {
      int blackSum = 0;
      for (ArrayPiece p : board.allPiecesOfColor(ArrayBoard.BLACK)) {
        switch (p.type()) {
          case ArrayPiece.KING:
            blackSum +=
                4
                    * (calculateBlackKingWeight(
                        p,
                        board.countOfColor(ArrayBoard.WHITE),
                        board.countOfColor(ArrayBoard.BLACK)));
            break;
          case ArrayPiece.QUEEN:
            blackSum += 2 * queenval;
            break;
          case ArrayPiece.ROOK:
            blackSum += 2 * rookval;
            break;
          case ArrayPiece.BISHOP:
            blackSum += 2 * (bishoppos[7 - p.row()][p.col()] + bishopval);
            break;
          case ArrayPiece.KNIGHT:
            blackSum += 2 * (knightpos[7 - p.row()][p.col()] + knightval);
            break;
          case ArrayPiece.PAWN:
            blackSum += 2 * (pawnpos[7 - p.row()][p.col()] + pawnval);
            break;
        }
      }
      return blackSum;
    }
  }