]> git.sesse.net Git - remoteglot-book/blobdiff - merge_count.cpp
Build with the new transposition data from pgn-extract. A lot of UI is still missing...
[remoteglot-book] / merge_count.cpp
diff --git a/merge_count.cpp b/merge_count.cpp
new file mode 100644 (file)
index 0000000..dbf028d
--- /dev/null
@@ -0,0 +1,46 @@
+#include "merge_count.h"
+
+#include <unordered_set>
+
+using namespace std;
+
+Count merge_count(const Count& c0, const Count& c1)
+{
+       Count c;
+
+       c.set_white(c0.white() + c1.white());
+       c.set_draw(c0.draw() + c1.draw());
+       c.set_black(c0.black() + c1.black());
+       c.set_sum_white_elo(c0.sum_white_elo() + c1.sum_white_elo());
+       c.set_sum_black_elo(c0.sum_black_elo() + c1.sum_black_elo());
+       c.set_num_elo(c0.num_elo() + c1.num_elo());
+       if (c0.first_timestamp() <= c1.first_timestamp()) {
+               c.set_opening_num(c0.opening_num());
+               if (c0.has_first_timestamp()) {
+                       c.set_first_timestamp(c0.first_timestamp());
+               }
+               c.set_pgn_file_num(c0.pgn_file_num());
+               c.set_pgn_start_position(c0.pgn_start_position());
+       } else {
+               c.set_opening_num(c1.opening_num());
+               if (c1.has_first_timestamp()) {
+                       c.set_first_timestamp(c1.first_timestamp());
+               }
+               c.set_pgn_file_num(c1.pgn_file_num());
+               c.set_pgn_start_position(c1.pgn_start_position());
+       }
+
+       // Merge the moves, with deduplication.
+       unordered_set<string> moves;
+       for (int i = 0; i < c0.move_size(); ++i) {
+               moves.insert(c0.move(i));
+               c.add_move(c0.move(i));
+       }
+       for (int i = 0; i < c1.move_size(); ++i) {
+               if (!moves.count(c1.move(i))) {
+                       c.add_move(c1.move(i));
+               }
+       }
+
+       return c;
+}