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                     NeXT version by John Neil
9 */
10 /*
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation - version 1.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License in file COPYING for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24 Please report any bug/fix, modification, suggestion to
25 
26 mail address:   Man L. Li
27                 Dept. of Computer Science
28                 University of Houston
29                 4800 Calhoun Road
30                 Houston, TX 77004
31 
32 e-mail address: manli@cs.uh.edu         (Internet)
33                 coscgbn@uhvax1.bitnet   (BITNET)
34                 70070,404               (CompuServe)
35 
36 For the NeXT version, please report any bug/fix, modification, suggestion to
37 
38 mail address:   John Neil
39                 Mathematics Department
40                 Portland State University
41                 PO Box 751
42                 Portland, OR  97207
43 
44 e-mail address: neil@math.mth.pdx.edu  (Internet)
45                 neil@psuorvm.bitnet    (BITNET)
46 */
47 
48 #include "comment.header"
49 
50 /* $Id: opening.c,v 1.1 2003/01/12 04:01:52 gcasa Exp $ */
51 
52 /*
53  * $Log: opening.c,v $
54  * Revision 1.1  2003/01/12 04:01:52  gcasa
55  * Committing the entire GNU Go and NeXT Go application to the repository.
56  * See COPYING file for GNU License.
57  *
58  * Revision 1.3  1997/07/06 19:35:03  ergo
59  * actual version
60  *
61  * Revision 1.2  1997/05/04 18:57:09  ergo
62  * added time control for moves
63  *
64  */
65 
66 extern int rd, MAXX, MAXY;
67 extern void Random(int*);
68 
opening(int * i,int * j,int * cnd,int type)69 int opening(int *i, int *j, int *cnd, int type)
70      /* get move for opening from game tree */
71 {
72   struct tnode {
73     int i, j, ndct, next[8];
74   };
75 
76   static struct tnode tree[] = {
77     {-1, -1, 8, { 1, 2, 3, 4, 5, 6, 7, 20}},	/* 0 */
78     {2, 3, 2, { 8, 9}},
79     {2, 4, 1, {10}},
80     {3, 2, 2, {11, 12}},
81     {3, 3, 6, {14, 15, 16, 17, 18, 19}},
82     {3, 4, 1, {10}},  /* 5 */
83     {4, 2, 1, {13}},
84     {4, 3, 1, {13}},
85     {4, 2, 0},
86     {4, 3, 0},
87     {3, 2, 0},  /* 10 */
88     {2, 4, 0},
89     {3, 4, 0},
90     {2, 3, 0},
91     {2, 5, 1, {10}},
92     {2, 6, 1, {10}},  /* 15 */
93     {3, 5, 1, {10}},
94     {5, 2, 1, {13}},
95     {5, 3, 1, {13}},
96     {6, 2, 1, {13}},
97     {2, 2, 0}  /* 20 */
98   };
99   int m;
100 
101   /* get i, j */
102   if ((type == 1) || (type == 3))
103     *i = (18 - tree[*cnd].i)*MAXX/19;   /* inverted */
104   else
105     *i = tree[*cnd].i*MAXX/19;
106   if ((type == 2) || (type == 3))
107     *j = (18 - tree[*cnd].j)*MAXY/19;   /* reflected */
108   else
109     *j = tree[*cnd].j*MAXY/19;
110   if (tree[*cnd].ndct)  /* more move */
111     {
112       Random(&rd);
113       m = rd % tree[*cnd].ndct;  /* select move */
114       *cnd = tree[*cnd].next[m];	/* new	current node */
115       return 1;
116     }
117   else
118     return 0;
119 }  /* end opening */
120 
121