forked from quackle/quackle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leavecalc.c
executable file
·171 lines (130 loc) · 3.65 KB
/
leavecalc.c
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// old, unused reference code
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "board.h"
#include "bag.h"
#include "util.h"
#include "generator.h"
using namespace std;
using namespace Utility;
Generator G;
Board randboard(string leave, int minleft, int maxleft) {
int leaveatmost = minleft + rand()%(maxleft - minleft);
Board B;
B.init();
Bag S;
Rack dummy;
S.fill(dummy, leave);
Rack R[2];
S.refill(R[0]);
S.refill(R[1]);
G.setboard(B);
for (int i = 0; (i < 25) && !S.empty(); i++) {
for (int j = 0; j < 2; j++) {
if (S.size() <= leaveatmost) {
return G.getboard();
}
// cout << S << endl;
// cout << R << endl;
G.setrack(R[j]);
bool canexch = false;
if (S.size() >= 7) {
canexch = true;
}
Move M = G.findstaticbest(canexch);
cout << "randboard M: " << R[j] << " " << M << " " << M.score << " " << M.equity << endl;
if (M.action == Place) {
G.makemove(M);
R[j] -= M;
S.refill(R[j]);
}
else if (M.action == Exchange) {
S.exch(M, R[j]);
}
// cout << B << endl;
R[j] -= M;
S.refill(R[j]);
}
}
return G.getboard();
}
void sim(Board orig, string leave, int n) {
Bag origS;
for (int i = 0; i < 15; i++) {
for (int j = 0; j < 15; j++) {
string c = "";
if (isalpha(orig.letters[i][j])) {
if (isupper(orig.letters[i][j])) {
c += orig.letters[i][j];
}
else {
c = "?";
}
}
Rack dummy;
origS.fill(dummy, c);
}
}
for (int i = 0; i < n; i++) {
Board B = orig;
Rack R[2];
Bag S = origS;
// cout << "S: " << S << endl;
S.fill(R[0], leave);
// cout << "R[0] before it gets filled: " << R[0] << endl;
S.refill(R[0]);
S.refill(R[1]);
Move M[3];
G.setboard(B);
for (int j = 0; j < 3; j++) {
G.setrack(R[j % 2]);
cout << "R[" << j % 2 << "]: " << R[j % 2] << endl;
bool canexch = false;
if (S.size() >= 7) {
canexch = true;
}
M[j] = G.findstaticbest(canexch);
if (M[j].action == Place) {
B.makemove(M[j]);
G.makemove(M[j]);
R[j % 2] -= M[j];
S.refill(R[j % 2]);
}
else if (M[j].action == Exchange) {
S.exch(M[j], R[j % 2]);
}
cout << "M[" << j << "]: " << M[j] << " " << M[j].score << " " << M[j].equity << endl;
cout << B << endl;
R[j % 2] -= M[j];
S.refill(R[j % 2]);
}
}
}
int main(int argc, char** argv) {
//G.loaddawg("twl15new.anadawg");
G.loaddawg("ods.dawg");
G.loadsyn2("syn2");
cout << "loaded dawg" << endl;
srand(time(NULL));
string leave;
if (argc < 2) {
leave = "";
}
else {
leave = argv[1];
}
for (int i = 0; i < leave.length(); i++) {
leave[i] = toupper(leave[i]);
}
cout << "leave: " << leave << endl;
for (int i = 0; i < 1000; i++) {
Board B = randboard(leave, 0, 72);
cout << B << endl;
sim(B, leave, 10);
}
}