/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *
* http://www.gnu.org/software/gnugo/ for more information. *
* Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
* 2008 and 2009 by the Free Software Foundation. *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation - version 3 or *
* (at your option) any later version. *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License in file COPYING for more details. *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02111, USA. *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------
showbord.c -- Show current go board and playing information
-------------------------------------------------------------*/
* NOTE : this is no longer intended as the main user interface
* as it was in GNU Go 1.2. It is now a debugging aid, showing
* the internal state of dragons, and things. But with
* color enabled, it should be easy enough to see the state
* Note : the dragons must have been calculated before this is called
* Stuff to enumerate the dragons
/* Element at origin of each worm stores allocated worm number. */
static unsigned char dragon_num
[BOARDMAX
];
static int next_white
; /* next worm number to allocate */
* 3=yellow/brown [unknown]
/* Both black and white are common background colors and should be
static const int colors
[3][5] = {
{0, 0, 0, 0, 0}, /*not used */
{6, 2, 1, 3, 5}, /* WHITE : dead, alive, critical, unknown, unchecked */
{6, 2, 1, 3, 5} /* BLACK : dead, alive, critical, unknown, unchecked */
static const int domain_colors
[4] = {5, 1, 2, 3}; /* gray, black, white, both */
/* The following four functions define an API for drawing boards. The
* typical use would be along the following lines:
* for (m = 0; m < board_size; m++)
* for (n = 0; n < board_size; n++) {
* draw_color_char(m, n, c, color);
* Coordinate system, hoshi points, and linefeeds are written
* automatically by the board drawing functions. The coordinates m, n
* must be ordered as in the full loops above.
/* Init color and print a line with coordinate letters above the board. */
draw_letter_coordinates(stderr
);
/* Draw a colored character. If c has the value EMPTY, either a "." or
* a "+" is drawn, depending on whether it is a hoshi stone. If this
* is the first or last intersection on a line, the coordinate number
draw_color_char(int m
, int n
, int c
, int color
)
/* Is this the first column? */
fprintf(stderr
, "\n%2d", board_size
- m
);
/* Do we see a hoshi point? */
if (is_hoshi_point(m
, n
))
/* Use fprintf to draw black characters. This way they'll turn out
* white on terminals with black background.
if (color
== GG_COLOR_BLACK
)
fprintf(stderr
, " %c", c
);
write_color_char(color
, c
);
/* Is this the last column? */
fprintf(stderr
, " %-2d", board_size
- m
);
/* Draw a black character as specified above. */
draw_char(int m
, int n
, int c
)
draw_color_char(m
, n
, c
, GG_COLOR_BLACK
);
/* Print a line with coordinate letters under the board. */
draw_letter_coordinates(stderr
);
* Write one stone. Use 'empty' if the board is empty ('-' or '+')
* We use capital letters A,B,... for black, lower case a,b,... for white.
* This allows us to indicate up to 26 dragons uniquely, and more with
/* The variable xo=1 if running gnugo -T, 2 if running gnugo -E, or
* 3 if displaying owl_status.
showchar(int i
, int j
, int empty
, int xo
)
struct dragon_data
*d
; /* dragon data at (i, j) */
d
= &(dragon
[POS(i
, j
)]);
fprintf(stderr
, " %c", empty
);
if (black_eye
[POS(i
, j
)].color
== BLACK
) {
if (white_eye
[POS(i
, j
)].color
== WHITE
)
empty_color
= domain_colors
[3];
empty_color
= domain_colors
[1];
if (black_eye
[POS(i
, j
)].marginal
)
else if (white_eye
[POS(i
, j
)].color
== WHITE
) {
empty_color
= domain_colors
[2];
if (white_eye
[POS(i
, j
)].marginal
)
empty_color
= domain_colors
[0];
write_color_char(empty_color
, empty_char
);
if (xo
== 0 || ! ON_BOARD1(d
->origin
)) {
fprintf(stderr
, " %c", BOARD(i
, j
) == BLACK
? 'X' : 'O');
/* Figure out ascii character for this dragon. This is the
* dragon number allocated to the origin of this worm. */
w
= dragon_num
[d
->origin
];
/* Not yet allocated - allocate next one. */
/* Count upwards for black, downwards for white to reduce confusion. */
if (BOARD(i
, j
) == BLACK
)
w
= dragon_num
[d
->origin
] = next_black
++;
w
= dragon_num
[d
->origin
] = next_white
--;
w
= w
%26 + (BOARD(i
, j
) == BLACK
? 'A' : 'a');
write_color_char(colors
[BOARD(i
, j
)][d
->crude_status
], w
);
if (BOARD(i
, j
) == BLACK
)
write_color_char(domain_colors
[1], 'X');
write_color_char(domain_colors
[2], 'O');
write_color_char(colors
[BOARD(i
, j
)][d2
->owl_status
], w
);
write_color_char(colors
[BOARD(i
, j
)][d
->status
], w
);
* xo=0: black and white XO board for ascii game
* xo=1: colored dragon display
* xo=2: colored eye display
* xo=3: colored owl display
* xo=4: colored matcher status display
/* Set all dragon numbers to 0. */
memset(dragon_num
, 0, sizeof(dragon_num
));
for (i
= 0; i
< board_size
; i
++) {
fprintf(stderr
, "\n%2d", ii
);
for (j
= 0; j
< board_size
; j
++)
showchar(i
, j
, is_hoshi_point(i
, j
) ? '+' : '.', xo
);
fprintf(stderr
, " %d", ii
);
if (xo
== 0 && ((board_size
< 10 && i
== board_size
-2)
|| (board_size
>= 10 && i
== 8)))
fprintf(stderr
, " WHITE (O) has captured %d stones", black_captured
);
if (xo
== 0 && ((board_size
< 10 && i
== board_size
-1)
|| (board_size
>= 10 && i
== 9)))
fprintf(stderr
, " BLACK (X) has captured %d stones", white_captured
);
write_color_string(GG_COLOR_GREEN
, " green=alive");
write_color_string(GG_COLOR_CYAN
, " cyan=dead");
write_color_string(GG_COLOR_RED
, " red=critical");
write_color_string(GG_COLOR_YELLOW
, " yellow=unknown");
write_color_string(GG_COLOR_MAGENTA
, " magenta=unchecked");
/* Some print utility function that don't really have a better place
* in the engine code than here.
static const char *status_names
[] = {
/* Convert a status value to a string. */
status_to_string(enum dragon_status status
)
return status_names
[(int) status
];
/* Convert a read result to a string */
result_to_string(int result
)
case KO_B
: return "KO_B";
case LOSS
: return "LOSS";
case GAIN
: return "GAIN";
case KO_A
: return "KO_A";
#ifndef HAVE_VARIADIC_DEFINE
/* See gnugo.h for related TRACE family macro definitions */
/* Always returns 1 to allow use in short-circuit logical expressions. */
DEBUG_func(int flag
, const char *fmt
, ...)
vgprintf(stderr
, fmt
, ap
);
#endif /*HAVE_VARIADIC_DEFINE*/