movepick: 完成 next_move() 函数并应用
This commit is contained in:
parent
a5581bee01
commit
24b0901b23
|
@ -164,13 +164,35 @@ void MovePicker::score()
|
|||
}
|
||||
}
|
||||
|
||||
/// MovePicker::select() returns the next move satisfying a predicate function.
|
||||
/// It never returns the TT move.
|
||||
template<MovePicker::PickType T, typename Pred>
|
||||
Move MovePicker::select(Pred filter)
|
||||
{
|
||||
while (cur < endMoves) {
|
||||
if (T == Best)
|
||||
std::swap(*cur, *std::max_element(cur, endMoves));
|
||||
|
||||
if (*cur != ttMove && filter())
|
||||
return *cur++;
|
||||
|
||||
cur++;
|
||||
}
|
||||
return MOVE_NONE;
|
||||
}
|
||||
|
||||
/// MovePicker::next_move() is the most important method of the MovePicker class. It
|
||||
/// returns a new pseudo legal move every time it is called until there are no more
|
||||
/// moves left, picking the move with the highest score from a list of generated moves.
|
||||
Move MovePicker::next_move()
|
||||
{
|
||||
// TODO
|
||||
return MOVE_NONE;
|
||||
endMoves = generate(pos, moves);
|
||||
moveCount = endMoves - moves;
|
||||
|
||||
score();
|
||||
partial_insertion_sort(moves, endMoves, -100); // TODO: limit = -3000 * depth
|
||||
|
||||
return *moves;
|
||||
}
|
||||
|
||||
#ifdef HOSTORY_HEURISTIC
|
||||
|
|
|
@ -69,9 +69,17 @@ public:
|
|||
}
|
||||
|
||||
Position *pos;
|
||||
Move ttMove { MOVE_NONE };
|
||||
ExtMove *cur, *endMoves;
|
||||
ExtMove moves[MAX_MOVES] { MOVE_NONE };
|
||||
|
||||
int moveCount{ 0 };
|
||||
|
||||
int move_count()
|
||||
{
|
||||
return moveCount;
|
||||
}
|
||||
|
||||
#ifdef HOSTORY_HEURISTIC
|
||||
// TODO: Fix size
|
||||
Score placeHistory[64];
|
||||
|
|
|
@ -730,23 +730,18 @@ Value search(Position *pos, Stack<Position> &ss, Depth depth, Depth originDepth,
|
|||
}
|
||||
|
||||
MovePicker mp(pos);
|
||||
mp.endMoves = generate(pos, mp.moves);
|
||||
mp.score();
|
||||
Move nextMove = mp.next_move();
|
||||
int moveCount = mp.move_count();
|
||||
|
||||
partial_insertion_sort(mp.moves, mp.endMoves, -100);
|
||||
ExtMove *cur = mp.moves;
|
||||
|
||||
int nchild = mp.endMoves - cur;
|
||||
|
||||
if (nchild == 1 && depth == originDepth) {
|
||||
bestMove = mp.moves[0].move;
|
||||
if (moveCount == 1 && depth == originDepth) {
|
||||
bestMove = nextMove;
|
||||
bestValue = VALUE_UNIQUE;
|
||||
return bestValue;
|
||||
}
|
||||
|
||||
#ifdef TRANSPOSITION_TABLE_ENABLE
|
||||
#ifdef PREFETCH_SUPPORT
|
||||
for (int i = 0; i < nchild; i++) {
|
||||
for (int i = 0; i < moveCount; i++) {
|
||||
TranspositionTable::prefetch(pos->next_primary_key(mp.moves[i].move));
|
||||
}
|
||||
|
||||
|
@ -758,14 +753,14 @@ Value search(Position *pos, Stack<Position> &ss, Depth depth, Depth originDepth,
|
|||
#endif // PREFETCH_SUPPORT
|
||||
#endif // TRANSPOSITION_TABLE_ENABLE
|
||||
|
||||
for (int i = 0; i < nchild; i++) {
|
||||
for (int i = 0; i < moveCount; i++) {
|
||||
ss.push(*(pos));
|
||||
Color before = pos->sideToMove;
|
||||
Move move = mp.moves[i].move;
|
||||
pos->do_move(move);
|
||||
Color after = pos->sideToMove;
|
||||
|
||||
if (gameOptions.getDepthExtension() == true && nchild == 1) {
|
||||
if (gameOptions.getDepthExtension() == true && moveCount == 1) {
|
||||
epsilon = 1;
|
||||
} else {
|
||||
epsilon = 0;
|
||||
|
|
Loading…
Reference in New Issue