home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / games / gnugo / c / opening < prev    next >
Encoding:
Text File  |  1995-03-11  |  2.4 KB  |  92 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 <stdio.h>
  37. #include "header.h"
  38.  
  39. int opening(i, j, cnd, type)
  40. /* get move for opening from game tree */
  41. int *i, *j, *cnd, type;
  42. {
  43.  struct tnode {
  44.    int i, j, ndct, next[8];
  45.   };
  46.  
  47.  static struct tnode tree[] = {
  48.   {-1, -1, 8, { 1, 2, 3, 4, 5, 6, 7, 20}},    /* 0 */
  49.   {2, 3, 2, { 8, 9}},
  50.   {2, 4, 1, {10}},
  51.   {3, 2, 2, {11, 12}},
  52.   {3, 3, 6, {14, 15, 16, 17, 18, 19}},
  53.   {3, 4, 1, {10}},  /* 5 */
  54.   {4, 2, 1, {13}},
  55.   {4, 3, 1, {13}},
  56.   {4, 2, 0},
  57.   {4, 3, 0},
  58.   {3, 2, 0},  /* 10 */
  59.   {2, 4, 0},
  60.   {3, 4, 0},
  61.   {2, 3, 0},
  62.   {2, 5, 1, {10}},
  63.   {2, 6, 1, {10}},  /* 15 */
  64.   {3, 5, 1, {10}},
  65.   {5, 2, 1, {13}},
  66.   {5, 3, 1, {13}},
  67.   {6, 2, 1, {13}},
  68.   {2, 2, 0}  /* 20 */
  69. };
  70. int m;
  71.  
  72. /* get i, j */
  73.  if ((type == 1) || (type == 3))
  74.     *i = 18 - tree[*cnd].i;   /* inverted */
  75.  else
  76.     *i = tree[*cnd].i;
  77.  if ((type == 2) || (type == 3))
  78.     *j = 18 - tree[*cnd].j;   /* reflected */
  79.  else
  80.     *j = tree[*cnd].j;
  81.  if (tree[*cnd].ndct)  /* more move */
  82.    {
  83.     random(&rd);
  84.     m = rd % tree[*cnd].ndct;  /* select move */
  85.     *cnd = tree[*cnd].next[m];    /* new    current node */
  86.     return 1;
  87.   }
  88.  else
  89.     return 0;
  90. }  /* end opening */
  91.  
  92.