#include typedef struct pos_T { char s; struct pos_T *p; } pos_t; pos_t board[19][19]; pos_t* get_p(int x, int y) { pos_t* p = &board[x][y]; while (p->p != 0) board[x][y].p = p = p->p; return p; } int has_freedom(pos_t* p, char s) { int i,j; for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) if ( board[i][j].s == s && p == get_p(i,j) && ( (i > 0 && board[i-1][j].s == ' ') || (i < 18 && board[i+1][j].s == ' ') || (j > 0 && board[i][j-1].s == ' ') || (j < 18 && board[i][j+1].s == ' '))) return 1; return 0; } void check(int x, int y, char s, char os, pos_t* p) { if (board[x][y].s == s) { pos_t* pp = get_p(x,y); if (pp != p) pp->p = p; } else if (board[x][y].s == os) { pos_t* pp = get_p(x,y); if (!has_freedom(pp, os)) { int i,j; for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) if (pp == get_p(i, j)) { board[i][j].s = ' '; printf(" %d %d e", i+1, j+1); } } } } void place_stone(int x, int y, char s) { char os = s == 'w' ? 'b' : 'w'; pos_t* p = &board[x][y]; p->s = s; p->p = 0; printf("%d %d %c", x+1, y+1, s); if (x > 0) check(x-1, y, s, os, p); if (x < 18) check(x+1, y, s, os, p); if (y > 0) check(x, y-1, s, os, p); if (y < 18) check(x, y+1, s, os, p); printf("\n"); } main() { char buffer[100]; int voorgift = 1; int n = 0, i; { int i, j; for (i = 0; i < 19 ; i++) for (j = 0; j < 19; j++) { board[i][j].s = ' '; board[i][j].p = 0; } } printf("%%!PS-Adobe-2.0 EPSF-2.0\n"); printf("%%%%BoundingBox: 0 0 360 360\n"); printf("%%%%Title: Go game\n"); printf("/dot{0.1 sub exch 0.1 sub exch moveto 0 0.2 rlineto\n"); printf("0.2 0 rlineto 0 -0.2 rlineto closepath fill}def\n"); printf("/v{0.4 0 360 arc closepath gsave fill grestore stroke}def\n"); printf("/w{q p gt{pop pop}{/y exch def /x exch def\n"); printf("x y 0.4 0 360 arc closepath gsave 1 1 1 setrgbcolor eofill grestore stroke\n"); printf("q p eq{x y 0.15 0 360 arc closepath gsave 1 0 0 setrgbcolor eofill grestore stroke}if\n"); printf("}ifelse /q q 1 add def}def\n"); printf("/b{q p gt{pop pop}{/y exch def /x exch def\n"); printf("x y 0.4 0 360 arc closepath gsave fill grestore stroke\n"); printf("q p eq{x y 0.15 0 360 arc closepath gsave 1 0 0 setrgbcolor eofill grestore stroke}if\n"); printf("}ifelse /q q 1 add def}def\n"); printf("/n{/q q 1 add def}def\n"); printf("/shd {dup dup currentrgbcolor 4 -2 roll mul 4 -2\n"); printf("roll mul 4 -2 roll mul setrgbcolor}bind def\n"); printf("/e{q 1 sub p gt {pop pop}{/y exch def /x exch def\n"); printf("x y 0.5 0 360 arc closepath 1 1 1 setrgbcolor\n"); printf("fill 0 0 0 setrgbcolor\n"); printf("x 0.55 sub 1 max y moveto x 0.55 add 19 min y lineto stroke\n"); printf("x y 0.55 sub 1 max moveto x y 0.55 add 19 min lineto stroke\n"); printf("x 4 eq x 10 eq or x 16 eq or y 4 eq y 10 eq or y 16 eq or and{x y dot}if}ifelse}def\n"); printf("/c{q 1 sub p eq {/ct exch def}{pop}ifelse}def\n"); printf("/m{q 1 sub p eq {/mt exch def}{pop}ifelse}def\n"); printf("/l{q 1 sub p eq {/y exch def /x exch def gsave\n"); printf("x y 0.4 0 360 arc closepath 1 1 1 setrgbcolor\n"); printf("fill 0 0 0 setrgbcolor x y moveto -0.23 -0.22 rmoveto\n"); printf("/Times-Roman findfont setfont\n"); printf("show grestore}{pop pop pop}ifelse}def\n"); printf("/g{/p exch def /q 1 def gsave /ct()def /mt()def\n"); printf("30 30 scale 0 8 translate .01 setlinewidth\n"); printf("1 1 19{1 moveto 0 18 rlineto stroke}for\n"); printf("1 1 19{1 exch moveto 18 0 rlineto stroke}for\n"); printf("4 4 dot 4 10 dot 4 16 dot\n"); printf("10 4 dot 10 10 dot 10 16 dot\n"); printf("16 4 dot 16 10 dot 16 16 dot\n"); while (fgets(buffer, 99, stdin)) { if (buffer[0] == ';') { int b_output = 0; int b_pass; int b_x; int b_y; int w_output = 0; int w_pass; int w_x; int w_y; if (strncmp(buffer, ";B[", 3) == 0) { b_output = 1; b_pass = buffer[3] == 't' && buffer[4] == 't'; b_x = buffer[3] - 'a'; b_y = 18 - (buffer[4] - 'a'); if (fgets(buffer, 99, stdin)) { if (strncmp(buffer, ";W[", 3) == 0) { w_pass = buffer[3] == 't' && buffer[4] == 't'; w_x = buffer[3] - 'a'; w_y = 18 - (buffer[4] - 'a'); if (voorgift && !b_pass && w_pass) { n++; printf("%d %d v\n", b_x+1, b_y+1); board[b_x][b_y].s = 'b'; board[b_x][b_y].p = 0; b_output = 0; } else { voorgift = 0; w_output = 1; } } } } if (b_output) { n++; if (b_pass) printf("(black passes) c n\n"); else place_stone(b_x, b_y, 'b'); } if (w_output) { n++; if (w_pass) printf("(white passes) c n\n"); else place_stone(w_x, w_y, 'w'); } } } printf("/Times-Roman findfont 0.8 scalefont setfont\n"); printf("1 0 moveto ct show\n"); printf("0 0 0.5 setrgbcolor 1 -1 moveto mt show\n"); printf("grestore showpage} bind def\n"); printf("%%%%EndProlog\n"); for (i = 1; i <= n; i++) printf("%%%%Page: %d %d\n%d g\n", i, i, i); printf("%%EOF\n"); }