Module Name: src Committed By: rillig Date: Sun May 29 13:49:10 UTC 2022
Modified Files: src/games/gomoku: bdinit.c gomoku.h makemove.c pickmove.c Log Message: gomoku: add data type for one of the 4 directions of a frame No functional change. To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/games/gomoku/bdinit.c cvs rdiff -u -r1.49 -r1.50 src/games/gomoku/gomoku.h cvs rdiff -u -r1.37 -r1.38 src/games/gomoku/makemove.c cvs rdiff -u -r1.56 -r1.57 src/games/gomoku/pickmove.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/games/gomoku/bdinit.c diff -u src/games/gomoku/bdinit.c:1.31 src/games/gomoku/bdinit.c:1.32 --- src/games/gomoku/bdinit.c:1.31 Sun May 29 11:36:12 2022 +++ src/games/gomoku/bdinit.c Sun May 29 13:49:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $ */ +/* $NetBSD: bdinit.c,v 1.32 2022/05/29 13:49:10 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* from: @(#)bdinit.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: bdinit.c,v 1.31 2022/05/29 11:36:12 rillig Exp $"); +__RCSID("$NetBSD: bdinit.c,v 1.32 2022/05/29 13:49:10 rillig Exp $"); #include <string.h> #include "gomoku.h" @@ -109,7 +109,7 @@ static void init_spot_frame(struct spotstr *sp, frame_index *fip) { - for (int r = 4; --r >= 0; ) { + for (direction r = 4; r-- > 0; ) { if ((sp->s_flags & (BFLAG << r)) != 0) continue; Index: src/games/gomoku/gomoku.h diff -u src/games/gomoku/gomoku.h:1.49 src/games/gomoku/gomoku.h:1.50 --- src/games/gomoku/gomoku.h:1.49 Sun May 29 10:37:21 2022 +++ src/games/gomoku/gomoku.h Sun May 29 13:49:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: gomoku.h,v 1.49 2022/05/29 10:37:21 rillig Exp $ */ +/* $NetBSD: gomoku.h,v 1.50 2022/05/29 13:49:10 rillig Exp $ */ /* * Copyright (c) 1994 @@ -190,18 +190,21 @@ struct elist { /* The index of a frame in the global 'frames'. */ typedef unsigned short frame_index; +/* 0 = right, 1 = down right, 2 = down, 3 = down left. */ +typedef unsigned char direction; + /* * One spot structure for each location on the board. - * A frame consists of the combination for the current spot plus the five spots - * 0: right, 1: right & down, 2: down, 3: down & left. + * A frame consists of the combination for the current spot plus the next + * five spots in the direction. */ struct spotstr { short s_occ; /* color of occupant */ short s_wval; /* weighted value */ int s_flags; /* flags for graph walks */ frame_index s_frame[4]; /* level 1 combo for [dir] */ - union comboval s_fval[2][4]; /* combo value for [color][frame] */ - union comboval s_combo[2]; /* minimum combo value for BLK & WHT */ + union comboval s_fval[2][4]; /* combo value for [color][dir] */ + union comboval s_combo[2]; /* minimum combo value for [color] */ u_char s_level[2]; /* number of frames in the min combo */ u_char s_nforce[2]; /* number of <1,x> combos */ struct elist *s_empty; /* level n combo completion spots */ @@ -221,10 +224,10 @@ struct spotstr { #define BFLAGALL 0x0F0000 /* all frames dead */ struct game { - spot_index moves[BSZ * BSZ]; /* log of all played moves */ - unsigned int nmoves; /* number of played moves */ - spot_index winning_spot; - int winning_dir; + unsigned int nmoves; /* number of played moves */ + spot_index moves[BSZ * BSZ]; /* log of all played moves */ + spot_index winning_spot; + direction winning_dir; }; extern const char letters[]; Index: src/games/gomoku/makemove.c diff -u src/games/gomoku/makemove.c:1.37 src/games/gomoku/makemove.c:1.38 --- src/games/gomoku/makemove.c:1.37 Sun May 29 11:36:12 2022 +++ src/games/gomoku/makemove.c Sun May 29 13:49:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $ */ +/* $NetBSD: makemove.c,v 1.38 2022/05/29 13:49:10 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* @(#)makemove.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: makemove.c,v 1.37 2022/05/29 11:36:12 rillig Exp $"); +__RCSID("$NetBSD: makemove.c,v 1.38 2022/05/29 13:49:10 rillig Exp $"); #include "gomoku.h" @@ -77,7 +77,7 @@ sortframes_remove(struct combostr *cbp) } static int -old_weight_value(const struct spotstr *sp, int r) +old_weight_value(const struct spotstr *sp, direction r) { union comboval cb; int val = 0; @@ -115,7 +115,7 @@ makemove(int us, spot_index mv) /* compute new frame values */ sp->s_wval = 0; - for (int r = 4; --r >= 0; ) { /* for each direction */ + for (direction r = 4; r-- > 0; ) { int d = dd[r]; struct spotstr *fsp = &board[mv]; @@ -161,7 +161,8 @@ makemove(int us, spot_index mv) } /* compute new value & combo number for this frame & color */ - fsp->s_fval[us != BLACK ? BLACK : WHITE][r].s = 0x600; + int them = us != BLACK ? BLACK : WHITE; + fsp->s_fval[them][r].s = 0x600; union comboval *cp = &fsp->s_fval[us][r]; /* both ends open? */ if (space && sp->s_occ == EMPTY) { @@ -233,7 +234,8 @@ makemove(int us, spot_index mv) static void update_overlap_same_direction(spot_index s1, spot_index s2, - frame_index a, int d, int i_minus_f, int r) + frame_index a, int d, int i_minus_f, + direction r) { /* * count the number of empty spots to see if there is @@ -275,13 +277,13 @@ update_overlap_same_direction(spot_index } /* - * The last move was at 'osp', which is part of frame 'a'. There are 6 frames - * with direction 'rb' that cross frame 'a' in 'osp'. Since the spot 'osp' + * The last move was at 'os', which is part of frame 'a'. There are 6 frames + * with direction 'rb' that cross frame 'a' in 'os'. Since the spot 'os' * cannot be used as a double threat anymore, mark each of these crossing * frames as non-overlapping with frame 'a'. */ static void -update_overlap_different_direction(spot_index os, frame_index a, int rb) +update_overlap_different_direction(spot_index os, frame_index a, direction rb) { int db = dd[rb]; @@ -299,17 +301,17 @@ update_overlap_different_direction(spot_ } /* - * fix up the overlap array according to the changed 'osp'. + * fix up the overlap array according to the changed 'os'. */ static void update_overlap(spot_index os) { - for (int r = 4; --r >= 0; ) { /* for each direction */ + for (direction r = 4; r-- > 0; ) { int d = dd[r]; spot_index s1 = os; - /* for each frame 'a' that contains the spot 'osp' */ + /* for each frame 'a' that contains the spot 'os' */ for (int f = 0; f < 6; f++, s1 -= d) { if (board[s1].s_occ == BORDER) break; @@ -321,7 +323,7 @@ update_overlap(spot_index os) * to indicate whether they still overlap or not. * Since F1 overlap F2 == F2 overlap F1, we only need to * do the rows 0 <= r1 <= r. The r1 == r case is special - * since the two frames can overlap at more than one point. + * since the two frames can overlap in more than one spot. */ frame_index a = board[s1].s_frame[r]; @@ -335,8 +337,8 @@ update_overlap(spot_index os) update_overlap_same_direction(s1, s2, a, d, i - f, r); } - /* the other directions can only intersect at spot osp */ - for (int rb = 0; rb < r; rb++) + /* the other directions can only intersect at spot 'os' */ + for (direction rb = 0; rb < r; rb++) update_overlap_different_direction(os, a, rb); } } Index: src/games/gomoku/pickmove.c diff -u src/games/gomoku/pickmove.c:1.56 src/games/gomoku/pickmove.c:1.57 --- src/games/gomoku/pickmove.c:1.56 Sun May 29 12:44:17 2022 +++ src/games/gomoku/pickmove.c Sun May 29 13:49:10 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: pickmove.c,v 1.56 2022/05/29 12:44:17 rillig Exp $ */ +/* $NetBSD: pickmove.c,v 1.57 2022/05/29 13:49:10 rillig Exp $ */ /* * Copyright (c) 1994 @@ -34,7 +34,7 @@ #include <sys/cdefs.h> /* @(#)pickmove.c 8.2 (Berkeley) 5/3/95 */ -__RCSID("$NetBSD: pickmove.c,v 1.56 2022/05/29 12:44:17 rillig Exp $"); +__RCSID("$NetBSD: pickmove.c,v 1.57 2022/05/29 13:49:10 rillig Exp $"); #include <stdlib.h> #include <string.h> @@ -227,7 +227,7 @@ static int curcolor; /* implicit paramet static unsigned int curlevel; /* implicit parameter to makecombo() */ static bool -four_in_a_row(int color, spot_index s, int r) +four_in_a_row(int color, spot_index s, direction r) { struct spotstr *sp = &board[s]; @@ -437,7 +437,8 @@ makecombo2(struct combostr *ocbp, struct baseB = ocb.cv_force + ocb.cv_win - 1; fcnt = ocb.cv_force - 2; emask = fcnt != 0 ? ((ocb.cv_win != 0 ? 0x1E : 0x1F) & ~(1 << off)) : 0; - for (int r = 4; --r >= 0; ) { /* for each direction */ + + for (direction r = 4; r-- > 0; ) { /* don't include frames that overlap in the same direction */ if (r == ocbp->c_dir) continue;