Signed-off-by: Marco Costalba <mcostalba@gmail.com>
/// search captures, promotions and some checks) and about how important good
/// move ordering is at the current node.
/// search captures, promotions and some checks) and about how important good
/// move ordering is at the current node.
-MovePicker::MovePicker(Position &p, bool pvnode, Move ttm, Move mk,
- Move k1, Move k2, Depth dpth) {
- pos = &p;
+MovePicker::MovePicker(const Position& p, bool pvnode, Move ttm, Move mk,
+ Move k1, Move k2, Depth d) : pos(p) {
pvNode = pvnode;
ttMove = ttm;
mateKiller = (mk == ttm)? MOVE_NONE : mk;
killer1 = k1;
killer2 = k2;
pvNode = pvnode;
ttMove = ttm;
mateKiller = (mk == ttm)? MOVE_NONE : mk;
killer1 = k1;
killer2 = k2;
movesPicked = 0;
numOfMoves = 0;
numOfBadCaptures = 0;
movesPicked = 0;
numOfMoves = 0;
numOfBadCaptures = 0;
if (ttMove != MOVE_NONE)
{
assert(move_is_ok(ttMove));
if (ttMove != MOVE_NONE)
{
assert(move_is_ok(ttMove));
- if (generate_move_if_legal(*pos, ttMove, pinned) != MOVE_NONE)
+ if (generate_move_if_legal(pos, ttMove, pinned) != MOVE_NONE)
if (mateKiller != MOVE_NONE)
{
assert(move_is_ok(mateKiller));
if (mateKiller != MOVE_NONE)
{
assert(move_is_ok(mateKiller));
- if (generate_move_if_legal(*pos, mateKiller, pinned) != MOVE_NONE)
+ if (generate_move_if_legal(pos, mateKiller, pinned) != MOVE_NONE)
return ttMove;
}
break;
case PH_GOOD_CAPTURES:
return ttMove;
}
break;
case PH_GOOD_CAPTURES:
- numOfMoves = generate_captures(*pos, moves);
+ numOfMoves = generate_captures(pos, moves);
score_captures();
movesPicked = 0;
break;
score_captures();
movesPicked = 0;
break;
break;
case PH_NONCAPTURES:
break;
case PH_NONCAPTURES:
- numOfMoves = generate_noncaptures(*pos, moves);
+ numOfMoves = generate_noncaptures(pos, moves);
score_noncaptures();
movesPicked = 0;
break;
case PH_EVASIONS:
score_noncaptures();
movesPicked = 0;
break;
case PH_EVASIONS:
- assert(pos->is_check());
- numOfMoves = generate_evasions(*pos, moves);
+ assert(pos.is_check());
+ numOfMoves = generate_evasions(pos, moves);
score_evasions();
movesPicked = 0;
break;
case PH_QCAPTURES:
score_evasions();
movesPicked = 0;
break;
case PH_QCAPTURES:
- numOfMoves = generate_captures(*pos, moves);
+ numOfMoves = generate_captures(pos, moves);
score_qcaptures();
movesPicked = 0;
break;
case PH_QCHECKS:
score_qcaptures();
movesPicked = 0;
break;
case PH_QCHECKS:
- numOfMoves = generate_checks(*pos, moves, dc);
+ numOfMoves = generate_checks(pos, moves, dc);
for (int i = 0; i < numOfMoves; i++)
{
Move m = moves[i].move;
for (int i = 0; i < numOfMoves; i++)
{
Move m = moves[i].move;
- moves[i].score = pos->see(m);
+ moves[i].score = pos.see(m);
if (moves[i].score >= 0)
{
moves[i].score = move_promotion(m) ? QueenValueMidgame
if (moves[i].score >= 0)
{
moves[i].score = move_promotion(m) ? QueenValueMidgame
- : int(pos->midgame_value_of_piece_on(move_to(m)))
- -int(pos->type_of_piece_on(move_from(m)));
+ : int(pos.midgame_value_of_piece_on(move_to(m)))
+ -int(pos.type_of_piece_on(move_from(m)));
// FIXME second term seems wrong !
}
}
// FIXME second term seems wrong !
}
}
else if (m == killer2)
moves[i].score = HistoryMax + 1;
else
else if (m == killer2)
moves[i].score = HistoryMax + 1;
else
- moves[i].score = H.move_ordering_score(pos->piece_on(move_from(m)), m);
+ moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), m);
// Ensure moves in history are always sorted as first
if (moves[i].score > 0)
moves[i].score += 1000;
// Ensure moves in history are always sorted as first
if (moves[i].score > 0)
moves[i].score += 1000;
- moves[i].score += pos->mg_pst_delta(moves[i].move);
+ moves[i].score += pos.mg_pst_delta(moves[i].move);
Move m = moves[i].move;
if (m == ttMove)
moves[i].score = 2*HistoryMax;
Move m = moves[i].move;
if (m == ttMove)
moves[i].score = 2*HistoryMax;
- else if (!pos->square_is_empty(move_to(m)))
+ else if (!pos.square_is_empty(move_to(m)))
- moves[i].score = pos->see(m);
+ moves[i].score = pos.see(m);
if (moves[i].score >= 0)
moves[i].score += HistoryMax;
}
else
if (moves[i].score >= 0)
moves[i].score += HistoryMax;
}
else
- moves[i].score = H.move_ordering_score(pos->piece_on(move_from(m)), m);
+ moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), m);
}
// FIXME try psqt also here
}
}
// FIXME try psqt also here
}
{
Move m = moves[i].move;
moves[i].score = move_promotion(m) ? QueenValueMidgame
{
Move m = moves[i].move;
moves[i].score = move_promotion(m) ? QueenValueMidgame
- : int(pos->midgame_value_of_piece_on(move_to(m)))
- -int(pos->midgame_value_of_piece_on(move_to(m))) / 64;
+ : int(pos.midgame_value_of_piece_on(move_to(m)))
+ -int(pos.midgame_value_of_piece_on(move_to(m))) / 64;
// FIXME Why second term like that ???
}
}
// FIXME Why second term like that ???
}
}
switch (PhaseTable[phaseIndex]) {
case PH_GOOD_CAPTURES:
switch (PhaseTable[phaseIndex]) {
case PH_GOOD_CAPTURES:
- assert(!pos->is_check());
+ assert(!pos.is_check());
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
moves[bestIndex] = moves[movesPicked++];
if ( move != ttMove
&& move != mateKiller
moves[bestIndex] = moves[movesPicked++];
if ( move != ttMove
&& move != mateKiller
- && pos->move_is_legal(move, pinned))
+ && pos.move_is_legal(move, pinned))
return move;
}
}
break;
case PH_NONCAPTURES:
return move;
}
}
break;
case PH_NONCAPTURES:
- assert(!pos->is_check());
+ assert(!pos.is_check());
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
moves[bestIndex] = moves[movesPicked++];
if ( move != ttMove
&& move != mateKiller
moves[bestIndex] = moves[movesPicked++];
if ( move != ttMove
&& move != mateKiller
- && pos->move_is_legal(move, pinned))
+ && pos.move_is_legal(move, pinned))
return move;
}
}
break;
case PH_EVASIONS:
return move;
}
}
break;
case PH_EVASIONS:
- assert(pos->is_check());
+ assert(pos.is_check());
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
break;
case PH_BAD_CAPTURES:
break;
case PH_BAD_CAPTURES:
- assert(!pos->is_check());
+ assert(!pos.is_check());
assert(badCapturesPicked >= 0);
// It's probably a good idea to use SEE move ordering here, instead
// of just picking the first move. FIXME
assert(badCapturesPicked >= 0);
// It's probably a good idea to use SEE move ordering here, instead
// of just picking the first move. FIXME
move = badCaptures[badCapturesPicked++].move;
if ( move != ttMove
&& move != mateKiller
move = badCaptures[badCapturesPicked++].move;
if ( move != ttMove
&& move != mateKiller
- && pos->move_is_legal(move, pinned))
+ && pos.move_is_legal(move, pinned))
return move;
}
break;
case PH_QCAPTURES:
return move;
}
break;
case PH_QCAPTURES:
- assert(!pos->is_check());
+ assert(!pos.is_check());
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
// Remember to change the line below if we decide to hash the qsearch!
// Maybe also postpone the legality check until after futility pruning?
// FIXME !!!
// Remember to change the line below if we decide to hash the qsearch!
// Maybe also postpone the legality check until after futility pruning?
// FIXME !!!
- if (/* move != ttMove && */ pos->move_is_legal(move, pinned))
+ if (/* move != ttMove && */ pos.move_is_legal(move, pinned))
return move;
}
}
break;
case PH_QCHECKS:
return move;
}
}
break;
case PH_QCHECKS:
- assert(!pos->is_check());
+ assert(!pos.is_check());
assert(movesPicked >= 0);
// Perhaps we should do something better than just picking the first
// move here? FIXME
assert(movesPicked >= 0);
// Perhaps we should do something better than just picking the first
// move here? FIXME
move = moves[movesPicked++].move;
// Remember to change the line below if we decide to hash the qsearch!
// FIXME !!!
move = moves[movesPicked++].move;
// Remember to change the line below if we decide to hash the qsearch!
// FIXME !!!
- if (/* move != ttMove && */ pos->move_is_legal(move, pinned))
+ if (/* move != ttMove && */ pos.move_is_legal(move, pinned))
- MovePicker(Position &p, bool pvnode, Move ttm, Move mk, Move k1, Move k2,
- Depth dpth);
+ MovePicker(const Position& p, bool pvnode, Move ttm, Move mk, Move k1, Move k2, Depth d);
Move get_next_move();
Move get_next_move(Lock &lock);
int number_of_moves() const;
Move get_next_move();
Move get_next_move(Lock &lock);
int number_of_moves() const;
void score_qcaptures();
Move pick_move_from_list();
void score_qcaptures();
Move pick_move_from_list();
Move ttMove, mateKiller, killer1, killer2;
Bitboard pinned, dc;
MoveStack moves[256], badCaptures[64];
Move ttMove, mateKiller, killer1, killer2;
Bitboard pinned, dc;
MoveStack moves[256], badCaptures[64];