-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathposition_frequency.cpp
More file actions
68 lines (57 loc) · 1.26 KB
/
position_frequency.cpp
File metadata and controls
68 lines (57 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <map>
#include <string>
#include <vector>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include "board.h"
#include "move.h"
#include "move_do.h"
#include "pgn.h"
#include "san.h"
#include "square.h"
#include "util.h"
#include "move_legal.h"
#include "polyglot_lib.h"
#include "utils.h"
#include "pgn_utils.h"
using namespace std;
// Test parser
void quit() {
exit(100);
}
const int kMinFreq = 100;
const int kMaxFreq = 100000;
const int kMinPly = 5 * 2;
const int kMaxPly = 30 * 2;
int main(int argc, char * argv[]) {
polyglot_init();
map<string, int> freq;
while (*++argv) {
pgn_t pgn[1];
pgn_open(pgn, *argv);
while (pgn_next_game(pgn)) {
board_t board;
board_start(&board);
char str[256];
int ply = 0;
while (pgn_next_move(pgn,str,256)) {
int move = move_from_san(str, &board);
CHECK(move != MoveNone);
move_do(&board, move);
if (ply >= kMinPly && ply <= kMaxPly) {
freq[BoardToSimpleFen(board)]++;
}
ply++;
}
}
pgn_close(pgn);
}
for (const auto it : freq) {
if (it.second >= kMinFreq && it.second <= kMaxFreq) {
printf("%d,%s\n", it.second, it.first.c_str());
}
}
}