This removes a bunch of redundant code.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
numOfBadCaptures = 0;
dc = p.discovered_check_candidates(p.side_to_move());
numOfBadCaptures = 0;
dc = p.discovered_check_candidates(p.side_to_move());
phaseIndex = EvasionsPhaseIndex;
phaseIndex = EvasionsPhaseIndex;
- else if(depth > Depth(0))
+ else if (depth > Depth(0))
phaseIndex = MainSearchPhaseIndex;
phaseIndex = MainSearchPhaseIndex;
- else if(depth == Depth(0))
+ else if (depth == Depth(0))
phaseIndex = QsearchWithChecksPhaseIndex;
else
phaseIndex = QsearchWithoutChecksPhaseIndex;
phaseIndex = QsearchWithChecksPhaseIndex;
else
phaseIndex = QsearchWithoutChecksPhaseIndex;
+/// 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
/// 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
Move MovePicker::pick_move_from_list() {
Move MovePicker::pick_move_from_list() {
- int bestScore = -10000000;
int bestIndex;
Move move;
int bestIndex;
Move move;
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
+ int bestScore = -10000000;
bestIndex = -1;
for (int i = movesPicked; i < numOfMoves; i++)
{
bestIndex = -1;
for (int i = movesPicked; i < numOfMoves; i++)
{
badCaptures[numOfBadCaptures++] = moves[i];
moves[i--] = moves[--numOfMoves];
}
badCaptures[numOfBadCaptures++] = moves[i];
moves[i--] = moves[--numOfMoves];
}
- else if (moves[i].score > bestScore)
+ else if (moves[i].score > bestScore) // FIXME >= 0 ??
{
bestIndex = i;
bestScore = moves[i].score;
{
bestIndex = i;
bestScore = moves[i].score;
// 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.
// 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 = (pvNode || movesPicked < 12 ? find_best_index() : movesPicked);
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
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();
assert(movesPicked >= 0);
while (movesPicked < numOfMoves)
{
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);
void score_evasions();
void score_qcaptures();
Move pick_move_from_list();
void score_evasions();
void score_qcaptures();
Move pick_move_from_list();
const Position& pos;
Move ttMove, mateKiller, killer1, killer2;
const Position& pos;
Move ttMove, mateKiller, killer1, killer2;