X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmovepick.cpp;h=34c69895562136317dc1ecb7d13917a42f262c60;hb=3c05bd70ebf57cebb88d29a88e6c492976a97761;hp=187a3c513e0275a112c377919a40d62cbdebf586;hpb=8b57416ace03cc37568f19ed561931cfda288bb3;p=stockfish diff --git a/src/movepick.cpp b/src/movepick.cpp index 187a3c51..34c69895 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -134,6 +134,7 @@ Move MovePicker::get_next_move() { case PH_GOOD_CAPTURES: numOfMoves = generate_captures(pos, moves); score_captures(); + capSquares = EmptyBoardBB; movesPicked = 0; break; @@ -211,6 +212,8 @@ void MovePicker::score_captures() { // where it is possible to recapture with the hanging piece). Exchanging // big pieces before capturing a hanging piece probably helps to reduce // the subtree size. + // While scoring captures it moves all captures with negative SEE values + // to the badCaptures[] array. Move m; int seeValue; @@ -225,8 +228,15 @@ void MovePicker::score_captures() { else moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m))) -int(pos.type_of_piece_on(move_from(m))); - } else + } + else + { + // Losing capture, move it to the badCaptures[] array + assert(numOfBadCaptures < 63); moves[i].score = seeValue; + badCaptures[numOfBadCaptures++] = moves[i]; + moves[i--] = moves[--numOfMoves]; + } } } @@ -288,8 +298,11 @@ void MovePicker::score_qcaptures() { } -/// find_best_index() loops across the moves and returns index of -/// the highest scored one. +/// find_best_index() loops across the moves and returns index of +/// the highest scored one. There is also a second version that +/// lowers the priority of moves that attack the same square, +/// so that if the best move that attack a square fails the next +/// move picked attacks a different square if any, not the same one. int MovePicker::find_best_index() { @@ -304,14 +317,48 @@ int MovePicker::find_best_index() { return bestIndex; } +int MovePicker::find_best_index(Bitboard* squares, int values[]) { + + int hs; + Move m; + Square to; + int bestScore = -10000000, bestIndex = -1; + + for (int i = movesPicked; i < numOfMoves; i++) + { + m = moves[i].move; + to = move_to(m); + + if (!bit_is_set(*squares, to)) + { + // Init at first use + set_bit(squares, to); + values[to] = 0; + } + + hs = moves[i].score - values[to]; + if (hs > bestScore) + { + bestIndex = i; + bestScore = hs; + } + } + + if (bestIndex != -1) + { + // Raise value of the picked square, so next attack + // to the same square will get low priority. + to = move_to(moves[bestIndex].move); + values[to] += 0xB00; + } + 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 /// transposition table move if that has already been serched previously. -/// While picking captures in the PH_GOOD_CAPTURES phase (i.e. while picking -/// non-losing captures in the main search), it moves all captures with -/// negative SEE values to the badCaptures[] array. Move MovePicker::pick_move_from_list() { @@ -325,23 +372,8 @@ Move MovePicker::pick_move_from_list() { while (movesPicked < numOfMoves) { - int bestScore = -10000000; - bestIndex = -1; - for (int i = movesPicked; i < numOfMoves; i++) - { - if (moves[i].score < 0) - { - // Losing capture, move it to the badCaptures[] array - assert(numOfBadCaptures < 63); - badCaptures[numOfBadCaptures++] = moves[i]; - moves[i--] = moves[--numOfMoves]; - } - else if (moves[i].score > bestScore) - { - bestIndex = i; - bestScore = moves[i].score; - } - } + bestIndex = find_best_index(&capSquares, capSqValues); + if (bestIndex != -1) // Found a good capture { move = moves[bestIndex].move;