-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovepick.cpp
More file actions
43 lines (38 loc) · 1.42 KB
/
movepick.cpp
File metadata and controls
43 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "movepick.h"
#include "eval.h"
#include <position.h>
#include <algorithm>
using namespace chess;
using engine::eval::piece_value;
namespace engine::movepick {
Value historyHeuristic[SQUARE_NB][SQUARE_NB]{};
Move killerMoves[256][2];
void orderMoves(chess::Board & board, chess::Movelist & moves, chess::Move ttMove, int ply)
{
std::vector<std::pair<chess::Move, Value>> scoredMoves;
scoredMoves.reserve(moves.size());
for (const auto& move : moves)
{
Value score = 0;
if (move == ttMove)
score = 10000;
else if (board.isCapture(move))
score =
((move.typeOf() & EN_PASSANT)==0?piece_value(board.at<PieceType>(move.to())):piece_value(PAWN))*10 - piece_value(board.at<PieceType>(move.from()));
else if (move == killerMoves[ply][0])
score = 8500;
else if (move == killerMoves[ply][1])
score = 8000;
else
score = historyHeuristic[move.from()][move.to()];
scoredMoves.emplace_back(move, score);
}
std::stable_sort(scoredMoves.begin(), scoredMoves.end(),
[](const auto& a, const auto& b)
{
return a.second > b.second;
});
for (size_t i = 0; i < scoredMoves.size(); ++i)
moves[i] = scoredMoves[i].first;
}
}