home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / findcolr < prev    next >
Encoding:
Text File  |  1995-03-11  |  2.3 KB  |  100 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.  
  36. #include "header.h"
  37. #include <stdio.h>
  38.  
  39. int findcolor(i, j)
  40. /* find color for empty piece */
  41. int i, j;
  42. {
  43.  int k, color1, color2;
  44.  
  45. /* check North neighbor */
  46.  color1 = 0;
  47.  k = i;
  48.  do --k;
  49.  while ((p[k][j] == EMPTY) && (k > 0));
  50.  color1 = p[k][j];
  51.  
  52. /* check South neighbor */
  53.  color2 = 0;
  54.  k = i;
  55.  do k++;
  56.  while ((p[k][j] == EMPTY) && (k < 18));
  57.  color2 = p[k][j];
  58.  
  59.  if (color1)
  60.    {
  61.     if ((color1 == color2) || (color2 == 0))
  62.        return color1;
  63.     else
  64.        return 0;  /* cannot determine */
  65.   }
  66.  else
  67.     if (color2)
  68.        return color2;
  69.     else  /* both zero */
  70.        {
  71. /* check West neighbor */
  72.     color1 = 0;
  73.     k = j;
  74.     do --k;
  75.     while ((p[i][k] == EMPTY) && (k > 0));
  76.     color1 = p[i][k];
  77.  
  78. /* check East neighbor */
  79.     color2 = 0;
  80.     k = j;
  81.     do k++;
  82.     while ((p[i][k] == EMPTY) && (k < 18));
  83.     color2 = p[i][k];
  84.  
  85.     if (color1)
  86.       {
  87.        if ((color1 == color2) || (color2 == 0))
  88.           return color1;
  89.        else
  90.           return 0;  /* cannot determine */
  91.      }
  92.     else
  93.        if (color2)
  94.           return color2;
  95.        else
  96.           return 0;
  97.       }
  98. }  /* end findcolor */
  99.  
  100.