X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.cpp;h=1024cbffede226903eaf47f8f48e2001cabfe370;hp=4b1fccc4fdc810db49cb461ec54d2502b5f4d716;hb=35fd5ce5bc3b2a99369e277a83b4426ab3bc5bc2;hpb=2943e1ca3171341cd301b18280f3fa3b6bdda162 diff --git a/src/movepick.cpp b/src/movepick.cpp index 4b1fccc4..1024cbff 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -73,11 +73,11 @@ MovePicker::MovePicker(const Position& p, bool pvnode, Move ttm, Move mk, numOfBadCaptures = 0; dc = p.discovered_check_candidates(p.side_to_move()); - if(p.is_check()) + if (p.is_check()) phaseIndex = EvasionsPhaseIndex; - else if(depth > Depth(0)) + else if (depth > Depth(0)) phaseIndex = MainSearchPhaseIndex; - else if(depth == Depth(0)) + else if (depth == Depth(0)) phaseIndex = QsearchWithChecksPhaseIndex; else phaseIndex = QsearchWithoutChecksPhaseIndex; @@ -99,7 +99,7 @@ Move MovePicker::get_next_move() { while (true) { // If we already have a list of generated moves, pick the best move from - // the list, and return it: + // the list, and return it. move = pick_move_from_list(); if (move != MOVE_NONE) { @@ -107,7 +107,7 @@ Move MovePicker::get_next_move() { return move; } - // Next phase: + // Next phase phaseIndex++; switch (PhaseTable[phaseIndex]) { @@ -125,7 +125,7 @@ Move MovePicker::get_next_move() { { assert(move_is_ok(mateKiller)); if (generate_move_if_legal(pos, mateKiller, pinned) != MOVE_NONE) - return ttMove; + return mateKiller; } break; @@ -199,11 +199,10 @@ Move MovePicker::get_next_move(Lock &lock) { /// MovePicker::score_captures(), MovePicker::score_noncaptures(), /// MovePicker::score_evasions() and MovePicker::score_qcaptures() assign a /// numerical move ordering score to each move in a move list. The moves -/// with highest scores will be picked first by -/// MovePicker::pick_move_from_list(). +/// with highest scores will be picked first by pick_move_from_list(). void MovePicker::score_captures() { - // Winning and equal captures in the main search are ordered by MVV/LVA. + // Winning and equal captures in the main search are ordered by MVV. // Suprisingly, this appears to perform slightly better than SEE based // move ordering. The reason is probably that in a position with a winning // capture, capturing a more valuable (but sufficiently defended) piece @@ -217,12 +216,8 @@ void MovePicker::score_captures() { Move m = moves[i].move; moves[i].score = pos.see(m); 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))); - // FIXME second term seems wrong ! - } + : pos.midgame_value_of_piece_on(move_to(m)); } } @@ -267,18 +262,33 @@ void MovePicker::score_evasions() { void MovePicker::score_qcaptures() { - // Use MVV/LVA ordering. + // Use MVV ordering for (int i = 0; i < numOfMoves; i++) { 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; - // FIXME Why second term like that ??? + : pos.midgame_value_of_piece_on(move_to(m)); } } +/// find_best_index() loops across the moves and returns index of +/// the highest scored one. + +int MovePicker::find_best_index() { + + int bestScore = -10000000, bestIndex = -1; + + for (int i = movesPicked; i < numOfMoves; i++) + if (moves[i].score > bestScore) + { + bestIndex = i; + bestScore = moves[i].score; + } + return bestIndex; +} + + /// MovePicker::pick_move_from_list() picks the move with the biggest score /// from a list of generated moves (moves[] or badCaptures[], depending on /// the current move generation phase). It takes care not to return the @@ -289,7 +299,6 @@ void MovePicker::score_qcaptures() { Move MovePicker::pick_move_from_list() { - int bestScore = -10000000; int bestIndex; Move move; @@ -300,7 +309,7 @@ Move MovePicker::pick_move_from_list() { assert(movesPicked >= 0); while (movesPicked < numOfMoves) { - bestScore = -10000000; + int bestScore = -10000000; bestIndex = -1; for (int i = movesPicked; i < numOfMoves; i++) { @@ -338,18 +347,7 @@ Move MovePicker::pick_move_from_list() { // the entire move list for the best move. If many moves have already // been searched and it is not a PV node, we are probably failing low // anyway, so we just pick the first move from the list. - if (pvNode || movesPicked < 12) - { - bestScore = -10000000; - bestIndex = -1; - for (int i = movesPicked; i < numOfMoves; i++) - if(moves[i].score > bestScore) - { - bestIndex = i; - bestScore = moves[i].score; - } - } else - bestIndex = movesPicked; + bestIndex = (movesPicked < 12 || pvNode ? find_best_index() : movesPicked); if (bestIndex != -1) { @@ -368,14 +366,7 @@ Move MovePicker::pick_move_from_list() { assert(movesPicked >= 0); while (movesPicked < numOfMoves) { - bestScore = -10000000; - bestIndex = -1; - for (int i = movesPicked; i < numOfMoves; i++) - if (moves[i].score > bestScore) - { - bestIndex = i; - bestScore = moves[i].score; - } + bestIndex = find_best_index(); if (bestIndex != -1) { @@ -406,27 +397,14 @@ Move MovePicker::pick_move_from_list() { assert(movesPicked >= 0); while (movesPicked < numOfMoves) { - bestScore = -10000000; - if (movesPicked < 4) // FIXME makes sens to score qcaps? - { - bestIndex = -1; - for (int i = movesPicked; i < numOfMoves; i++) - if(moves[i].score > bestScore) - { - bestIndex = i; - bestScore = moves[i].score; - } - } else - bestIndex = movesPicked; + // FIXME makes sens to score qcaps? + bestIndex = (movesPicked < 4 ? find_best_index() : movesPicked); if (bestIndex != -1) { move = moves[bestIndex].move; moves[bestIndex] = moves[movesPicked++]; - // 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; } } @@ -439,10 +417,8 @@ Move MovePicker::pick_move_from_list() { // move here? FIXME while (movesPicked < numOfMoves) { - 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)) + move = moves[movesPicked++].move; + if (move != ttMove && pos.move_is_legal(move, pinned)) return move; } break; @@ -458,6 +434,7 @@ Move MovePicker::pick_move_from_list() { /// picked next move. It can be used in search to further differentiate /// according to the current move type: capture, non capture, escape, etc. MovePicker::MovegenPhase MovePicker::current_move_type() const { + return PhaseTable[phaseIndex]; }