-
Notifications
You must be signed in to change notification settings - Fork 0
/
trap_fuzzer.d
76 lines (66 loc) · 2.01 KB
/
trap_fuzzer.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
import tango.io.Stdout;
import tango.math.random.Random;
import position;
import trapmoves;
import trap_check;
private ulong random_bit(ulong bits)
{
int num = popcount(bits);
int bix = rand.uniformR!(int)(num);
ulong b;
for (int i=0; i <= bix; i++)
{
b = bits & -bits;
bits ^= b;
}
return b;
}
void gen_position(inout Position pos)
{
Piece[] white_pieces;
white_pieces = [Piece.WELEPHANT, Piece.WCAMEL, Piece.WHORSE,
Piece.WHORSE, Piece.WDOG, Piece.WDOG, Piece.WCAT, Piece.WCAT].dup;
Piece[] black_pieces;
black_pieces = [Piece.BELEPHANT, Piece.BCAMEL, Piece.BHORSE,
Piece.BHORSE, Piece.BDOG, Piece.BDOG, Piece.BCAT, Piece.BCAT].dup;
ulong[] restricted_sqr = [0UL, RANK_8, 0, 0, 0, 0, 0, RANK_1, 0, 0, 0, 0, 0];
int[] num_piece = [0, 8, 2, 2, 2, 1, 1, 8, 2, 2, 2, 1, 1];
ulong empty = ALL_BITS_SET;
ulong sqb;
for (Piece pt=Piece.WRABBIT; pt <= Piece.BELEPHANT; pt++)
{
int pt_side = pt < Piece.BRABBIT ? Side.WHITE : Side.BLACK;
for (int n=0; n < num_piece[pt]; n++)
{
sqb = random_bit(empty & ~(TRAPS
& ~neighbors_of(pos.placement[pt_side]))
& ~restricted_sqr[pt]);
empty ^= sqb;
pos.place_piece(pt, sqb);
}
}
pos.set_steps_left(4);
}
int main(char[][] args)
{
Position pos = new Position();
StepList steps = StepList.allocate();
TrapCheck cap_checker = new TrapCheck();
int pos_count;
while (true)
{
gen_position(pos);
pos_count += 1;
Stdout.format("{}w", pos_count).newline;
Stdout(pos.to_long_str()).newline;
cap_checker.check_captures(pos, pos, steps);
Position bpos = pos.reverse();
Stdout.format("{}b", pos_count).newline;
Stdout(bpos.to_long_str()).newline;
cap_checker.check_captures(bpos, bpos, steps);
Position.free(bpos);
assert (steps.numsteps == 0);
pos.clear();
}
return 0;
}