| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: makemove.c,v 1.25 2022/05/27 23:29:15 rillig Exp $ */ | | 1 | /* $NetBSD: makemove.c,v 1.26 2022/05/28 04:52:23 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1994 | | 4 | * Copyright (c) 1994 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Ralph Campbell. | | 8 | * Ralph Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | /* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */ | | 36 | /* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */ |
37 | __RCSID("$NetBSD: makemove.c,v 1.25 2022/05/27 23:29:15 rillig Exp $"); | | 37 | __RCSID("$NetBSD: makemove.c,v 1.26 2022/05/28 04:52:23 rillig Exp $"); |
38 | | | 38 | |
39 | #include "gomoku.h" | | 39 | #include "gomoku.h" |
40 | | | 40 | |
41 | /* direction deltas */ | | 41 | /* direction deltas */ |
42 | const int dd[4] = { | | 42 | const int dd[4] = { |
43 | 1, /* right */ | | 43 | 1, /* right */ |
44 | -(BSZ + 1) + 1, /* down + right */ | | 44 | -(BSZ + 1) + 1, /* down + right */ |
45 | -(BSZ + 1), /* down */ | | 45 | -(BSZ + 1), /* down */ |
46 | -(BSZ + 1) - 1 /* down + left */ | | 46 | -(BSZ + 1) - 1 /* down + left */ |
47 | }; | | 47 | }; |
48 | | | 48 | |
49 | static const int weight[5] = { 0, 1, 7, 22, 100 }; | | 49 | static const int weight[5] = { 0, 1, 7, 22, 100 }; |
50 | | | 50 | |
| @@ -207,27 +207,26 @@ makemove(int us, int mv) | | | @@ -207,27 +207,26 @@ makemove(int us, int mv) |
207 | if (nmoves == BSZ * BSZ) | | 207 | if (nmoves == BSZ * BSZ) |
208 | return TIE; | | 208 | return TIE; |
209 | | | 209 | |
210 | return MOVEOK; | | 210 | return MOVEOK; |
211 | } | | 211 | } |
212 | | | 212 | |
213 | /* | | 213 | /* |
214 | * fix up the overlap array due to updating spot osp. | | 214 | * fix up the overlap array due to updating spot osp. |
215 | */ | | 215 | */ |
216 | static void | | 216 | static void |
217 | update_overlap(struct spotstr *osp) | | 217 | update_overlap(struct spotstr *osp) |
218 | { | | 218 | { |
219 | | | 219 | |
220 | struct spotstr *esp = NULL; | | | |
221 | for (int r = 4; --r >= 0; ) { /* for each direction */ | | 220 | for (int r = 4; --r >= 0; ) { /* for each direction */ |
222 | int d = dd[r]; | | 221 | int d = dd[r]; |
223 | struct spotstr *sp1 = osp; | | 222 | struct spotstr *sp1 = osp; |
224 | int bmask = BFLAG << r; | | 223 | int bmask = BFLAG << r; |
225 | | | 224 | |
226 | for (int f = 0; f < 6; f++, sp1 -= d) { /* for each frame */ | | 225 | for (int f = 0; f < 6; f++, sp1 -= d) { /* for each frame */ |
227 | if (sp1->s_occ == BORDER) | | 226 | if (sp1->s_occ == BORDER) |
228 | break; | | 227 | break; |
229 | if ((sp1->s_flags & bmask) != 0) | | 228 | if ((sp1->s_flags & bmask) != 0) |
230 | continue; | | 229 | continue; |
231 | /* | | 230 | /* |
232 | * Update all other frames that intersect the current one | | 231 | * Update all other frames that intersect the current one |
233 | * to indicate whether they still overlap or not. | | 232 | * to indicate whether they still overlap or not. |
| @@ -241,32 +240,34 @@ update_overlap(struct spotstr *osp) | | | @@ -241,32 +240,34 @@ update_overlap(struct spotstr *osp) |
241 | | | 240 | |
242 | for (int i = f + 1; i < 6; i++, sp2 -= d) { | | 241 | for (int i = f + 1; i < 6; i++, sp2 -= d) { |
243 | if (sp2->s_occ == BORDER) | | 242 | if (sp2->s_occ == BORDER) |
244 | break; | | 243 | break; |
245 | if ((sp2->s_flags & bmask) != 0) | | 244 | if ((sp2->s_flags & bmask) != 0) |
246 | continue; | | 245 | continue; |
247 | | | 246 | |
248 | /* | | 247 | /* |
249 | * count the number of empty spots to see if there is | | 248 | * count the number of empty spots to see if there is |
250 | * still an overlap. | | 249 | * still an overlap. |
251 | */ | | 250 | */ |
252 | int n = 0; | | 251 | int n = 0; |
253 | struct spotstr *sp = sp1; | | 252 | struct spotstr *sp = sp1; |
| | | 253 | struct spotstr *esp = NULL; |
254 | for (int b = i - f; b < 5; b++, sp += d) { | | 254 | for (int b = i - f; b < 5; b++, sp += d) { |
255 | if (sp->s_occ == EMPTY) { | | 255 | if (sp->s_occ == EMPTY) { |
256 | esp = sp; /* save the intersection point */ | | 256 | esp = sp; /* save the intersection point */ |
257 | n++; | | 257 | n++; |
258 | } | | 258 | } |
259 | } | | 259 | } |
| | | 260 | |
260 | int b = (int)(sp2->s_frame[r] - frames); | | 261 | int b = (int)(sp2->s_frame[r] - frames); |
261 | if (n == 0) { | | 262 | if (n == 0) { |
262 | if (sp->s_occ == EMPTY) { | | 263 | if (sp->s_occ == EMPTY) { |
263 | str[b] &= 0xA; | | 264 | str[b] &= 0xA; |
264 | overlap[b * FAREA + a] &= 0xC; | | 265 | overlap[b * FAREA + a] &= 0xC; |
265 | intersect[a * FAREA + b] = (short)(sp - board); | | 266 | intersect[a * FAREA + b] = (short)(sp - board); |
266 | intersect[b * FAREA + a] = (short)(sp - board); | | 267 | intersect[b * FAREA + a] = (short)(sp - board); |
267 | } else { | | 268 | } else { |
268 | str[b] = 0; | | 269 | str[b] = 0; |
269 | overlap[b * FAREA + a] = 0; | | 270 | overlap[b * FAREA + a] = 0; |
270 | } | | 271 | } |
271 | } else if (n == 1) { | | 272 | } else if (n == 1) { |
272 | if (sp->s_occ == EMPTY) { | | 273 | if (sp->s_occ == EMPTY) { |