diff --git a/source/search.cpp b/source/search.cpp index d9dd5cd..8a4c38f 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -14,6 +14,8 @@ static inline bool doingNullMove = false; // [id][ply] static inline int killerMoves[2][64]; +// [stm][from][to] +static inline int historyMoves[2][64][64]; inline PVLine pvLine; @@ -33,14 +35,15 @@ static int ScoreMove(Board &board, Move &move) { targetType = Pawn; } - return moveScoreTable[attackerType][targetType] + 10000; + return moveScoreTable[attackerType][targetType] + 30000; } else { if (killerMoves[0][ply] == move) { - return 9000; - } - - if (killerMoves[1][ply] == move) { - return 8000; + return 20000; + } else if (killerMoves[1][ply] == move) { + return 18000; + } else { + // Max 16384 + return historyMoves[board.sideToMove][move.MoveFrom()][move.MoveTo()]; } } @@ -203,8 +206,10 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { // For all moves for (int i = 0; i < board.currentMoveIndex; i++) { + Move currMove = board.moveList[i]; + Board copy = board; - copy.MakeMove(copy.moveList[i]); + copy.MakeMove(currMove); // First move (suspected PV node) if (!i) { @@ -228,8 +233,13 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { // Fail high (beta cutoff) if (score >= beta) { - killerMoves[1][ply] = killerMoves[0][ply]; - killerMoves[0][ply] = board.moveList[i]; + if (!currMove.IsCapture()) { + killerMoves[1][ply] = killerMoves[0][ply]; + killerMoves[0][ply] = currMove; + + historyMoves[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()] = + std::min(16384, historyMoves[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()] + depth * depth); + } TT.WriteEntry(board.hashKey, depth, score, CutNode, Move()); return score; @@ -240,8 +250,8 @@ SearchResults PVS(Board board, int depth, int alpha, int beta) { if (score > alpha) { nodeType = PV; alpha = score; - results.bestMove = board.moveList[i]; - pvLine.SetMove(ply, board.moveList[i]); + results.bestMove = currMove; + pvLine.SetMove(ply, currMove); } }