Quick hackjob to add color when playing in ASCII mode.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Tue, 18 May 2021 12:58:25 +0000 (05:58 -0700)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Tue, 18 May 2021 12:58:25 +0000 (05:58 -0700)
interface/play_ascii.c

index 5b0cdf9..fa2975f 100644 (file)
@@ -184,6 +184,13 @@ set_handicap_spots(int boardsize)
 }
 
 
 }
 
 
+#define WHITECOLOR "\x1B[41m"
+#define BLACKCOLOR "\x1B[44m"
+#define RESETCOLOR "\x1B[0m"
+
+#define BACK1COLOR "\x1B[47m"
+#define BACK2COLOR "\x1B[107m"
+
 /*
  * Display the board position when playing in ASCII.
  */
 /*
  * Display the board position when playing in ASCII.
  */
@@ -202,8 +209,8 @@ ascii_showboard(void)
   set_handicap_spots(board_size);
 
   printf("\n");
   set_handicap_spots(board_size);
 
   printf("\n");
-  printf("    White (O) has captured %d pieces\n", black_captured);
-  printf("    Black (X) has captured %d pieces\n", white_captured);
+  printf("    White (" WHITECOLOR " " RESETCOLOR ") has captured %d pieces\n", black_captured);
+  printf("    Black (" BLACKCOLOR " " RESETCOLOR ") has captured %d pieces\n", white_captured);
   if (showscore) {
     if (current_score_estimate == NO_SCORE)
       printf("    No score estimate is available yet.\n");
   if (showscore) {
     if (current_score_estimate == NO_SCORE)
       printf("    No score estimate is available yet.\n");
@@ -231,55 +238,77 @@ ascii_showboard(void)
   printf("\n");
   fflush(stdout);
   
   printf("\n");
   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 (POS(i, j) == last_move)
-       pos_is_move = 128;
-      else
-       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:
-         printf(" %c", hspots[i][j]);
-         last_pos_was_move = 0;
-         break;
-       case BLACK:
-         printf(" %c", dead ? 'x' : 'X');
-         last_pos_was_move = 0;
-         break;
-       case WHITE:
-         printf(" %c", dead ? 'o' : 'O');
-         last_pos_was_move = 0;
-         break;
-       case BLACK+128:
-         printf("(%c)", 'X');
-         last_pos_was_move = 256;
-         break;
-       case WHITE+128:
-         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');
-         last_pos_was_move = 0;
-         break;
-       case WHITE+256:
-         printf("%c", dead ? 'o' : 'O');
-         last_pos_was_move = 0;
-         break;
-       default: 
-         fprintf(stderr, "Illegal board value %d\n", (int) BOARD(i, j));
-         exit(EXIT_FAILURE);
-         break;
-      }
-    }
+    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 (POS(i, j) == last_move) pos_is_move = 128;
+            else 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:
+                    printf(BLACKCOLOR "  " RESETCOLOR);
+                    last_pos_was_move = 0;
+                    break;
+                case WHITE:
+                    printf(WHITECOLOR "  " RESETCOLOR);
+                    last_pos_was_move = 0;
+                    break;
+                case BLACK+128:
+                    printf(BLACKCOLOR "()" RESETCOLOR);
+                    last_pos_was_move = 256;
+                    break;
+                case WHITE+128:
+                    printf(WHITECOLOR "()" RESETCOLOR);
+                    last_pos_was_move = 256;
+                    break;
+                case EMPTY+256:
+                    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+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);
+                    break;
+            }
+        }
     
     if (last_pos_was_move == 0) {
       if (board_size > 10)
     
     if (last_pos_was_move == 0) {
       if (board_size > 10)