showterri display territory\n\
"
-/* some options for the ascii interface */
+/* ANSI color codes */
+#define RESETCOLOR "\x1B[0m"
+#define WHITECOLOR "\x1B[41m"
+#define BLACKCOLOR "\x1B[44m"
+#define TILE1COLOR "\x1B[47m"
+#define TILE2COLOR "\x1B[107m"
+#define TILE3COLOR "\x1B[43m"
+
+/* some options for the ansi interface */
static int opt_showboard = 1;
static int showdead = 0;
static SGFTree sgftree;
static int current_score_estimate = NO_SCORE;
static void do_play_ansi(Gameinfo* gameinfo, bool strict);
-static int ascii_endgame(Gameinfo* gameinfo, int reason);
-static void ascii_count(Gameinfo* gameinfo);
+static int ansi_endgame(Gameinfo* gameinfo, int reason, bool strict);
+static void ansi_count(Gameinfo* gameinfo, bool strict);
static void showcapture(char* line);
static void showdefense(char* line);
-static void ascii_goto(Gameinfo* gameinfo, char* line);
-static void ascii_free_handicap(Gameinfo* gameinfo, char* handicap_string);
+static void ansi_goto(Gameinfo* gameinfo, char* line);
+static void ansi_free_handicap(Gameinfo* gameinfo, char* handicap_string, bool strict);
/* If sgf game info is written can't reset parameters like handicap, etc. */
static int sgf_initialized;
/*
- * Create letterbar for the top and bottom of the ASCII board.
+ * Create letterbar for the top and bottom of the ANSI board.
*/
static void
return;
}
-#define WHITECOLOR "\x1B[41m"
-#define BLACKCOLOR "\x1B[44m"
-#define RESETCOLOR "\x1B[0m"
-
-#define BACK1COLOR "\x1B[43m"
-#define BACK2COLOR "\x1B[47m"
-
/*
- * Display the board position when playing in ASCII.
+ * Display the board position when playing in ANSI.
*/
static void
-ascii_showboard(void)
+ansi_showboard(bool strict)
{
int i, j;
char letterbar[64];
pos_is_move = 0;
dead = (dragon_status(POS(i, j)) == DEAD) && showdead;
switch (BOARD(i, j) + pos_is_move + last_pos_was_move) {
- case EMPTY + 128:
- case EMPTY:
- if (i % 2 == 0) {
- if (j % 2 == 0) {
- printf(BACK1COLOR " " RESETCOLOR);
- } else {
- printf(BACK2COLOR " " RESETCOLOR);
- }
- } else {
- if (j % 2 == 0) {
- printf(BACK2COLOR " " RESETCOLOR);
- } else {
- printf(BACK1COLOR " " RESETCOLOR);
- }
- }
- last_pos_was_move = 0;
- break;
case BLACK:
+ case BLACK + 256:
printf(BLACKCOLOR " " RESETCOLOR);
last_pos_was_move = 0;
break;
case WHITE:
+ case WHITE + 256:
printf(WHITECOLOR " " RESETCOLOR);
last_pos_was_move = 0;
break;
printf(WHITECOLOR "()" RESETCOLOR);
last_pos_was_move = 0;
break;
+ case EMPTY:
+ case EMPTY + 128:
case EMPTY + 256:
if (i % 2 == 0) {
if (j % 2 == 0) {
- printf(BACK1COLOR " " RESETCOLOR);
+ printf(TILE1COLOR " " RESETCOLOR);
} else {
- printf(BACK2COLOR " " RESETCOLOR);
+ if (strict) {
+ printf(TILE3COLOR " " RESETCOLOR);
+ } else {
+ printf(TILE2COLOR " " RESETCOLOR);
+ }
}
} else {
if (j % 2 == 0) {
- printf(BACK2COLOR " " RESETCOLOR);
+ if (strict) {
+ printf(TILE3COLOR " " RESETCOLOR);
+ } else {
+ printf(TILE2COLOR " " RESETCOLOR);
+ }
} else {
- printf(BACK1COLOR " " RESETCOLOR);
+ printf(TILE1COLOR " " RESETCOLOR);
}
}
last_pos_was_move = 0;
break;
- case BLACK + 256:
- printf(BLACKCOLOR " " RESETCOLOR);
- last_pos_was_move = 0;
- break;
- case WHITE + 256:
- printf(WHITECOLOR " " RESETCOLOR);
- last_pos_was_move = 0;
- break;
default:
fprintf(stderr, "Illegal board value %d\n", (int)BOARD(i, j));
exit(EXIT_FAILURE);
clock_print(BLACK);
}
-} /* end ascii_showboard */
+} /* end ansi_showboard */
/*
* command help
*/
static int
-computer_move(Gameinfo* gameinfo, int* passes)
+computer_move(Gameinfo* gameinfo, int* passes, bool strict)
{
int move;
float move_value;
adjust_level_offset(gameinfo->to_move);
move = genmove(gameinfo->to_move, &move_value, &resign);
if (resignation_allowed && resign) {
- int state = ascii_endgame(gameinfo, 2);
+ int state = ansi_endgame(gameinfo, 2, strict);
if (state != -1)
return state;
*/
static int
-do_move(Gameinfo* gameinfo, char* command, int* passes, int force)
+do_move(Gameinfo* gameinfo, char* command, int* passes, int force, bool strict)
{
int move = string_to_location(board_size, command);
sgffile_output(&sgftree);
if (opt_showboard) {
- ascii_showboard();
+ ansi_showboard(strict);
printf("GNU Go is thinking...\n");
}
}
gameinfo->to_move = OTHER_COLOR(gameinfo->to_move);
- return computer_move(gameinfo, passes);
+ return computer_move(gameinfo, passes, strict);
}
/*
*/
static int
-do_pass(Gameinfo* gameinfo, int* passes, int force)
+do_pass(Gameinfo* gameinfo, int* passes, int force, bool strict)
{
(*passes)++;
init_sgf(gameinfo);
return 0;
}
- return computer_move(gameinfo, passes);
+ return computer_move(gameinfo, passes, strict);
}
/*
/* Does the computer play first? If so, make a move. */
if (gameinfo->computer_player == gameinfo->to_move)
- state = computer_move(gameinfo, &passes);
+ state = computer_move(gameinfo, &passes, strict);
- /* main ASCII Play loop */
+ /* main ANSI Play loop */
while (state == 0) {
/* Display game board. */
if (opt_showboard)
- ascii_showboard();
+ ansi_showboard(strict);
#if !READLINE
/* Print the prompt */
/* Get the command or move. */
switch (get_command(command)) {
case RESIGN:
- state = ascii_endgame(gameinfo, 1);
+ state = ansi_endgame(gameinfo, 1, strict);
break;
case END:
}
while (*command && *command != ' ')
command++;
- ascii_free_handicap(gameinfo, command);
+ ansi_free_handicap(gameinfo, command, strict);
break;
case SETKOMI:
case DISPLAY:
if (!opt_showboard)
- ascii_showboard();
+ ansi_showboard(strict);
break;
case FORCE:
command += 6; /* skip the force part... */
switch (get_command(command)) {
case MOVE:
- state = do_move(gameinfo, command, &passes, 1);
+ state = do_move(gameinfo, command, &passes, 1, strict);
break;
case PASS:
- state = do_pass(gameinfo, &passes, 1);
+ state = do_pass(gameinfo, &passes, 1, strict);
break;
default:
printf("Illegal forced move: %s %d\n", command,
break;
case MOVE:
- state = do_move(gameinfo, command, &passes, 0);
+ state = do_move(gameinfo, command, &passes, 0, strict);
break;
case PASS:
- state = do_pass(gameinfo, &passes, 0);
+ state = do_pass(gameinfo, &passes, 0, strict);
break;
case PLAY:
for (m = 0; m < num; m++) {
gameinfo->computer_player
= OTHER_COLOR(gameinfo->computer_player);
- state = computer_move(gameinfo, &passes);
+ state = computer_move(gameinfo, &passes, strict);
if (state)
break;
if (passes >= 2)
if (gameinfo->computer_player == WHITE)
gameinfo->computer_player = BLACK;
if (gameinfo->computer_player == gameinfo->to_move)
- state = computer_move(gameinfo, &passes);
+ state = computer_move(gameinfo, &passes, strict);
break;
case PLAYWHITE:
if (gameinfo->computer_player == BLACK)
gameinfo->computer_player = WHITE;
if (gameinfo->computer_player == gameinfo->to_move)
- state = computer_move(gameinfo, &passes);
+ state = computer_move(gameinfo, &passes, strict);
break;
case SWITCH:
gameinfo->computer_player = OTHER_COLOR(gameinfo->computer_player);
- state = computer_move(gameinfo, &passes);
+ state = computer_move(gameinfo, &passes, strict);
break;
case UNDO:
case CMD_GOTO:
strtok(command, " ");
- ascii_goto(gameinfo, strtok(NULL, " "));
+ ansi_goto(gameinfo, strtok(NULL, " "));
break;
case CMD_SAVE:
init_sgf(gameinfo);
writesgf(sgftree.root, tmpstring);
printf("You may resume the game");
- printf(" with -l %s --mode ascii\n", tmpstring);
+ printf(" with -l %s --mode ansi\n", tmpstring);
printf("or load %s\n", tmpstring);
} else
printf("Please specify filename\n");
}
if (passes >= 2)
- state = ascii_endgame(gameinfo, 0);
+ state = ansi_endgame(gameinfo, 0, strict);
}
#if READLINE
free(line_ptr);
/* Communicates with user after a game has ended. */
static int
-ascii_endgame(Gameinfo* gameinfo, int reason)
+ansi_endgame(Gameinfo* gameinfo, int reason, bool strict)
{
char line[80];
char* line_ptr;
case COUNT:
if (reason == 0)
- ascii_count(gameinfo);
+ ansi_count(gameinfo, strict);
break;
case CONTINUE:
return state;
}
-/* ascii_count() scores the game.
+/* ansi_count() scores the game.
*/
static void
-ascii_count(Gameinfo* gameinfo)
+ansi_count(Gameinfo* gameinfo, bool strict)
{
char line[12];
int done = 0;
printf("\nGame over. Let's count!.\n");
showdead = 1;
- ascii_showboard();
+ ansi_showboard(strict);
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");
} else if (!strncmp(line, "undo", 4)) {
printf("UNDO not allowed anymore. The status of the stones now\n");
printf("toggles after entering the location of it.\n");
- ascii_showboard();
+ ansi_showboard(strict);
} else {
int pos = string_to_location(board_size, line);
if (pos == NO_MOVE || board[pos] == EMPTY)
enum dragon_status status = dragon_status(pos);
status = (status == DEAD) ? ALIVE : DEAD;
change_dragon_status(pos, status);
- ascii_showboard();
+ ansi_showboard(strict);
}
}
}
}
static void
-ascii_goto(Gameinfo* gameinfo, char* line)
+ansi_goto(Gameinfo* gameinfo, char* line)
{
const char* movenumber = line;
}
static void
-ascii_free_handicap(Gameinfo* gameinfo, char* handicap_string)
+ansi_free_handicap(Gameinfo* gameinfo, char* handicap_string, bool strict)
{
int handi;
int i;
handi = 0;
while (1) {
- ascii_showboard();
+ ansi_showboard(strict);
printf("\nType in coordinates of next handicap stone, or one of the following commands:\n");
printf(" undo take back the last stone placed\n");
printf(" clear remove all the stones placed so far\n");