home *** CD-ROM | disk | FTP | other *** search
- /* #[info: */
- /************************************************************************
- * *
- * #### # # # ##### # #### ### *
- * # # # ## ## # ### # # # # *
- * # # # # ## # # # # # # # # *
- * # ## ####### # # ### # ####### ### # *
- * # # # # # # # # # # # # *
- * # # # # # # # # # # # # *
- * #### # # # # ##### ###### # # #### ### *
- * *
- * Jan van der Steen *
- * *
- * Centre for Mathematics and Computer Science *
- * Amsterdam, the Netherlands *
- * *
- *----------------------------------------------------------------------*
- * File : game2asc.c *
- * Purpose : Emit a Go Game Using ASCII characters *
- * Version : 1.4 *
- * Modified: 2/14/93 13:39:05 *
- * Author : Jan van der Steen (jansteen@cwi.nl) *
- ************************************************************************/
- /* #]info: */
- /* #[include: */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "gogame.h"
- #include "game2asc.h"
-
- /* #]include: */
- /* #[define: */
-
- #define COORDINATES "A B C D E F G H J K L M N O P Q R S T"
-
- /* #]define: */
- /* #[prototype: */
-
- #ifdef __STDC__
- # define PROTO(s) s
- #else
- # define PROTO(s) ()
- #endif
-
- static void ascii_chain PROTO((GOGAME *gogame, char *prefix));
-
- #undef PROTO
-
- /* #]prototype: */
-
- /* #[ascii_position: */
-
- void
- ascii_position(gogame, title, prefix)
- /*
- * Print the final position
- */
- GOGAME *gogame;
- char *title;
- char *prefix;
- {
- PLACE p;
- int n = (2*gogame->gm_size - (int)strlen(title))/2 + 3;
-
- fprintf(stdout, "%s\n", prefix);
- fprintf(stdout, "%s %s\n", prefix, COORDINATES);
- for (p = 0; p < gogame->gm_size*gogame->gm_size; p++) {
- GONODE *node = NODE(gogame,p);
-
- if (p % gogame->gm_size == 0) {
- fprintf(stdout, "%s%2d ",
- prefix,
- gogame->gm_size - NODE2J(gogame, node));
- }
- if (node->gn_stone == (GOMOVE *) 0) putc('.', stdout);
- else
- switch(node->gn_stone->mv_side) {
- case BLACK : putc('@', stdout); break;
- case WHITE : putc('O', stdout); break;
- default : putc('?', stdout); break;
- }
- putc(' ', stdout);
- if ((p+1) % gogame->gm_size == 0)
- fprintf(stdout, "%2d\n", gogame->gm_size - NODE2J(gogame, node));
- }
- fprintf(stdout, "%s %s\n", prefix, COORDINATES);
-
- /*
- * Print the title (centered below the Goban)
- */
- fprintf(stdout, "%s\n", prefix);
- fprintf(stdout, "%s" , prefix); while (n-- > 0) putc(' ', stdout);
- fprintf(stdout, "%s\n", title );
- fprintf(stdout, "%s\n", prefix);
- }
-
- /* #]ascii_position: */
- /* #[game2ascii: */
-
- void
- game2ascii(gogame)
- GOGAME *gogame;
- {
- char title[256];
-
- /*
- * Construct title from the name of the players
- */
- sprintf(title,
- "%s (%s) versus %s (%s)",
- (gogame->gm_black) ? gogame->gm_black : "NN",
- (gogame->gm_brank) ? gogame->gm_brank : "NR",
- (gogame->gm_white) ? gogame->gm_white : "NN",
- (gogame->gm_wrank) ? gogame->gm_wrank : "NR");
-
- /*
- * Print the final position
- */
- ascii_position(gogame, title, "%\t");
- }
-
- /* #]game2ascii: */
-