home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / endgame < prev    next >
Encoding:
Text File  |  1995-03-11  |  3.2 KB  |  128 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35. #include "header.h"
  36. #include <stdio.h>
  37.  
  38. int mk,uk,mymove,umove; 
  39.  
  40. void endgame()
  41. /* count pieces and announce the winner */
  42. {
  43.  char an[10];
  44.  int i, j, mtot, utot, cont;
  45.  
  46.  printf("\nTo count score, we need the following steps:\n");
  47.  printf("First, I need you to remove all dead pieces on the board.\n");
  48.  printf("Second, I need you to fill in neutral territories with ");
  49.  printf("pieces.\n");
  50.  printf("Last, I will fill in all pieces and anounce the winner.\n");
  51.  
  52. /* remove dead pieces */
  53.  printf("\nFirst, you should enter the dead pieces (blank and white) to");
  54.  printf(" be removed.  Enter\n");
  55.  printf(" 'stop' when you have finished.\n");
  56.  
  57.  cont = 1;
  58.  do {
  59.      printf("Dead piece? ");
  60.      scanf("%s", an);
  61.      if (strcmp(an, "stop"))
  62.        {
  63.     getij(an, &i, &j);
  64.     if (p[i][j] == mymove)
  65.       {
  66.        p[i][j] = EMPTY;
  67.        mk++;
  68.      }
  69.     else
  70.        if (p[i][j] == umove)
  71.          {
  72.           p[i][j] = EMPTY;
  73.           uk++;
  74.         }
  75.     showboard();
  76.       }
  77.     else
  78.        cont = 0;
  79.    }
  80.  while (cont);
  81.  
  82. /* fill in neutral */
  83.  printf("Next, you need to fill in pieces (black and white) in all neutral");
  84.  printf(" territories.\n");
  85.  printf("Enter your and my pieces alternately and enter 'stop' when finish\n");
  86.  cont = 1;
  87.  
  88.  do {
  89.      printf("Your piece? ");
  90.      scanf("%s", an);
  91.      if (strcmp(an, "stop"))
  92.        {
  93.     getij(an, &i, &j);
  94.     p[i][j] = umove;
  95.     printf("My piece? ");
  96.     scanf("%s", an);
  97.     getij(an, &i, &j);
  98.     p[i][j] = mymove;
  99.     showboard();
  100.       }
  101.      else
  102.     cont = 0;
  103.    }
  104.   while (cont);
  105.  
  106. /* set empty to side they belong to */
  107.   for (i = 0; i < 19; i++)
  108.      for (j = 0; j < 19; j++)
  109.     if (p[i][j] == EMPTY)
  110.        p[i][j] = findcolor(i, j);
  111.  
  112. /* count total */
  113.   mtot = 0;  utot = 0;
  114.   for (i = 0; i < 19; i++)
  115.      for (j = 0; j < 19; j++)
  116.     if (p[i][j] == mymove)
  117.       ++mtot;
  118.     else
  119.        if (p[i][j] == umove)
  120.          ++utot;
  121.  
  122.   showboard();
  123.   printf("Your total number of pieces %d\n", utot);
  124.   printf("My total number of pieces %d\n", mtot);
  125.  
  126. }  /* end endgame */
  127.  
  128.