void getmove(char move[], int *i, int *j) /* interpret response of human move to board position */ { FILE *fp; int m, n; if (strcmp(move, "stop") == 0) /* stop game */ play = 0; else { if (strcmp(move, "save") == 0) /* save data and stop game */ { fp = fopen("gnugo.dat", "w"); /* save board configuration */ for (m = 0; m < 19; m++) for (n = 0; n < 19; n++) fprintf(fp, "%c", p[m][n]); /* my color, pieces captured */ fprintf(fp, "%d %d %d ", mymove, mk, uk); /* opening pattern flags */ for (m = 0; m < 9; m++) fprintf(fp, "%d ", opn[m]); fclose(fp); play = -1; } else { if (strcmp(move, "pass") == 0) /* human pass */ { pass++; *i = -1; /* signal pass */ } else { pass = 0; /* move[0] from A to T, move[1] move[2] from 1 to 19 */ /* convert move to coordinate */ if (!getij(move, i, j) || (p[*i][*j] != EMPTY) || suicide(*i, *j)) { if (feof(stdin)) exit(1); printf("illegal move !\n"); printf("your move? "); scanf("%s", move); getmove(move, i, j); } } } } } /* end getmove */
void endgame(void) /* count pieces and announce the winner */ { char an[10]; int i, j, k, N, mtot, utot, cont; int mymovelist[NODES][5]; int umovelist[NODES][5]; printf("\nTo count score, we need the following steps:\n"); printf("First, I need you to remove all dead pieces on the board.\n"); printf("Second, I need you to fill in neutral territories with "); printf("pieces.\n"); printf("Last, I will fill in all pieces and announce the winner.\n"); /* remove dead pieces */ printf("\nFirst, you should enter the dead pieces (black and white) to"); printf(" be removed. Enter\n"); printf(" 'stop' when you have finished.\n"); /* Create an adjacency list for the game board. */ /* First a list for the computer's moves */ createlist(mymove, mymovelist); /* Then a list for our opponent's moves */ createlist(umove, umovelist); cont = 1; do { printf("Dead piece? "); scanf("%s", an); if (strcmp(an, "stop")) { getij(an, &i, &j); if (p[i][j] == mymove) { #ifdef DEBUG printf("Just before bfslist.\n"); #endif N = bfslist(i, j, mymovelist, listpt); #ifdef DEBUG printf("Survived first bfslist.\n"); #endif for (k=0;k<N;k++) { node2ij(listpt[k], &i, &j); p[i][j] = EMPTY; mk++; } } else if (p[i][j] == umove) { #ifdef DEBUG printf("Just before second bfslist.\n"); #endif N = bfslist(i, j, umovelist, listpt); for (k=0;k<N;k++) { node2ij(listpt[k], &i, &j); p[i][j] = EMPTY; uk++; } } showboard(); } else cont = 0; } while (cont); /* fill in neutral */ printf("Next, you need to fill in pieces (black and white) in all neutral"); printf(" territories.\n"); printf("Enter your and my pieces alternately and"); printf(" enter 'stop' when finish\n"); cont = 1; N = 0; do { if ( (N%2) == 0 ) { printf("Your piece? "); scanf("%s", an); if (strcmp(an, "stop")) { getij(an, &i, &j); p[i][j] = umove; showboard(); } else cont = 0; } else { printf("My piece? "); scanf("%s", an); if (strcmp(an, "stop")) { getij(an, &i, &j); p[i][j] = mymove; showboard(); } else cont = 0; } N++; } while (cont); /* set empty to side they belong to */ for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) if (p[i][j] == EMPTY) p[i][j] = findcolor(i, j); /* count total */ mtot = 0; utot = 0; for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) if (p[i][j] == mymove) ++mtot; else if (p[i][j] == umove) ++utot; showboard(); printf("Your total number of pieces %d\n", utot); printf("My total number of pieces %d\n", mtot); } /* end endgame */