12 static bool board_printed
;
15 board_load(struct board
*b
, FILE *f
, unsigned int size
)
17 board_printed
= false;
18 board_resize(b
, size
);
20 for (unsigned int y
= size
- 1; y
>= 0; y
--) {
22 if (!fgets(line
, sizeof(line
), f
)) {
23 fprintf(stderr
, "Premature EOF.\n");
26 line
[strlen(line
) - 1] = 0; // chomp
27 if (strlen(line
) != size
) {
28 fprintf(stderr
, "Line not %d char long: %s\n", size
, line
);
31 for (unsigned int x
= 0; x
< size
; x
++) {
34 case '.': s
= S_NONE
; break;
35 case 'X': s
= S_BLACK
; break;
36 case 'O': s
= S_WHITE
; break;
37 default: fprintf(stderr
, "Invalid stone %c\n", line
[x
]);
40 if (s
== S_NONE
) continue;
41 struct move m
= { .color
= s
, .coord
= coord_xy(b
, x
+ 1, y
+ 1) };
42 if (board_play(b
, &m
) < 0) {
43 fprintf(stderr
, "Failed to play %s %s\n",
44 stone2str(s
), coord2sstr(m
.coord
, b
));
45 board_print(b
, stderr
);
51 board_print(b
, stderr
);
55 test_sar(struct board
*b
, char *arg
)
57 enum stone color
= str2stone(arg
);
59 coord_t
*cc
= str2coord(arg
, board_size(b
));
60 coord_t c
= *cc
; coord_done(cc
);
61 arg
+= strcspn(arg
, " ") + 1;
64 printf("sar %s %s %d...\t", stone2str(color
), coord2sstr(c
, b
), eres
);
66 int rres
= is_bad_selfatari(b
, color
, c
);
72 if (debug_level
<= 2) {
73 if (DEBUGL(0) && !board_printed
) {
74 board_print(b
, stderr
);
77 printf("sar %s %s %d...\t", stone2str(color
), coord2sstr(c
, b
), eres
);
79 printf("FAILED (%d)\n", rres
);
85 unittest(char *filename
)
87 FILE *f
= fopen(filename
, "r");
93 struct board
*b
= board_init();
95 while (fgets(line
, sizeof(line
), f
)) {
96 line
[strlen(line
) - 1] = 0; // chomp
98 case '%': printf("\n%s\n", line
); continue;
101 if (!strncmp(line
, "boardsize ", 10)) {
102 board_load(b
, f
, atoi(line
+ 10));
103 } else if (!strncmp(line
, "sar ", 4)) {
104 test_sar(b
, line
+ 4);
106 fprintf(stderr
, "Syntax error: %s\n", line
);