diff --git a/CuckooChessEngine/src/chess/ComputerPlayer.java b/CuckooChessEngine/src/chess/ComputerPlayer.java index 5aea724..2216396 100644 --- a/CuckooChessEngine/src/chess/ComputerPlayer.java +++ b/CuckooChessEngine/src/chess/ComputerPlayer.java @@ -30,7 +30,7 @@ public class ComputerPlayer implements Player { public static final String engineName; static { - String name = "CuckooChess 1.13a2"; + String name = "CuckooChess 1.13a3"; String m = System.getProperty("sun.arch.data.model"); if ("32".equals(m)) name += " 32-bit"; diff --git a/CuckooChessEngine/src/chess/Evaluate.java b/CuckooChessEngine/src/chess/Evaluate.java index ca595e8..93a1864 100644 --- a/CuckooChessEngine/src/chess/Evaluate.java +++ b/CuckooChessEngine/src/chess/Evaluate.java @@ -947,8 +947,7 @@ public class Evaluate { // King + minor piece vs king + minor piece is a draw return 0; } - if (!handled && (pos.wMtrl == qV) && (pos.bMtrl == pV) && - (Long.bitCount(pos.pieceTypeBB[Piece.WQUEEN]) == 1)) { + if (!handled && (pos.wMtrl == qV) && (pos.bMtrl == pV) && (pos.pieceTypeBB[Piece.WQUEEN] != 0)) { int wk = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.WKING]); int wq = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.WQUEEN]); int bk = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.BKING]); @@ -956,15 +955,26 @@ public class Evaluate { score = evalKQKP(wk, wq, bk, bp); handled = true; } - if (!handled && (pos.wMtrl == rV) && (pos.bMtrl == pV) && - (Long.bitCount(pos.pieceTypeBB[Piece.WROOK]) == 1)) { - int bp = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.BPAWN]); - score = krkpEval(pos.getKingSq(true), pos.getKingSq(false), - bp, pos.whiteMove); - handled = true; + if (!handled && (pos.wMtrl == rV) && (pos.pieceTypeBB[Piece.WROOK] != 0)) { + if (pos.bMtrl == pV) { + int bp = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.BPAWN]); + score = krkpEval(pos.getKingSq(true), pos.getKingSq(false), + bp, pos.whiteMove); + handled = true; + } else if ((pos.bMtrl == bV) && (pos.pieceTypeBB[Piece.BBISHOP] != 0)) { + score /= 8; + final int kSq = pos.getKingSq(false); + final int x = Position.getX(kSq); + final int y = Position.getY(kSq); + if ((pos.pieceTypeBB[Piece.BBISHOP] & BitBoard.maskDarkSq) != 0) { + score += (7 - distToH1A8[7-y][7-x]) * 7; + } else { + score += (7 - distToH1A8[7-y][x]) * 7; + } + handled = true; + } } - if (!handled && (pos.bMtrl == qV) && (pos.wMtrl == pV) && - (Long.bitCount(pos.pieceTypeBB[Piece.BQUEEN]) == 1)) { + if (!handled && (pos.bMtrl == qV) && (pos.wMtrl == pV) && (pos.pieceTypeBB[Piece.BQUEEN] != 0)) { int bk = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.BKING]); int bq = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.BQUEEN]); int wk = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.WKING]); @@ -972,12 +982,24 @@ public class Evaluate { score = -evalKQKP(63-bk, 63-bq, 63-wk, 63-wp); handled = true; } - if (!handled && (pos.bMtrl == rV) && (pos.wMtrl == pV) && - (Long.bitCount(pos.pieceTypeBB[Piece.BROOK]) == 1)) { - int wp = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.WPAWN]); - score = -krkpEval(63-pos.getKingSq(false), 63-pos.getKingSq(true), - 63-wp, !pos.whiteMove); - handled = true; + if (!handled && (pos.bMtrl == rV) && (pos.pieceTypeBB[Piece.BROOK] != 0)) { + if (pos.wMtrl == pV) { + int wp = BitBoard.numberOfTrailingZeros(pos.pieceTypeBB[Piece.WPAWN]); + score = -krkpEval(63-pos.getKingSq(false), 63-pos.getKingSq(true), + 63-wp, !pos.whiteMove); + handled = true; + } else if ((pos.wMtrl == bV) && (pos.pieceTypeBB[Piece.WBISHOP] != 0)) { + score /= 8; + final int kSq = pos.getKingSq(true); + final int x = Position.getX(kSq); + final int y = Position.getY(kSq); + if ((pos.pieceTypeBB[Piece.WBISHOP] & BitBoard.maskDarkSq) != 0) { + score -= (7 - distToH1A8[7-y][7-x]) * 7; + } else { + score -= (7 - distToH1A8[7-y][x]) * 7; + } + handled = true; + } } if (!handled && (score > 0)) { if ((wMtrlPawns == 0) && (wMtrlNoPawns <= bMtrlNoPawns + bV)) { diff --git a/CuckooChessEngine/src/chess/Position.java b/CuckooChessEngine/src/chess/Position.java index 65c7b40..c5deab7 100644 --- a/CuckooChessEngine/src/chess/Position.java +++ b/CuckooChessEngine/src/chess/Position.java @@ -371,8 +371,8 @@ public class Position { } - public final int getKingSq(boolean whiteMove) { - return whiteMove ? wKingSq : bKingSq; + public final int getKingSq(boolean white) { + return white ? wKingSq : bKingSq; } /** Apply a move to the current position. */ diff --git a/CuckooChessEngine/test/chess/EvaluateTest.java b/CuckooChessEngine/test/chess/EvaluateTest.java index aff7f8b..a7405dc 100644 --- a/CuckooChessEngine/test/chess/EvaluateTest.java +++ b/CuckooChessEngine/test/chess/EvaluateTest.java @@ -301,6 +301,15 @@ public class EvaluateTest { pos = TextIO.readFEN("rk/p/8/8/8/8/NKR/8 w - - 0 1"); score = evalWhite(pos); assertTrue(score < nV - 2 * pV); + + // KRKB, defending king should prefer corner that bishop cannot attack + pos = TextIO.readFEN("6B1/8/8/8/8/2k5/4r3/2K5 w - - 0 93"); + score = evalWhite(pos); + assertTrue(score >= -pV); + score = moveScore(pos, "Kd1"); + assertTrue(score < 0); + score = moveScore(pos, "Kb1"); + assertTrue(score > 0); } /**