X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.cpp;h=20aaabbdde0288a28743ea230706dc2905cc281f;hp=95bbddba670788af7d2b937a72ddb4c28a791a31;hb=c6d62b7da5b9bb0e8c987596d1c6a304b337ca32;hpb=32934c0c8d75fe63e08046f6ba7dd546de67dc01 diff --git a/src/movepick.cpp b/src/movepick.cpp index 95bbddba..20aaabbd 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -228,29 +228,18 @@ void MovePicker::score_captures() { // to the badCaptures[] array. Move m; int seeValue; - Square from, to; for (int i = 0; i < numOfMoves; i++) { m = moves[i].move; - from = move_from(m); - to = move_to(m); - - bool hxl = ( int(pos.midgame_value_of_piece_on(from)) - -int(pos.midgame_value_of_piece_on(to)) > 0) - || pos.type_of_piece_on(from) == KING; - - // Avoid calling see() for LxH and equal captures because - // SEE is always >= 0 and we order for MVV/LVA anyway. - seeValue = (hxl ? pos.see(m) : 0); - + seeValue = pos.see(m); if (seeValue >= 0) { if (move_promotion(m)) moves[i].score = QueenValueMidgame; else - moves[i].score = int(pos.midgame_value_of_piece_on(to)) - -int(pos.type_of_piece_on(from)); + moves[i].score = int(pos.midgame_value_of_piece_on(move_to(m))) + -int(pos.type_of_piece_on(move_from(m))); } else { @@ -321,17 +310,19 @@ void MovePicker::score_qcaptures() { } -/// 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 +/// 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() { - int bestScore = -10000000, bestIndex = -1; + assert(movesPicked < numOfMoves); - for (int i = movesPicked; i < numOfMoves; i++) + int bestIndex = movesPicked, bestScore = moves[movesPicked].score; + + for (int i = movesPicked + 1; i < numOfMoves; i++) if (moves[i].score > bestScore) { bestIndex = i; @@ -340,41 +331,43 @@ 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; +int MovePicker::find_best_index(Bitboard* squares, int values[]) { + + assert(movesPicked < numOfMoves); + + 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; } @@ -389,6 +382,7 @@ Move MovePicker::pick_move_from_list() { Move move; switch (PhaseTable[phaseIndex]) { + case PH_GOOD_CAPTURES: assert(!pos.is_check()); assert(movesPicked >= 0); @@ -396,16 +390,12 @@ Move MovePicker::pick_move_from_list() { while (movesPicked < numOfMoves) { bestIndex = find_best_index(); - - if (bestIndex != -1) // Found a good capture - { - move = moves[bestIndex].move; - moves[bestIndex] = moves[movesPicked++]; - if ( move != ttMove - && move != mateKiller - && pos.pl_move_is_legal(move, pinned)) - return move; - } + move = moves[bestIndex].move; + moves[bestIndex] = moves[movesPicked++]; + if ( move != ttMove + && move != mateKiller + && pos.pl_move_is_legal(move, pinned)) + return move; } break; @@ -420,16 +410,12 @@ Move MovePicker::pick_move_from_list() { // 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. bestIndex = (pvNode || movesPicked < 12) ? find_best_index() : movesPicked; - - if (bestIndex != -1) - { - move = moves[bestIndex].move; - moves[bestIndex] = moves[movesPicked++]; - if ( move != ttMove - && move != mateKiller - && pos.pl_move_is_legal(move, pinned)) - return move; - } + move = moves[bestIndex].move; + moves[bestIndex] = moves[movesPicked++]; + if ( move != ttMove + && move != mateKiller + && pos.pl_move_is_legal(move, pinned)) + return move; } break; @@ -440,13 +426,9 @@ Move MovePicker::pick_move_from_list() { while (movesPicked < numOfMoves) { bestIndex = find_best_index(); - - if (bestIndex != -1) - { - move = moves[bestIndex].move; - moves[bestIndex] = moves[movesPicked++]; - return move; - } + move = moves[bestIndex].move; + moves[bestIndex] = moves[movesPicked++]; + return move; } break; @@ -471,16 +453,12 @@ Move MovePicker::pick_move_from_list() { while (movesPicked < numOfMoves) { 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? - if (/* move != ttMove && */ pos.pl_move_is_legal(move, pinned)) - return move; - } + 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? + if (/* move != ttMove && */ pos.pl_move_is_legal(move, pinned)) + return move; } break;