Skip to content

Commit 5f2e240

Browse files
authored
Update movepick.cpp
1 parent 55eafd9 commit 5f2e240

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

movepick.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,39 @@
33
#include <position.h>
44
using namespace chess;
55
namespace engine {
6+
Value historyHeuristic[SQUARE_NB][SQUARE_NB]{};
7+
Move killerMoves[MAX_PLY][2];
68
void movepick::orderMoves(chess::Board & board, chess::Movelist & moves, chess::Move ttMove, int ply)
79
{
8-
std::vector<std::pair<chess::Move,Value>> moves_;
10+
std::vector<std::pair<chess::Move, Value>> scoredMoves;
11+
scoredMoves.reserve(moves.size());
12+
13+
for (const auto& move : moves)
14+
{
15+
Value score = 0;
16+
17+
if (move == ttMove)
18+
score = 10000;
19+
else if (board.isCapture(move))
20+
score =
21+
((move.type() & EN_PASSANT)==0?piece_value(board.at<PieceType>(move.to())):piece_value(PAWN))*10 - piece_value(board.at<PieceType>(move.from()));
22+
else if (move == killerMoves[ply][0])
23+
score = 8500;
24+
else if (move == killerMoves[ply][1])
25+
score = 8000;
26+
else
27+
score = historyHeuristic[move.from().index()][move.to().index()];
28+
29+
scoredMoves.emplace_back(move, score);
30+
}
31+
32+
std::stable_sort(scoredMoves.begin(), scoredMoves.end(),
33+
[](const auto& a, const auto& b)
34+
{
35+
return a.second > b.second;
36+
});
37+
38+
for (size_t i = 0; i < scoredMoves.size(); ++i)
39+
moves[i] = scoredMoves[i].first;
940
}
1041
}

0 commit comments

Comments
 (0)