home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / getmove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  3.3 KB  |  117 lines  |  [TEXT/R*ch]

  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.  
  36. #include <stdio.h>
  37.  
  38. #define writeMGTexists
  39. #ifdef writeMGTexists
  40. extern char *fname;
  41. #else
  42. extern int mymove, umove;
  43. extern int mk, uk;    /* piece captured */
  44. extern int opn[9];
  45. #endif
  46.  
  47. #define EMPTY 0
  48.  
  49. extern unsigned char p[19][19];
  50. extern int play, pass;
  51.  
  52. static char fnameBuffer[128];
  53. extern int rflag, opposingStone;
  54. extern int randmove(int*,int*,int);
  55.  
  56. getmove(int *i, int *j)
  57. /* interpret response of human move to board position */
  58. {
  59.    FILE *fp;
  60.    int m, n;
  61.    char move[128];
  62.  
  63.    if (rflag) { randmove(i, j, opposingStone); return; }
  64.    move[0] = 0;
  65.    printf("your move? ");
  66.    gets(move);
  67.  
  68.    if      (strcmp(move, "stop") == 0) play = 0; /* stop game */
  69.    else if (strcmp(move, "quit") == 0) play = 0; /* stop game */
  70.    else if (strcmp(move, "exit") == 0) play = 0; /* stop game */
  71.    else if (strncmp(move, "rand", 4) == 0) { rflag = 2; getmove(i, j); }
  72.    else if (strcmp(move, "undo") == 0) {
  73.      undo(2);
  74.      showboard();
  75.      getmove(i,j);
  76.    }
  77.    else if (strcmp(move, "save") == 0) {
  78. #ifdef writeMGTexists
  79.      fnameBuffer[0] = 0;
  80.      if (scanf("%s",fnameBuffer) == 1) {
  81.        saveSmartGoFile(fnameBuffer);
  82.        printf("saved game to file %s\n",fnameBuffer);
  83.      }
  84.      getmove(i,j);
  85. #else
  86. /* save data and stop game */
  87.      fp = fopen("gnugo.dat", "w");
  88. /* save board configuration */
  89.      for (m = 0; m < 19; m++)
  90.        for (n = 0; n < 19; n++)
  91.            fprintf(fp, "%c", p[m][n]);
  92. /* my color, pieces captured */
  93.          fprintf(fp, "%d %d %d ", mymove, mk, uk);
  94. /* opening pattern flags */
  95.          for (m = 0; m < 9; m++)
  96.            fprintf(fp, "%d ", opn[m]);
  97.  
  98.      fclose(fp);
  99.      play = -1;
  100. #endif
  101.      }
  102.      else if (strcmp(move, "pass") == 0 || move[0] == 0) { /* human pass */
  103.         pass++;
  104.         *i = -1;   /* signal pass */
  105.      }
  106.      else {
  107.       pass = 0;
  108.         /* move[0] from A to T, move[1] move[2] from 1 to 19 */
  109.         /* convert move to coordinate */
  110.       if (!getij(move, i, j) || (p[*i][*j] != EMPTY) || suicide(*i, *j))
  111.       {
  112.            printf("illegal move !\n");
  113.            getmove(i, j);
  114.           }
  115.      }
  116. }  /* end getmove */
  117.