+/// find_best_index() loops across the moves and returns index of\r
+/// the highest scored one. There is also a second version that\r
+/// lowers the priority of moves that attack the same square,\r
+/// so that if the best move that attack a square fails the next\r
+/// move picked attacks a different square if any, not the same 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;
+}
+
+int MovePicker::find_best_index(Bitboard* squares, int values[]) {\r
+\r
+ int hs;\r
+ Move m;\r
+ Square to;\r
+ int bestScore = -10000000, bestIndex = -1;\r
+\r
+ for (int i = movesPicked; i < numOfMoves; i++)\r
+ {\r
+ m = moves[i].move;\r
+ to = move_to(m);\r
+ \r
+ if (!bit_is_set(*squares, to))\r
+ {\r
+ // Init at first use\r
+ set_bit(squares, to);\r
+ values[to] = 0;\r
+ }\r
+\r
+ hs = moves[i].score - values[to];\r
+ if (hs > bestScore)\r
+ {\r
+ bestIndex = i;\r
+ bestScore = hs;\r
+ }\r
+ }\r
+\r
+ if (bestIndex != -1)\r
+ {\r
+ // Raise value of the picked square, so next attack\r
+ // to the same square will get low priority.\r
+ to = move_to(moves[bestIndex].move);\r
+ values[to] += 0xB00;\r
+ }\r
+ return bestIndex;\r
+}
+
+