-
Notifications
You must be signed in to change notification settings - Fork 0
/
handicaptest.d
99 lines (88 loc) · 2.37 KB
/
handicaptest.d
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
import std.conv;
import std.stdio;
import std.string;
import position;
import setupboard;
static char[] usage_str =
"usage: handicaptest <handicap pieces> [number of playouts]";
int main(char[][] args)
{
SetupGenerator setgen = new SetupGenerator();
setgen.random_all = true;
Position pos = Position.allocate();
uint tests = 1000000;
int wins = 0;
if (args.length < 2)
{
writefln(usage_str);
return 1;
}
if (args.length > 2)
{
try {
tests = toUint(args[2]);
} catch (ConvError E)
{
writefln("Could not understand the number of playouts");
writefln("\n%s", usage_str);
return 1;
}
}
int[13] handicap = [0, 8,2,2,2,1,1, 8,2,2,2,1,1];
for (int i = 0; i < args[1].length; i++)
{
int p = find(".RCDHMErcdhme", args[1][i]);
if (p < 1)
{
writefln("Illegal piece given, %s", args[1][i]);
return 1;
}
if (handicap[p] == 0)
{
writefln("All %s pieces already handicapped");
return 1;
}
handicap[p] -= 1;
}
Piece[][2] pieces;
for (int i=Piece.BELEPHANT; i > Piece.EMPTY; i--)
{
int pside = (i < Piece.BRABBIT) ? Side.WHITE : Side.BLACK;
for (int j=0; j < handicap[i]; j++)
{
pieces[pside].length = pieces[pside].length + 1;
pieces[pside][length-1] = cast(Piece)i;
}
}
writef("Playing ");
int rnum = 0;
for (int i = 0; i < pieces[0].length; i++)
{
if (pieces[0][i] == Piece.WRABBIT)
rnum++;
else
writef("%s", ".RCDHME"[pieces[0][i]]);
}
writef("%dR vs ", rnum);
rnum = 0;
for (int i = 0; i < pieces[1].length; i++)
{
if (pieces[1][i] == Piece.BRABBIT)
rnum++;
else
writef("%s", ".......rcdhme"[pieces[1][i]]);
}
writefln("%dr", rnum);
for (int i=0; i < tests; i++)
{
pos.clear();
setgen.setup_handicap(pieces[0], pos);
setgen.setup_handicap(pieces[1], pos);
PlayoutResult result = playout_steps(pos);
if (result.endscore == 1)
wins += 1;
}
writefln("Win percentage for gold %.2f%%", (cast(double)wins / tests)*100);
writefln("%d playouts with %d wins", tests, wins);
return 0;
}