home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Games / NeXTGo-3.0-MIS / suicide.c < prev   
Encoding:
C/C++ Source or Header  |  1997-07-06  |  1.6 KB  |  70 lines

  1. #include "comment.header"
  2.  
  3. /* $Id: suicide.c,v 1.3 1997/07/06 19:35:12 ergo Exp $ */
  4.  
  5. /*
  6.  * $Log: suicide.c,v $
  7.  * Revision 1.3  1997/07/06 19:35:12  ergo
  8.  * actual version
  9.  *
  10.  * Revision 1.2  1997/05/04 18:57:15  ergo
  11.  * added time control for moves
  12.  *
  13.  */
  14.  
  15. #define EMPTY 0
  16. #define BLACKSTONE 2
  17.  
  18. extern unsigned char p[19][19], l[19][19];
  19. extern int currentStone, opposingStone, MAXX, MAXY;
  20. extern int lib;
  21. extern int blackCapturedKoI, blackCapturedKoJ, whiteCapturedKoI, whiteCapturedKoJ;  /* piece captured */
  22. extern void countlib(int, int, int);
  23. extern void eval(int);
  24.  
  25. int suicide(int i, int j)
  26. /* check for suicide move of opponent at p[i][j] */
  27. {
  28.  int m, n, k, uik, ujk;
  29.  
  30. /* check liberty of new move */
  31.  lib = 0;
  32.  countlib(i, j, currentStone);
  33.  if (lib == 0)
  34. /* new move is suicide then check if kill my pieces and Ko possibility */
  35.    {
  36. /* assume alive */
  37.     p[i][j] = currentStone;
  38.  
  39. /* check opponent pieces */
  40.     eval(opposingStone);
  41.     k = 0;
  42.  
  43.     for (m = 0; m < MAXX; m++)
  44.       for (n = 0; n < MAXY; n++)
  45. /* count pieces that will be killed */
  46.     if ((p[m][n] == opposingStone) && !l[m][n]) ++k;
  47.  
  48.     if (currentStone == BLACKSTONE) {
  49.       uik = blackCapturedKoI;
  50.       ujk = blackCapturedKoJ;
  51.     } else {
  52.       uik = whiteCapturedKoI;
  53.       ujk = whiteCapturedKoJ;
  54.     }
  55.     if ((k == 0) || (k == 1 && ((i == uik) && (j == ujk))))
  56. /* either no effect on my pieces or an illegal Ko take back */
  57.       {
  58.        p[i][j] = EMPTY;   /* restore to open */
  59.        return 1;
  60.       }
  61.     else
  62. /* good move */
  63.       return 0;
  64.    }
  65.  else
  66. /* valid move */
  67.    return 0;
  68. }  /* end suicide */
  69.  
  70.