2022-05-28 02:10:54 +03:00
|
|
|
/* $NetBSD: gomoku.h,v 1.41 2022/05/27 23:10:54 rillig Exp $ */
|
1997-01-03 04:35:23 +03:00
|
|
|
|
1996-12-28 21:44:55 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1996-12-28 21:44:55 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)gomoku.h 8.2 (Berkeley) 5/3/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2004-01-27 23:25:48 +03:00
|
|
|
#include <sys/endian.h>
|
2022-05-16 23:57:01 +03:00
|
|
|
#include <stdbool.h>
|
1997-10-10 17:36:01 +04:00
|
|
|
#include <stdio.h>
|
1996-12-28 21:44:55 +03:00
|
|
|
|
2022-05-21 18:21:40 +03:00
|
|
|
/*
|
|
|
|
* The board consists of 19x19 spots, the coordinates are 1-based. The board
|
|
|
|
* is surrounded by border spots.
|
|
|
|
*/
|
|
|
|
|
1996-12-28 21:44:55 +03:00
|
|
|
#define BSZ 19
|
2022-05-16 01:56:20 +03:00
|
|
|
#define BAREA ((1 + BSZ + 1) * (BSZ + 1) + 1)
|
1996-12-28 21:44:55 +03:00
|
|
|
|
2022-05-21 18:21:40 +03:00
|
|
|
/*
|
|
|
|
* A 'frame' is a group of five or six contiguous board locations. An
|
|
|
|
* open-ended frame is one with spaces on both ends; otherwise, it is closed.
|
|
|
|
*/
|
2022-05-19 21:58:59 +03:00
|
|
|
#define FAREA (2 * BSZ * (BSZ - 4) + 2 * (BSZ - 4) * (BSZ - 4))
|
1996-12-28 21:44:55 +03:00
|
|
|
|
|
|
|
/* values for s_occ */
|
|
|
|
#define BLACK 0
|
|
|
|
#define WHITE 1
|
|
|
|
#define EMPTY 2
|
|
|
|
#define BORDER 3
|
|
|
|
|
2022-05-21 17:55:26 +03:00
|
|
|
/* return values for makemove, readinput */
|
1996-12-28 21:44:55 +03:00
|
|
|
#define MOVEOK 0
|
|
|
|
#define RESIGN 1
|
|
|
|
#define ILLEGAL 2
|
|
|
|
#define WIN 3
|
|
|
|
#define TIE 4
|
|
|
|
#define SAVE 5
|
2022-05-16 01:56:20 +03:00
|
|
|
#define PT(x, y) ((x) + (BSZ + 1) * (y))
|
1996-12-28 21:44:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A 'combo' is a group of intersecting frames and consists of two numbers:
|
2022-05-21 19:39:14 +03:00
|
|
|
* 'F' is the number of moves to make the combo non-blockable.
|
|
|
|
* 'W' is the minimum number of moves needed to win once it can't be blocked.
|
1996-12-28 21:44:55 +03:00
|
|
|
*
|
2022-05-21 18:21:40 +03:00
|
|
|
* A 'force' is a combo that is one move away from being non-blockable.
|
1996-12-28 21:44:55 +03:00
|
|
|
*
|
|
|
|
* Each time a frame is added to the combo, the number of moves to complete
|
|
|
|
* the force is the number of moves needed to 'fill' the frame plus one at
|
|
|
|
* the intersection point. The number of moves to win is the number of moves
|
|
|
|
* to complete the best frame minus the last move to complete the force.
|
|
|
|
* Note that it doesn't make sense to combine a <1,x> with anything since
|
|
|
|
* it is already a force. Also, the frames have to be independent so a
|
|
|
|
* single move doesn't affect more than one frame making up the combo.
|
|
|
|
*
|
2022-05-21 19:39:14 +03:00
|
|
|
* Rules for comparing which of two combos (<F1,W1> <F2,W2>) is better:
|
1996-12-28 21:44:55 +03:00
|
|
|
* Both the same color:
|
2022-05-21 19:39:14 +03:00
|
|
|
* <F',W'> = (F1 < F2 || F1 == F2 && W1 <= W2) ? <F1,W1> : <F2,W2>
|
1996-12-28 21:44:55 +03:00
|
|
|
* We want to complete the force first, then the combo with the
|
|
|
|
* fewest moves to win.
|
2022-05-21 19:39:14 +03:00
|
|
|
* Different colors, <F1,W1> is the combo for the player with the next move:
|
|
|
|
* <F',W'> = F2 <= 1 && (F1 > 1 || F2 + W2 < F1 + W1) ? <F2,W2> : <F1,W1>
|
1996-12-28 21:44:55 +03:00
|
|
|
* We want to block only if we have to (i.e., if they are one move away
|
2022-05-20 22:30:17 +03:00
|
|
|
* from completing a force, and we don't have a force that we can
|
1996-12-28 21:44:55 +03:00
|
|
|
* complete which takes fewer or the same number of moves to win).
|
|
|
|
*/
|
|
|
|
|
2022-05-21 18:21:40 +03:00
|
|
|
/*
|
|
|
|
* Single frame combo values:
|
2022-05-21 19:39:14 +03:00
|
|
|
* <F,W> board values
|
2022-05-21 18:21:40 +03:00
|
|
|
* 5,0 . . . . . O
|
|
|
|
* 4,1 . . . . . .
|
|
|
|
* 4,0 . . . . X O
|
|
|
|
* 3,1 . . . . X .
|
|
|
|
* 3,0 . . . X X O
|
|
|
|
* 2,1 . . . X X .
|
|
|
|
* 2,0 . . X X X O
|
|
|
|
* 1,1 . . X X X .
|
|
|
|
* 1,0 . X X X X O
|
|
|
|
* 0,1 . X X X X .
|
|
|
|
* 0,0 X X X X X O
|
|
|
|
*
|
2022-05-21 19:39:14 +03:00
|
|
|
* The rule for combining two combos (<F1,W1> <F2,W2>) with V valid
|
2022-05-21 18:21:40 +03:00
|
|
|
* intersection points is:
|
2022-05-21 19:39:14 +03:00
|
|
|
* F' = F1 + F2 - 2 - V
|
|
|
|
* W' = MIN(F1 + W1 - 1, F2 + W2 - 1)
|
2022-05-21 18:21:40 +03:00
|
|
|
*/
|
2022-05-16 01:00:11 +03:00
|
|
|
union comboval {
|
1996-12-28 21:44:55 +03:00
|
|
|
struct {
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2022-05-21 19:39:14 +03:00
|
|
|
u_char a;
|
|
|
|
u_char b;
|
1996-12-28 21:44:55 +03:00
|
|
|
#endif
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
2022-05-21 19:39:14 +03:00
|
|
|
u_char b;
|
|
|
|
u_char a;
|
1996-12-28 21:44:55 +03:00
|
|
|
#endif
|
|
|
|
} c;
|
|
|
|
u_short s;
|
|
|
|
};
|
2022-05-21 19:39:14 +03:00
|
|
|
#define cv_force c.a /* # moves to complete force */
|
|
|
|
#define cv_win c.b /* # moves to win */
|
1996-12-28 21:44:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure is used to record information about single frames (F) and
|
|
|
|
* combinations of two more frames (C).
|
|
|
|
* For combinations of two or more frames, there is an additional
|
|
|
|
* array of pointers to the frames of the combination which is sorted
|
|
|
|
* by the index into the frames[] array. This is used to prevent duplication
|
|
|
|
* since frame A combined with B is the same as B with A.
|
|
|
|
* struct combostr *c_sort[size c_nframes];
|
|
|
|
* The leaves of the tree (frames) are numbered 0 (bottom, leftmost)
|
|
|
|
* to c_nframes - 1 (top, right). This is stored in c_frameindex and
|
|
|
|
* c_dir if C_LOOP is set.
|
|
|
|
*/
|
|
|
|
struct combostr {
|
|
|
|
struct combostr *c_next; /* list of combos at the same level */
|
|
|
|
struct combostr *c_prev; /* list of combos at the same level */
|
2022-05-22 13:45:02 +03:00
|
|
|
struct combostr *c_link[2]; /* F: NULL,
|
|
|
|
* C: previous level */
|
|
|
|
union comboval c_linkv[2]; /* C: combo value for link[0, 1] */
|
|
|
|
union comboval c_combo; /* F: initial combo value (read-only),
|
|
|
|
* C: combo value for this level */
|
|
|
|
u_short c_vertex; /* F: frame head,
|
|
|
|
* C: intersection */
|
|
|
|
u_char c_nframes; /* F: 1,
|
|
|
|
* C: number of frames in the combo */
|
|
|
|
u_char c_dir; /* F: frame direction,
|
|
|
|
* C: loop frame */
|
|
|
|
u_char c_flags; /* C: combo flags */
|
|
|
|
u_char c_frameindex; /* C: intersection frame index */
|
1996-12-28 21:44:55 +03:00
|
|
|
u_char c_framecnt[2]; /* number of frames left to attach */
|
2022-05-22 13:45:02 +03:00
|
|
|
u_char c_emask[2]; /* C: bit mask of completion spots for
|
1996-12-28 21:44:55 +03:00
|
|
|
* link[0] and link[1] */
|
2022-05-22 13:45:02 +03:00
|
|
|
u_char c_voff[2]; /* C: vertex offset within frame */
|
1996-12-28 21:44:55 +03:00
|
|
|
};
|
|
|
|
|
2009-06-04 09:43:29 +04:00
|
|
|
/* flag values for c_flags */
|
2022-05-20 22:30:17 +03:00
|
|
|
#define C_OPEN_0 0x01 /* link[0] is an open-ended frame */
|
|
|
|
#define C_OPEN_1 0x02 /* link[1] is an open-ended frame */
|
1996-12-28 21:44:55 +03:00
|
|
|
#define C_LOOP 0x04 /* link[1] intersects previous frame */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This structure is used for recording the completion points of
|
|
|
|
* multi frame combos.
|
|
|
|
*/
|
|
|
|
struct elist {
|
|
|
|
struct elist *e_next; /* list of completion points */
|
|
|
|
struct combostr *e_combo; /* the whole combo */
|
|
|
|
u_char e_off; /* offset in frame of this empty spot */
|
|
|
|
u_char e_frameindex; /* intersection frame index */
|
|
|
|
u_char e_framecnt; /* number of frames left to attach */
|
|
|
|
u_char e_emask; /* real value of the frame's emask */
|
|
|
|
union comboval e_fval; /* frame combo value */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
struct spotstr {
|
|
|
|
short s_occ; /* color of occupant */
|
|
|
|
short s_wval; /* weighted value */
|
2009-06-04 09:43:29 +04:00
|
|
|
int s_flags; /* flags for graph walks */
|
1996-12-28 21:44:55 +03:00
|
|
|
struct combostr *s_frame[4]; /* level 1 combo for frame[dir] */
|
|
|
|
union comboval s_fval[2][4]; /* combo value for [color][frame] */
|
|
|
|
union comboval s_combo[2]; /* minimum combo value for BLK & WHT */
|
|
|
|
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 */
|
|
|
|
struct elist *s_nempty; /* level n+1 combo completion spots */
|
|
|
|
int dummy[2]; /* XXX */
|
|
|
|
};
|
|
|
|
|
2009-06-04 09:43:29 +04:00
|
|
|
/* flag values for s_flags */
|
1996-12-28 21:44:55 +03:00
|
|
|
#define CFLAG 0x000001 /* frame is part of a combo */
|
|
|
|
#define CFLAGALL 0x00000F /* all frame directions marked */
|
|
|
|
#define IFLAG 0x000010 /* legal intersection point */
|
|
|
|
#define IFLAGALL 0x0000F0 /* any intersection points? */
|
|
|
|
#define FFLAG 0x000100 /* frame is part of a <1,x> combo */
|
|
|
|
#define FFLAGALL 0x000F00 /* all force frames */
|
|
|
|
#define MFLAG 0x001000 /* frame has already been seen */
|
|
|
|
#define MFLAGALL 0x00F000 /* all frames seen */
|
|
|
|
#define BFLAG 0x010000 /* frame intersects border or dead */
|
|
|
|
#define BFLAGALL 0x0F0000 /* all frames dead */
|
|
|
|
|
2022-05-21 20:19:10 +03:00
|
|
|
extern const char letters[];
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
extern const char pdir[];
|
1996-12-28 21:44:55 +03:00
|
|
|
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
extern const int dd[4];
|
1996-12-28 21:44:55 +03:00
|
|
|
extern struct spotstr board[BAREA]; /* info for board */
|
|
|
|
extern struct combostr frames[FAREA]; /* storage for single frames */
|
|
|
|
extern struct combostr *sortframes[2]; /* sorted, non-empty frames */
|
|
|
|
extern u_char overlap[FAREA * FAREA]; /* frame [a][b] overlap */
|
|
|
|
extern short intersect[FAREA * FAREA]; /* frame [a][b] intersection */
|
2022-05-27 22:59:56 +03:00
|
|
|
extern int movelog[BSZ * BSZ];
|
|
|
|
extern unsigned int nmoves;
|
1996-12-28 21:44:55 +03:00
|
|
|
extern int debug;
|
|
|
|
|
2022-05-17 00:48:45 +03:00
|
|
|
extern bool interactive;
|
2014-03-22 22:58:57 +04:00
|
|
|
extern const char *plyr[];
|
|
|
|
|
2004-01-27 23:30:28 +03:00
|
|
|
void bdinit(struct spotstr *);
|
2010-03-29 07:51:55 +04:00
|
|
|
int get_coord(void);
|
2022-05-17 00:48:45 +03:00
|
|
|
int get_key(const char *);
|
2022-05-21 15:29:34 +03:00
|
|
|
bool get_line(char *, int, void (*)(const char *));
|
2004-01-27 23:30:28 +03:00
|
|
|
void ask(const char *);
|
|
|
|
void dislog(const char *);
|
|
|
|
void bdump(FILE *);
|
|
|
|
void bdisp(void);
|
|
|
|
void bdisp_init(void);
|
|
|
|
void cursfini(void);
|
|
|
|
void cursinit(void);
|
2022-05-21 12:25:51 +03:00
|
|
|
void bdwho(void);
|
2009-06-04 10:27:47 +04:00
|
|
|
void panic(const char *, ...) __printflike(1, 2) __dead;
|
|
|
|
void debuglog(const char *, ...) __printflike(1, 2);
|
2004-01-27 23:30:28 +03:00
|
|
|
void whatsup(int);
|
|
|
|
const char *stoc(int);
|
|
|
|
int ctos(const char *);
|
|
|
|
int makemove(int, int);
|
|
|
|
void clearcombo(struct combostr *, int);
|
|
|
|
void markcombo(struct combostr *);
|
|
|
|
int pickmove(int);
|
2022-05-17 00:02:18 +03:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void printcombo(struct combostr *, char *, size_t);
|
|
|
|
#endif
|