diff -r -u gnugo-3.2/interface/play_ascii.c gnugo-3.2_color/interface/play_ascii.c --- gnugo-3.2/interface/play_ascii.c Fri Apr 12 16:23:54 2002 +++ gnugo-3.2_color/interface/play_ascii.c Tue Dec 3 11:18:30 2002 @@ -30,6 +30,7 @@ #include "liberty.h" #include "interface.h" #include "sgftree.h" +#include "../utils/gg_utils.h" #define DEBUG_COMMANDS "\ capture try to capture indicated group\n\ @@ -183,6 +184,128 @@ return; } +/* + * ZB Display the colored board position when playing in ASCII. + */ + +static void +ascii_colored_showboard(void) +{ + int i, j; + char letterbar[64]; + int last_pos_was_move; + int pos_is_move; + int dead; + +/*ZB*/ + gg_init_color(); +/* write_color_char_stdout(1,'Z'); */ +/****/ + + make_letterbar(board_size, letterbar); + set_handicap_spots(board_size); + + printf("\n"); + printf(" White has captured %d pieces\n", black_captured); + printf(" Black has captured %d pieces\n", white_captured); + if (showscore) { + if (current_score_estimate == NO_SCORE) + printf(" No score estimate is available yet.\n"); + else if (current_score_estimate < 0) + printf(" Estimated score: Black is ahead by %d\n", + -current_score_estimate); + else if (current_score_estimate > 0) + printf(" Estimated score: White is ahead by %d\n", + current_score_estimate); + else + printf(" Estimated score: Even!\n"); + } + + printf("\n"); + + fflush(stdout); + printf("%s%s\n", (emacs ? "EMACS1\n" : ""), letterbar); + fflush(stdout); + + for (i = 0; i < board_size; i++) { + printf(" %2d", board_size - i); + last_pos_was_move = 0; + for (j = 0; j < board_size; j++) { + if (last_move_i == i && last_move_j == j) + pos_is_move = 128; + else + pos_is_move = 0; + dead = (matcher_status(POS(i, j))==DEAD) && showdead; + switch (BOARD(i, j) + pos_is_move + last_pos_was_move) { + case EMPTY+128: + case EMPTY: + printf(" %c", hspots[i][j]); + last_pos_was_move = 0; + break; + case BLACK: + if (dead) write_color_string_stdout(1," x"); else write_color_string_stdout(1," X"); + /*if (dead) printf(" %c", 'x'); else printf(" %c", 'X');*/ + /*printf(" %c", dead ? 'x' : 'X');*/ + last_pos_was_move = 0; + break; + case WHITE: + if (dead) write_color_string_stdout(6," o"); else write_color_string_stdout(6," O"); + /*if (dead) printf(" %c", 'o'); else printf(" %c", 'O');*/ + /*printf(" %c", dead ? 'o' : 'O');*/ + last_pos_was_move = 0; + break; + case BLACK+128: + write_color_string_stdout(1,"(X)"); + /*printf("(%c)", 'X');*/ + last_pos_was_move = 256; + break; + case WHITE+128: + write_color_string_stdout(6,"(O)"); + /*printf("(%c)", 'O');*/ + last_pos_was_move = 256; + break; + case EMPTY+256: + printf("%c", hspots[i][j]); + last_pos_was_move = 0; + break; + case BLACK+256: + /*printf("%c", dead ? 'x' : 'X');*/ + if (dead) write_color_string_stdout(1,"x"); else write_color_string_stdout(1,"X"); + last_pos_was_move = 0; + break; + case WHITE+256: + /*printf("%c", dead ? 'o' : 'O');*/ + if (dead) write_color_string_stdout(6,"o"); else write_color_string_stdout(6,"O"); + last_pos_was_move = 0; + break; + default: + fprintf(stderr, "Illegal board value %d\n", BOARD(i, j)); + exit(EXIT_FAILURE); + break; + } + } + + if (last_pos_was_move == 0) { + if (board_size > 10) + printf(" %2d", board_size - i); + else + printf(" %1d", board_size - i); + } + else { + if (board_size > 10) + printf("%2d", board_size - i); + else + printf("%1d", board_size - i); + } + printf("\n"); + } + + fflush(stdout); + printf("%s\n\n", letterbar); + fflush(stdout); + +} /* end ascii_colored_showboard */ + /* * Display the board position when playing in ASCII. @@ -293,6 +416,7 @@ } /* end ascii_showboard */ + /* * command help */ @@ -506,7 +630,8 @@ last_move_j = j; if (opt_showboard && !emacs) { - ascii_showboard(); + /*ascii_showboard();*/ + ascii_colored_showboard(); printf("GNU Go is thinking...\n"); } if (force) { @@ -607,7 +732,8 @@ while (passes < 2 && !time_to_die) { /* Display game board. */ if (opt_showboard) - ascii_showboard(); + /*ascii_showboard();*/ + ascii_colored_showboard(); /* Print the prompt */ mprintf("%s(%d): ", color_to_string(gameinfo->to_move), movenum + 1); @@ -754,7 +880,8 @@ } case DISPLAY: if (!opt_showboard) - ascii_showboard(); + /*ascii_showboard();*/ + ascii_colored_showboard(); break; case FORCE: command += 6; /* skip the force part... */ @@ -1017,7 +1144,8 @@ printf("\nGame over. Let's count!.\n"); showdead = 1; - ascii_showboard(); + /*ascii_showboard();*/ + ascii_colored_showboard(); while (!done) { printf("Dead stones are marked with small letters (x,o).\n"); printf("\nIf you don't agree, enter the location of a group\n\ @@ -1053,7 +1181,8 @@ } else if (!strncmp(line, "undo", 4)) { printf("UNDO not allowed anymore. The status of the stones now toggles after entering the location of it.\n"); - ascii_showboard(); + /*ascii_showboard();*/ + ascii_colored_showboard(); } else { if (!ascii2pos(line, &i, &j) || BOARD(i, j) == EMPTY) @@ -1062,7 +1191,8 @@ int status = matcher_status(POS(i, j)); status = (status == DEAD) ? ALIVE : DEAD; change_matcher_status(POS(i, j), status); - ascii_showboard(); + /*ascii_showboard();*/ + ascii_colored_showboard(); } } } diff -r -u gnugo-3.2/utils/gg_utils.c gnugo-3.2_color/utils/gg_utils.c --- gnugo-3.2/utils/gg_utils.c Thu Apr 18 23:21:31 2002 +++ gnugo-3.2_color/utils/gg_utils.c Tue Dec 3 10:42:17 2002 @@ -149,6 +149,55 @@ #endif void +write_color_char_no_space_stdout(int c, int x) +{ +#ifdef TERMINFO + + fprintf(stdout, "%s%c", tparm(setaf, c, 0, 0, 0, 0, 0, 0, 0, 0), x); + fputs(tparm(setaf, max_color, 0, 0, 0, 0, 0, 0, 0, 0), stdout); + +#elif defined(ANSI_COLOR) + + fprintf(stdout, "\033[%dm%c\033[0m", 30+c, x); + +#elif defined(WIN32) + + static HANDLE hStdOut = 0; + DWORD iCharsWritten; + BOOL succeed32; + CONSOLE_SCREEN_BUFFER_INFO bufInfo; + if (!hStdOut) { + hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (hStdOut == INVALID_HANDLE_VALUE) { + fprintf(stderr, "Unable to open stdout.\n"); + } + } + + /* Red & Blue are switched from what MS-Windows wants: + * FOREGROUND_BLUE 0x0001 // text color contains blue. + * FOREGROUND_GREEN 0x0002 // text color contains green. + * FOREGROUND_RED 0x0004 // text color contains red + * This magic switches the bits back: + */ + c = (c & 1) * 4 + (c & 2) + (c & 4) / 4; + c += FOREGROUND_INTENSITY; + succeed32 = GetConsoleScreenBufferInfo(hStdOut, &bufInfo); + if (!succeed32) { /* Probably redirecting output, just give plain text. */ + fprintf(stdout, "%c", x); + return; + } + verifyW32(SetConsoleTextAttribute(hStdOut, (WORD) c)); + verifyW32(WriteConsole(hStdOut, &x, 1, &iCharsWritten, 0)); + verifyW32(SetConsoleTextAttribute(hStdOut, bufInfo.wAttributes)); + +#else + + fprintf(stdout, "%c", x); + +#endif +} + +void write_color_char_no_space(int c, int x) { #ifdef TERMINFO @@ -195,6 +244,20 @@ fprintf(stderr, "%c", x); #endif +} + +void +write_color_string_stdout(int c, const char *str) +{ + while (*str) + write_color_char_no_space_stdout(c, *str++); +} + +void +write_color_char_stdout(int c, int x) +{ + fprintf(stderr, " "); + write_color_char_no_space_stdout(c, x); } void diff -r -u gnugo-3.2/utils/gg_utils.h gnugo-3.2_color/utils/gg_utils.h --- gnugo-3.2/utils/gg_utils.h Thu Apr 18 23:21:31 2002 +++ gnugo-3.2_color/utils/gg_utils.h Tue Dec 3 10:54:39 2002 @@ -51,6 +51,8 @@ #endif void gg_init_color(void); +void write_color_char_stdout(int c, int x); +void write_color_string_stdout(int c, const char *str); void write_color_char(int c, int x); void write_color_string(int c, const char *str);