]> git.sesse.net Git - remoteglot-book/blob - merge_count.cpp
Build with the new transposition data from pgn-extract. A lot of UI is still missing...
[remoteglot-book] / merge_count.cpp
1 #include "merge_count.h"
2
3 #include <unordered_set>
4
5 using namespace std;
6
7 Count merge_count(const Count& c0, const Count& c1)
8 {
9         Count c;
10
11         c.set_white(c0.white() + c1.white());
12         c.set_draw(c0.draw() + c1.draw());
13         c.set_black(c0.black() + c1.black());
14         c.set_sum_white_elo(c0.sum_white_elo() + c1.sum_white_elo());
15         c.set_sum_black_elo(c0.sum_black_elo() + c1.sum_black_elo());
16         c.set_num_elo(c0.num_elo() + c1.num_elo());
17         if (c0.first_timestamp() <= c1.first_timestamp()) {
18                 c.set_opening_num(c0.opening_num());
19                 if (c0.has_first_timestamp()) {
20                         c.set_first_timestamp(c0.first_timestamp());
21                 }
22                 c.set_pgn_file_num(c0.pgn_file_num());
23                 c.set_pgn_start_position(c0.pgn_start_position());
24         } else {
25                 c.set_opening_num(c1.opening_num());
26                 if (c1.has_first_timestamp()) {
27                         c.set_first_timestamp(c1.first_timestamp());
28                 }
29                 c.set_pgn_file_num(c1.pgn_file_num());
30                 c.set_pgn_start_position(c1.pgn_start_position());
31         }
32
33         // Merge the moves, with deduplication.
34         unordered_set<string> moves;
35         for (int i = 0; i < c0.move_size(); ++i) {
36                 moves.insert(c0.move(i));
37                 c.add_move(c0.move(i));
38         }
39         for (int i = 0; i < c1.move_size(); ++i) {
40                 if (!moves.count(c1.move(i))) {
41                         c.add_move(c1.move(i));
42                 }
43         }
44
45         return c;
46 }