Evaluate { final public int evalPos(Position pos) { int score = pos.wMtrl - pos.bMtrl; wKingAttacks = bKingAttacks = 0; wKingZone = BitBoard.kingAttacks[pos.getKingSq(true)]; wKingZone |= wKingZone << 8; bKingZone = BitBoard.kingAttacks[pos.getKingSq(false)]; bKingZone |= bKingZone >>> 8; wAttacksBB = bAttacksBB = 0L; long pawns = pos.pieceTypeBB[Piece.WPAWN]; wPawnAttacks = ((pawns & BitBoard.maskBToHFiles) << 7) | ((pawns & BitBoard.maskAToGFiles) << 9); pawns = pos.pieceTypeBB[Piece.BPAWN]; bPawnAttacks = ((pawns & BitBoard.maskBToHFiles) >>> 9) | ((pawns & BitBoard.maskAToGFiles) >>> 7); score += pieceSquareEval(pos); score += pawnBonus(pos); score += tradeBonus(pos); score += castleBonus(pos); score += rookBonus(pos); score += bishopEval(pos, score); score += threatBonus(pos); score += kingSafety(pos); score = endGameEval(pos, score); if (!pos.whiteMove) score = -score; return score; } Evaluate(); final int evalPos(Position pos);  }
@Test public void testEvalPos() throws ChessParseError { System.out.println("evalPos"); Position pos = TextIO.readFEN(TextIO.startPosFEN); UndoInfo ui = new UndoInfo(); pos.makeMove(TextIO.stringToMove(pos, "e4"), ui); pos.makeMove(TextIO.stringToMove(pos, "e5"), ui); pos.makeMove(TextIO.stringToMove(pos, "Nf3"), ui); pos.makeMove(TextIO.stringToMove(pos, "Nc6"), ui); pos.makeMove(TextIO.stringToMove(pos, "Bb5"), ui); pos.makeMove(TextIO.stringToMove(pos, "Nge7"), ui); assertTrue(moveScore(pos, "O-O") > 0); assertTrue(moveScore(pos, "Ke2") < 0); assertTrue(moveScore(pos, "Kf1") < 0); assertTrue(moveScore(pos, "Rg1") < 0); assertTrue(moveScore(pos, "Rf1") < 0); pos = TextIO.readFEN("8/8/8/1r3k2/4pP2/4P3/8/4K2R w K - 0 1"); assertEquals(true, pos.h1Castle()); int cs1 = evalWhite(pos); pos.setCastleMask(pos.getCastleMask() & ~(1 << Position.H1_CASTLE)); assertEquals(false, pos.h1Castle()); int cs2 = evalWhite(pos); assertTrue(cs2 >= cs1); pos = TextIO.readFEN("r4rk1/1pp1qppp/3b1n2/4p3/2B1P1b1/1QN2N2/PP3PPP/R3R1K1 w - - 0 1"); int ms1 = moveScore(pos, "Red1"); int ms2 = moveScore(pos, "Rec1"); int ms3 = moveScore(pos, "Rac1"); int ms4 = moveScore(pos, "Rad1"); assertTrue(ms1 > 0); assertTrue(ms2 > 0); assertTrue(ms1 > ms2); assertTrue(ms3 > 0); assertTrue(ms4 > 0); assertTrue(ms4 > ms1); assertTrue(ms3 > ms2); pos = TextIO.readFEN("r3kb1r/p3pp1p/bpPq1np1/4N3/2pP4/2N1PQ2/P1PB1PPP/R3K2R b KQkq - 0 12"); assertTrue(moveScore(pos, "O-O-O") > 0); pos.makeMove(TextIO.stringToMove(pos, "O-O-O"), ui); assertTrue(moveScore(pos, "O-O") > 0); pos = TextIO.readFEN("8/3k4/2p5/1pp5/1P1P4/3K4/8/8 w - - 0 1"); int sc1 = moveScore(pos, "bxc5"); int sc2 = moveScore(pos, "dxc5"); assertTrue(sc1 < sc2); pos = TextIO.readFEN("8/pp1bk3/8/8/8/8/PPPBK3/8 w - - 0 1"); sc1 = evalWhite(pos); pos.setPiece(Position.getSquare(3, 1), Piece.EMPTY); pos.setPiece(Position.getSquare(3, 0), Piece.WBISHOP); sc2 = evalWhite(pos); assertTrue(sc2 > sc1); pos = TextIO.readFEN("r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3"); sc1 = moveScore(pos, "Bd3"); sc2 = moveScore(pos, "Bc4"); assertTrue(sc2 > sc1); }