-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
68 lines (55 loc) · 1.62 KB
/
test.pl
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
#! /usr/bin/perl
# $Id: test.pl,v 1.1 2003/06/06 12:08:39 martinus Exp $
#
# tests for differences between pmars and exhaust
#
die "usage: $0: start_ix warriorA warriorB\n" if @ARGV < 3;
$start = $ARGV[0];
$WA = $ARGV[1];
$WB = $ARGV[2];
for ($i = $start; $i < 8192; $i++) {
$F = gray($i);
$F = perm13($F);
if ( $F >= 100 && $F <= 8000-100 ) {
if (1) {
print( "(i=$i): $F\n") if $i % 25 == 0;
if ( 0 != play( $F ) ) {
print "(i=$i): difference at position $F\n";
last;
}
}
}
}
exit 0;
sub gray {
my $i=shift;
return $i ^ ($i>>1);
}
# reverse the bits 0..12
sub perm13 {
my $x = shift;
my $y = 0;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1; $y = $y << 1;
$y |= ($x & 1); $x = $x >> 1;
return $y;
}
sub play {
my $F = shift;
my $p, $e;
do { $p = `pmars-server -bkF $F $WA $WB 2>/dev/null`} && $? == 0
or die "$0: execution of 'pmars-server' failed: $?\n";
do { $e = `./exhaust -bkF $F $WA $WB` } && $? == 0
or die "$0: execution of 'exhaust' failed: $?\n";
return $p cmp $e;
}