13 static bool board_printed
;
16 board_load(struct board
*b
, FILE *f
, int size
)
18 board_printed
= false;
19 board_resize(b
, size
);
21 for (int y
= size
- 1; y
>= 0; y
--) {
23 if (!fgets(line
, sizeof(line
), f
)) {
24 fprintf(stderr
, "Premature EOF.\n");
27 line
[strlen(line
) - 1] = 0; // chomp
28 if (strlen(line
) != size
) {
29 fprintf(stderr
, "Line not %d char long: %s\n", size
, line
);
32 for (int x
= 0; x
< size
; x
++) {
35 case '.': s
= S_NONE
; break;
36 case 'X': s
= S_BLACK
; break;
37 case 'O': s
= S_WHITE
; break;
38 default: fprintf(stderr
, "Invalid stone %c\n", line
[x
]);
41 if (s
== S_NONE
) continue;
42 struct move m
= { .color
= s
, .coord
= coord_xy(b
, x
+ 1, y
+ 1) };
43 if (board_play(b
, &m
) < 0) {
44 fprintf(stderr
, "Failed to play %s %s\n",
45 stone2str(s
), coord2sstr(m
.coord
, b
));
46 board_print(b
, stderr
);
52 board_print(b
, stderr
);
56 test_sar(struct board
*b
, char *arg
)
58 enum stone color
= str2stone(arg
);
60 coord_t
*cc
= str2coord(arg
, board_size(b
));
61 coord_t c
= *cc
; coord_done(cc
);
62 arg
+= strcspn(arg
, " ") + 1;
65 printf("sar %s %s %d...\t", stone2str(color
), coord2sstr(c
, b
), eres
);
67 int rres
= is_bad_selfatari(b
, color
, c
);
73 if (debug_level
<= 2) {
74 if (DEBUGL(0) && !board_printed
) {
75 board_print(b
, stderr
);
78 printf("sar %s %s %d...\t", stone2str(color
), coord2sstr(c
, b
), eres
);
80 printf("FAILED (%d)\n", rres
);
85 int main(int argc
, char *argv
[])
88 fprintf(stderr
, "Usage: %s TESTFILE [DEBUGLEVEL]\n", argv
[0]);
93 debug_level
= atoi(argv
[2]);
95 FILE *f
= fopen(argv
[1], "r");
101 struct board
*b
= board_init();
103 while (fgets(line
, sizeof(line
), f
)) {
104 line
[strlen(line
) - 1] = 0; // chomp
106 case '%': printf("\n%s\n", line
); continue;
109 if (!strncmp(line
, "boardsize ", 10)) {
110 board_load(b
, f
, atoi(line
+ 10));
111 } else if (!strncmp(line
, "sar ", 4)) {
112 test_sar(b
, line
+ 4);
114 fprintf(stderr
, "Syntax error: %s\n", line
);