2 More board functions related to cleaning and outputing board states.
14 #include "state_changes.h"
17 extern bool is_hoshi
[TOTAL_BOARD_SIZ
];
22 Clears the contents of a board.
27 memset(b
->p
, EMPTY
, TOTAL_BOARD_SIZ
);
28 b
->last_played
= b
->last_eaten
= NONE
;
33 Clears the contents of an output board.
38 memset(b
->tested
, false, TOTAL_BOARD_SIZ
);
44 Format a string with a representation of the contents of an output board.
45 RETURNS string representation
47 void out_board_to_string(
52 for (move m
= 0; m
< TOTAL_BOARD_SIZ
; ++m
) {
54 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " %4.2f", src
->value
[m
]);
56 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " -- ");
59 if (((m
+ 1) % BOARD_SIZ
) == 0) {
60 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n");
63 snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "Pass: %4.2f\n", src
->pass
);
68 Prints the string representation on an output board.
70 void fprint_out_board(
75 out_board_to_string(s
, b
);
82 Format a string with a representation of the contents of a board, complete with
83 ko violation indication and subject to the display options of european/japanese
84 styles (defined in board.h).
85 RETURNS string representation
89 const u8 p
[static TOTAL_BOARD_SIZ
],
96 if (last_eaten
!= NONE
) {
98 memcpy(tmp
.p
, p
, TOTAL_BOARD_SIZ
);
99 tmp
.last_played
= last_played
;
100 tmp
.last_eaten
= last_eaten
;
101 u8 own
= BLACK_STONE
;
103 if (is_board_move(last_played
) && p
[last_played
] == BLACK_STONE
) {
107 if (test_ko(&tmp
, last_eaten
, own
)) {
117 #if (!EUROPEAN_NOTATION) && (BOARD_SIZ > 9)
118 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " ");
120 for (u8 i
= 0; i
< BOARD_SIZ
; ++i
) {
122 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%2u", (i
+ 1) / 10);
124 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " ");
128 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n");
131 if (BOARD_SIZ
< 10) {
132 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " ");
134 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " ");
137 for (u8 i
= 0; i
< BOARD_SIZ
; ++i
) {
138 #if EUROPEAN_NOTATION
145 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " %c", c
);
147 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " %u", (i
+ 1) % 10);
154 for (move m
= 0; m
< TOTAL_BOARD_SIZ
; ++m
) {
155 if ((m
% BOARD_SIZ
== 0)) {
156 move n
= BOARD_SIZ
- (m
/ BOARD_SIZ
);
158 if (BOARD_SIZ
< 10) {
159 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n%2u", n
);
161 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n%3u", n
);
167 move_to_coord(m
, &x
, &y
);
169 char last_play_indicator
= (m
== last_played
) ? '(' : ((m
== last_played
+ 1 && x
> 0) ? ')' : ' ');
174 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c!", last_play_indicator
);
175 } else if (is_hoshi
[m
]) {
176 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c+", last_play_indicator
);
178 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c%c", last_play_indicator
, EMPTY_STONE_CHAR
);
182 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c%c", last_play_indicator
, BLACK_STONE_CHAR
);
185 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c%c", last_play_indicator
, WHITE_STONE_CHAR
);
188 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c?", last_play_indicator
);
191 if (x
== BOARD_SIZ
- 1) {
192 last_play_indicator
= (m
== last_played
) ? ')' : ' ';
193 move n
= BOARD_SIZ
- (m
/ BOARD_SIZ
);
195 if (BOARD_SIZ
< 10) {
196 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c%u", last_play_indicator
, n
);
198 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%c%2u", last_play_indicator
, n
);
207 if (BOARD_SIZ
< 10) {
208 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n ");
210 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n ");
213 for (u8 i
= 0; i
< BOARD_SIZ
; ++i
) {
214 #if EUROPEAN_NOTATION
220 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " %c", c
);
222 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " %u", i
>= 9 ? (i
+ 1) / 10 : (i
+ 1) % 10);
225 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n");
227 #if (!EUROPEAN_NOTATION) && (BOARD_SIZ > 9)
228 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " ");
229 for (u8 i
= 0; i
< BOARD_SIZ
; ++i
) {
231 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "%2u", (i
+ 1) % 10);
233 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, " ");
236 idx
+= snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\n");
239 if (last_played
== PASS
) {
240 snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\nLast play was a pass\n");
241 } else if (last_played
!= NONE
) {
242 char * mstr
= alloc();
243 #if EUROPEAN_NOTATION
244 coord_to_alpha_num(mstr
, last_played
);
246 coord_to_num_num(mstr
, last_played
);
248 snprintf(dst
+ idx
, MAX_PAGE_SIZ
- idx
, "\nLast played %s\n", mstr
);
255 Print a board string representation.
262 board_to_string(s
, b
->p
, b
->last_played
, b
->last_eaten
);
263 fprintf(fp
, "%s", s
);