+var reconcile_responses = function(probe_responses) {
+ var probe_response = {};
+
+ // Select the root that has searched the deepest, plain and simple.
+ probe_response['root'] = probe_responses[0]['root'];
+ for (var i = 1; i < probe_responses.length; ++i) {
+ var root = probe_responses[i]['root'];
+ if (root['depth'] > probe_response['root']['depth']) {
+ probe_response['root'] = root;
+ }
+ }
+
+ // Do the same ting for each move, combining on move.
+ var moves = {};
+ for (var i = 0; i < probe_responses.length; ++i) {
+ for (var j = 0; j < probe_responses[i]['line'].length; ++j) {
+ var line = probe_responses[i]['line'][j];
+ var uci_move = line['move']['from_sq'] + line['move']['to_sq'] + line['move']['promotion'];
+
+ if (!moves[uci_move]) {
+ moves[uci_move] = line;
+ } else {
+ moves[uci_move] = reconcile_moves(line, moves[uci_move]);
+ }
+ }
+ }
+ probe_response['line'] = [];
+ for (var move in moves) {
+ probe_response['line'].push(moves[move]);
+ }
+ return probe_response;
+}
+
+var reconcile_moves = function(a, b) {
+ // Prefer exact bounds, unless the depth is just so much higher.
+ if (a['bound'] === 'BOUND_EXACT' &&
+ b['bound'] !== 'BOUND_EXACT' &&
+ a['depth'] + 10 >= b['depth']) {
+ return a;
+ }
+ if (b['bound'] === 'BOUND_EXACT' &&
+ a['bound'] !== 'BOUND_EXACT' &&
+ b['depth'] + 10 >= a['depth']) {
+ return b;
+ }
+
+ if (a['depth'] > b['depth']) {
+ return a;
+ } else {
+ return b;
+ }
+}
+