]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - gomoku/bdinit.c
1 /* $NetBSD: bdinit.c,v 1.4 1997/10/10 13:36:01 lukem Exp $ */
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "from: @(#)bdinit.c 8.2 (Berkeley) 5/3/95";
44 __RCSID("$NetBSD: bdinit.c,v 1.4 1997/10/10 13:36:01 lukem Exp $");
61 /* mark the borders as such */
63 for (i
= BSZ2
; --i
>= 0; sp
++) {
64 sp
->s_occ
= BORDER
; /* top border */
68 /* fill entire board with EMPTY spots */
69 memset(frames
, 0, sizeof(frames
));
71 for (j
= 0; ++j
< BSZ1
; sp
++) { /* for each row */
72 for (i
= 0; ++i
< BSZ1
; sp
++) { /* for each column */
77 /* directions 1, 2, 3 are blocked */
78 sp
->s_flg
|= (BFLAG
<< 1) | (BFLAG
<< 2) |
80 sp
->s_fval
[BLACK
][1].s
= MAXCOMBO
;
81 sp
->s_fval
[BLACK
][2].s
= MAXCOMBO
;
82 sp
->s_fval
[BLACK
][3].s
= MAXCOMBO
;
83 sp
->s_fval
[WHITE
][1].s
= MAXCOMBO
;
84 sp
->s_fval
[WHITE
][2].s
= MAXCOMBO
;
85 sp
->s_fval
[WHITE
][3].s
= MAXCOMBO
;
87 /* five spaces, blocked on one side */
88 sp
->s_fval
[BLACK
][1].s
= 0x500;
89 sp
->s_fval
[BLACK
][2].s
= 0x500;
90 sp
->s_fval
[BLACK
][3].s
= 0x500;
91 sp
->s_fval
[WHITE
][1].s
= 0x500;
92 sp
->s_fval
[WHITE
][2].s
= 0x500;
93 sp
->s_fval
[WHITE
][3].s
= 0x500;
95 /* six spaces, not blocked */
96 sp
->s_fval
[BLACK
][1].s
= 0x401;
97 sp
->s_fval
[BLACK
][2].s
= 0x401;
98 sp
->s_fval
[BLACK
][3].s
= 0x401;
99 sp
->s_fval
[WHITE
][1].s
= 0x401;
100 sp
->s_fval
[WHITE
][2].s
= 0x401;
101 sp
->s_fval
[WHITE
][3].s
= 0x401;
104 /* directions 0, 1 are blocked */
105 sp
->s_flg
|= BFLAG
| (BFLAG
<< 1);
106 sp
->s_fval
[BLACK
][0].s
= MAXCOMBO
;
107 sp
->s_fval
[BLACK
][1].s
= MAXCOMBO
;
108 sp
->s_fval
[WHITE
][0].s
= MAXCOMBO
;
109 sp
->s_fval
[WHITE
][1].s
= MAXCOMBO
;
110 } else if (i
== (BSZ
- 4)) {
111 sp
->s_fval
[BLACK
][0].s
= 0x500;
112 sp
->s_fval
[WHITE
][0].s
= 0x500;
113 /* if direction 1 is not blocked */
114 if (!(sp
->s_flg
& (BFLAG
<< 1))) {
115 sp
->s_fval
[BLACK
][1].s
= 0x500;
116 sp
->s_fval
[WHITE
][1].s
= 0x500;
119 sp
->s_fval
[BLACK
][0].s
= 0x401;
120 sp
->s_fval
[WHITE
][0].s
= 0x401;
122 /* direction 3 is blocked */
123 sp
->s_flg
|= (BFLAG
<< 3);
124 sp
->s_fval
[BLACK
][3].s
= MAXCOMBO
;
125 sp
->s_fval
[WHITE
][3].s
= MAXCOMBO
;
127 !(sp
->s_flg
& (BFLAG
<< 3))) {
128 sp
->s_fval
[BLACK
][3].s
= 0x500;
129 sp
->s_fval
[WHITE
][3].s
= 0x500;
133 * Allocate a frame structure for non blocked frames.
135 for (r
= 4; --r
>= 0; ) {
136 if (sp
->s_flg
& (BFLAG
<< r
))
138 cbp
->c_combo
.s
= sp
->s_fval
[BLACK
][r
].s
;
139 cbp
->c_vertex
= sp
- board
;
142 sp
->s_frame
[r
] = cbp
;
146 sp
->s_occ
= BORDER
; /* left & right border */
147 sp
->s_flg
= BFLAGALL
;
150 /* mark the borders as such */
151 for (i
= BSZ1
; --i
>= 0; sp
++) {
152 sp
->s_occ
= BORDER
; /* bottom border */
153 sp
->s_flg
= BFLAGALL
;
156 sortframes
[BLACK
] = (struct combostr
*)0;
157 sortframes
[WHITE
] = (struct combostr
*)0;
162 * Initialize the overlap array.
163 * Each entry in the array is a bit mask with eight bits corresponding
164 * to whether frame B overlaps frame A (as indexed by overlap[A * FAREA + B]).
165 * The eight bits coorespond to whether A and B are open ended (length 6) or
167 * 0 A closed and B closed
168 * 1 A closed and B open
169 * 2 A open and B closed
170 * 3 A open and B open
171 * 4 A closed and B closed and overlaps in more than one spot
172 * 5 A closed and B open and overlaps in more than one spot
173 * 6 A open and B closed and overlaps in more than one spot
174 * 7 A open and B open and overlaps in more than one spot
175 * As pieces are played, it can make frames not overlap if there are no
176 * common open spaces shared between the two frames.
181 struct spotstr
*sp1
, *sp2
;
182 struct combostr
*cbp
;
183 int i
, f
, r
, n
, d1
, d2
;
184 int mask
, bmask
, vertex
, s
;
188 memset(overlap
, 0, sizeof(overlap
));
189 memset(intersect
, 0, sizeof(intersect
));
190 str
= &overlap
[FAREA
* FAREA
];
191 ip
= &intersect
[FAREA
* FAREA
];
192 for (cbp
= frames
+ FAREA
; --cbp
>= frames
; ) { /* each frame */
195 sp1
= &board
[vertex
= cbp
->c_vertex
];
196 d1
= dd
[r
= cbp
->c_dir
];
198 * s = 5 if closed, 6 if open.
199 * At this point black & white are the same.
201 s
= 5 + sp1
->s_fval
[BLACK
][r
].c
.b
;
202 /* for each spot in frame A */
203 for (i
= 0; i
< s
; i
++, sp1
+= d1
, vertex
+= d1
) {
204 /* the sixth spot in frame A only overlaps if it is open */
205 mask
= (i
== 5) ? 0xC : 0xF;
206 /* for each direction */
207 for (r
= 4; --r
>= 0; ) {
211 /* for each frame that intersects at spot sp1 */
212 for (f
= 0; f
< 6; f
++, sp2
-= d2
) {
213 if (sp2
->s_occ
== BORDER
)
215 if (sp2
->s_flg
& bmask
)
217 n
= sp2
->s_frame
[r
] - frames
;
219 str
[n
] |= (f
== 5) ? mask
& 0xA : mask
;
220 if (r
== cbp
->c_dir
) {
221 /* compute the multiple spot overlap values */
223 case 0: /* sp1 is the first spot in A */
229 case 1: /* sp1 is the second spot in A */
235 case 4: /* sp1 is the penultimate spot in A */
241 case 5: /* sp1 is the last spot in A */