| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pickmove.c,v 1.25 2022/05/15 22:08:05 rillig Exp $ */ | | 1 | /* $NetBSD: pickmove.c,v 1.26 2022/05/15 22:18:36 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. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
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 | #ifndef lint | | 36 | #ifndef lint |
37 | #if 0 | | 37 | #if 0 |
38 | static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95"; | | 38 | static char sccsid[] = "@(#)pickmove.c 8.2 (Berkeley) 5/3/95"; |
39 | #else | | 39 | #else |
40 | __RCSID("$NetBSD: pickmove.c,v 1.25 2022/05/15 22:08:05 rillig Exp $"); | | 40 | __RCSID("$NetBSD: pickmove.c,v 1.26 2022/05/15 22:18:36 rillig Exp $"); |
41 | #endif | | 41 | #endif |
42 | #endif /* not lint */ | | 42 | #endif /* not lint */ |
43 | | | 43 | |
44 | #include <stdlib.h> | | 44 | #include <stdlib.h> |
45 | #include <string.h> | | 45 | #include <string.h> |
46 | #include <curses.h> | | 46 | #include <curses.h> |
47 | #include <limits.h> | | 47 | #include <limits.h> |
48 | | | 48 | |
49 | #include "gomoku.h" | | 49 | #include "gomoku.h" |
50 | | | 50 | |
51 | #define BITS_PER_INT (sizeof(int) * CHAR_BIT) | | 51 | #define BITS_PER_INT (sizeof(int) * CHAR_BIT) |
52 | #define MAPSZ (BAREA / BITS_PER_INT) | | 52 | #define MAPSZ (BAREA / BITS_PER_INT) |
53 | | | 53 | |
| @@ -78,51 +78,51 @@ static int checkframes(struct combostr * | | | @@ -78,51 +78,51 @@ static int checkframes(struct combostr * |
78 | static int sortcombo(struct combostr **, struct combostr **, struct combostr *); | | 78 | static int sortcombo(struct combostr **, struct combostr **, struct combostr *); |
79 | static void printcombo(struct combostr *, char *, size_t); | | 79 | static void printcombo(struct combostr *, char *, size_t); |
80 | | | 80 | |
81 | int | | 81 | int |
82 | pickmove(int us) | | 82 | pickmove(int us) |
83 | { | | 83 | { |
84 | struct spotstr *sp, *sp1, *sp2; | | 84 | struct spotstr *sp, *sp1, *sp2; |
85 | union comboval *Ocp, *Tcp; | | 85 | union comboval *Ocp, *Tcp; |
86 | unsigned pos; | | 86 | unsigned pos; |
87 | int m; | | 87 | int m; |
88 | | | 88 | |
89 | /* first move is easy */ | | 89 | /* first move is easy */ |
90 | if (movenum == 1) | | 90 | if (movenum == 1) |
91 | return PT(K, 10); | | 91 | return PT((BSZ + 1) / 2, (BSZ + 1) / 2); |
92 | | | 92 | |
93 | /* initialize all the board values */ | | 93 | /* initialize all the board values */ |
94 | for (pos = PT(T, 20); pos-- > PT(A, 1); ) { | | 94 | for (pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) { |
95 | sp = &board[pos]; | | 95 | sp = &board[pos]; |
96 | sp->s_combo[BLACK].s = MAXCOMBO + 1; | | 96 | sp->s_combo[BLACK].s = MAXCOMBO + 1; |
97 | sp->s_combo[WHITE].s = MAXCOMBO + 1; | | 97 | sp->s_combo[WHITE].s = MAXCOMBO + 1; |
98 | sp->s_level[BLACK] = 255; | | 98 | sp->s_level[BLACK] = 255; |
99 | sp->s_level[WHITE] = 255; | | 99 | sp->s_level[WHITE] = 255; |
100 | sp->s_nforce[BLACK] = 0; | | 100 | sp->s_nforce[BLACK] = 0; |
101 | sp->s_nforce[WHITE] = 0; | | 101 | sp->s_nforce[WHITE] = 0; |
102 | sp->s_flags &= ~(FFLAGALL | MFLAGALL); | | 102 | sp->s_flags &= ~(FFLAGALL | MFLAGALL); |
103 | } | | 103 | } |
104 | nforce = 0; | | 104 | nforce = 0; |
105 | memset(forcemap, 0, sizeof(forcemap)); | | 105 | memset(forcemap, 0, sizeof(forcemap)); |
106 | | | 106 | |
107 | /* compute new values */ | | 107 | /* compute new values */ |
108 | nextcolor = us; | | 108 | nextcolor = us; |
109 | scanframes(BLACK); | | 109 | scanframes(BLACK); |
110 | scanframes(WHITE); | | 110 | scanframes(WHITE); |
111 | | | 111 | |
112 | /* find the spot with the highest value */ | | 112 | /* find the spot with the highest value */ |
113 | pos = PT(T, 19); | | 113 | pos = PT(BSZ, BSZ); |
114 | sp1 = sp2 = &board[pos]; | | 114 | sp1 = sp2 = &board[pos]; |
115 | for ( ; pos-- > PT(A, 1); ) { | | 115 | for ( ; pos-- > PT(1, 1); ) { |
116 | sp = &board[pos]; | | 116 | sp = &board[pos]; |
117 | if (sp->s_occ != EMPTY) | | 117 | if (sp->s_occ != EMPTY) |
118 | continue; | | 118 | continue; |
119 | if (debug && (sp->s_combo[BLACK].c.a == 1 || | | 119 | if (debug && (sp->s_combo[BLACK].c.a == 1 || |
120 | sp->s_combo[WHITE].c.a == 1)) { | | 120 | sp->s_combo[WHITE].c.a == 1)) { |
121 | debuglog("- %s %x/%d %d %x/%d %d %d", | | 121 | debuglog("- %s %x/%d %d %x/%d %d %d", |
122 | stoc(sp - board), | | 122 | stoc(sp - board), |
123 | sp->s_combo[BLACK].s, sp->s_level[BLACK], | | 123 | sp->s_combo[BLACK].s, sp->s_level[BLACK], |
124 | sp->s_nforce[BLACK], | | 124 | sp->s_nforce[BLACK], |
125 | sp->s_combo[WHITE].s, sp->s_level[WHITE], | | 125 | sp->s_combo[WHITE].s, sp->s_level[WHITE], |
126 | sp->s_nforce[WHITE], | | 126 | sp->s_nforce[WHITE], |
127 | sp->s_wval); | | 127 | sp->s_wval); |
128 | } | | 128 | } |
| @@ -342,27 +342,27 @@ scanframes(int color) | | | @@ -342,27 +342,27 @@ scanframes(int color) |
342 | d = 2; | | 342 | d = 2; |
343 | while (d <= ((movenum + 1) >> 1) && combolen > n) { | | 343 | while (d <= ((movenum + 1) >> 1) && combolen > n) { |
344 | if (debug) { | | 344 | if (debug) { |
345 | debuglog("%cL%d %d %d %d", "BW"[color], | | 345 | debuglog("%cL%d %d %d %d", "BW"[color], |
346 | d, combolen - n, combocnt, elistcnt); | | 346 | d, combolen - n, combocnt, elistcnt); |
347 | refresh(); | | 347 | refresh(); |
348 | } | | 348 | } |
349 | n = combolen; | | 349 | n = combolen; |
350 | addframes(d); | | 350 | addframes(d); |
351 | d++; | | 351 | d++; |
352 | } | | 352 | } |
353 | | | 353 | |
354 | /* scan for combos at empty spots */ | | 354 | /* scan for combos at empty spots */ |
355 | for (pos = PT(T, 20); pos-- > PT(A, 1); ) { | | 355 | for (pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) { |
356 | sp = &board[pos]; | | 356 | sp = &board[pos]; |
357 | for (ep = sp->s_empty; ep; ep = nep) { | | 357 | for (ep = sp->s_empty; ep; ep = nep) { |
358 | cbp = ep->e_combo; | | 358 | cbp = ep->e_combo; |
359 | if (cbp->c_combo.s <= sp->s_combo[color].s) { | | 359 | if (cbp->c_combo.s <= sp->s_combo[color].s) { |
360 | if (cbp->c_combo.s != sp->s_combo[color].s) { | | 360 | if (cbp->c_combo.s != sp->s_combo[color].s) { |
361 | sp->s_combo[color].s = cbp->c_combo.s; | | 361 | sp->s_combo[color].s = cbp->c_combo.s; |
362 | sp->s_level[color] = cbp->c_nframes; | | 362 | sp->s_level[color] = cbp->c_nframes; |
363 | } else if (cbp->c_nframes < sp->s_level[color]) | | 363 | } else if (cbp->c_nframes < sp->s_level[color]) |
364 | sp->s_level[color] = cbp->c_nframes; | | 364 | sp->s_level[color] = cbp->c_nframes; |
365 | } | | 365 | } |
366 | nep = ep->e_next; | | 366 | nep = ep->e_next; |
367 | free(ep); | | 367 | free(ep); |
368 | elistcnt--; | | 368 | elistcnt--; |
| @@ -552,27 +552,27 @@ addframes(int level) | | | @@ -552,27 +552,27 @@ addframes(int level) |
552 | { | | 552 | { |
553 | struct combostr *cbp, *ecbp; | | 553 | struct combostr *cbp, *ecbp; |
554 | struct spotstr *sp, *fsp; | | 554 | struct spotstr *sp, *fsp; |
555 | struct elist *ep, *nep; | | 555 | struct elist *ep, *nep; |
556 | int i, r, d; | | 556 | int i, r, d; |
557 | struct combostr **cbpp, *pcbp; | | 557 | struct combostr **cbpp, *pcbp; |
558 | union comboval fcb, cb; | | 558 | union comboval fcb, cb; |
559 | unsigned pos; | | 559 | unsigned pos; |
560 | | | 560 | |
561 | curlevel = level; | | 561 | curlevel = level; |
562 | | | 562 | |
563 | /* scan for combos at empty spots */ | | 563 | /* scan for combos at empty spots */ |
564 | i = curcolor; | | 564 | i = curcolor; |
565 | for (pos = PT(T, 20); pos-- > PT(A, 1); ) { | | 565 | for (pos = PT(BSZ, BSZ + 1); pos-- > PT(1, 1); ) { |
566 | sp = &board[pos]; | | 566 | sp = &board[pos]; |
567 | for (ep = sp->s_empty; ep; ep = nep) { | | 567 | for (ep = sp->s_empty; ep; ep = nep) { |
568 | cbp = ep->e_combo; | | 568 | cbp = ep->e_combo; |
569 | if (cbp->c_combo.s <= sp->s_combo[i].s) { | | 569 | if (cbp->c_combo.s <= sp->s_combo[i].s) { |
570 | if (cbp->c_combo.s != sp->s_combo[i].s) { | | 570 | if (cbp->c_combo.s != sp->s_combo[i].s) { |
571 | sp->s_combo[i].s = cbp->c_combo.s; | | 571 | sp->s_combo[i].s = cbp->c_combo.s; |
572 | sp->s_level[i] = cbp->c_nframes; | | 572 | sp->s_level[i] = cbp->c_nframes; |
573 | } else if (cbp->c_nframes < sp->s_level[i]) | | 573 | } else if (cbp->c_nframes < sp->s_level[i]) |
574 | sp->s_level[i] = cbp->c_nframes; | | 574 | sp->s_level[i] = cbp->c_nframes; |
575 | } | | 575 | } |
576 | nep = ep->e_next; | | 576 | nep = ep->e_next; |
577 | free(ep); | | 577 | free(ep); |
578 | elistcnt--; | | 578 | elistcnt--; |