[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

constant definitions



>
>I would like to share the first piece code which is the constant list of my
>prototype GO program:
>
>#ifndef GoConstantH
>#define GoConstantH
>// --------------------------------------------------------
>// GO constants
>// --------------------------------------------------------
>// Stone Color as Integer
>// --------------------------------------------------------
>const int BLACK =  1;
>const int EMPTY =  0;
>const int WHITE = -1;

I like to keep all the constants positive since sooner or later I
want to use one as an array index.  I use

#define BLACKSTONE 0
#define WHITESTONE 1
#define EMPTY 2

and can use for example

int opposite_color[3] = { 1, 0, 2 };

Internally everything is scaled so one point on the board is worth 50.
I did this so the worst case score would fit in 16 bits, so 100 is too
big.  Several programs use 64 per point, but I like 50 since I can
divide by 50 in my head when I'm looking at debug output :)

Attached is my header file of defines.  Ignore the reference to a
nondisclosure agreement.

David

/* Copyright 1984-1995 David Fotland.  All rights reserved.
 * This source code is being distributed under a nondisclosure
 * agreement.  Do not distribute it without written permission
 * from David Fotland.  Do not show it to anyone not party to the
 * nondisclosure.  Maintain good security on any computers or
 * disks containing this source code.
 */

#ifndef G2DEF_INCLUDED
#define G2DEF_INCLUDED

#ifdef PCDOS
# pragma warning(disable:4135)
# pragma warning(disable:4127) /* for while(TRUE)  */
# pragma warning(disable:4100) /*  allow unreferenced formal parameters */
# pragma warning(disable:4706) /*  allow assignments in conditional expressions */
# pragma warning(disable:4704) /*  allow asm */
#endif

# include "g2types.h"

/* assertion from Writing Solid Code */


#ifdef CHECK
void _Assert(char *,unsigned);  /* prototype */
# define ASSERT(f) \
  if(!(f))  \
      _Assert(__FILE__,__LINE__);
# else
# define ASSERT(f)
#endif


# define refresh() fflush(stdout)


/* fastcall only used by microsoft compilers */
#if !defined(PCDOS) && !defined(WIN31) && !defined(WIN95)
#define _fastcall
#endif

#if !defined(PCDOS) && !defined(win31)
#define near
#define far
#define _huge
#define __huge
#endif

#ifndef __STDC__
# define __STDC__
#endif

#if defined(PCDOS)
# define doint(i) _int86(i,&regs,&regs)
#endif

#define g2abs(x) (((x) > 0)?(x):(-(x)))

struct strategy {
	short value;       /* extra strategic value for this move */
	listval_t param;       /* square in group to check aliveness after lookahead */
	                 /* if square is enemy stone, it should be deader */
	                 /* NOSQUARE means use the group on the square moved to */
	                 /* index into newpat[] if reason is pattern matched */
	short pattern;	 /* pattern number for pattern matching reason */
	short guess;		/* extra guess value for rule */
	unsigned char reason;      /* reason to try this move (rule #) */
	char goodrule;    /* TRUE if this rule is satisfied after lookahead */
	char urgent;      /* TRUE if this rule is urgent */
	};

struct rulestruct {
	int value;	/* value of rule (added after lookahead) */
	int guess;      /* guessed value of rule (used to select moes to try) */
	unsigned short weakest;	/* weakest group this rule applies to */
	unsigned short attack;   /* TRUE if rule is for attacking group */
	};



# define PATYSIZE 6
# define PATXSIZE 6
# define MAXSIZE 5


struct potential {
	unsigned short pot_where; /* square for undercut */
	               /* connection number for connect */
	               /* square for vital */
                   /* army number of threatened group for threat */
	               /* liberty for extend */
	unsigned char pot_val;  /* conservative 8 per eye, for undercut, extend is amount of territory */
						/* value for threat does not include eye value */
	unsigned char pot_max;  /* maximum value for this eye potential */
	unsigned char pot_type;  /* extend, vital, connect, threat, undercut */
	};





/* the following group of defines is safe to change since no harm comes
 * except stupidness if they are two small
 */


# define NUMLEVELS 11


/* release values - not demo, not josedit */
#ifndef PCDOS

/* won't crash if nummoves is too small */
/* MAXMOVE is maximum number of moves allowed in a game */
/* typical game has about 250 moves.  about 400 moves is highest you usually see */
# define NUMMOVES 800
# define MAXMOVE (NUMMOVES-20)
/* MAXLADDER must be greater than MAXMOVE! */
/* must have room for maximum number of generated moves in iscaptured */
# define MAXLADDER (NUMMOVES-10)
/* won't crash if MAXGROUP too small. Each move makes at most one new group.
 * group numbers are not recycled */
# define NUMGROUPS ((group_t)250)  /* max 254 */
/* won't crash if numstrats too small, just gets a little stupid */
# define NUMSTRATS 500
/* won't crash if NUMPLY too small - just sets maximum depth for ladder searches */
# define NUMPLY 70
/* won't crash if NUMPOTENTIAL too small, just gets a little stupid */
/* 500 is enough for ordinary positions */
# define NUMPOTENTIAL 2000
/* usually no more than one new army per move, but could be several.
 * army numbers are recycled, so this is the maximum number of armies on the
 * board at one time. */
/* shouldn't crash if NUMARMIES too small, just will stop accepting moves */
/* it's possible to make positions with over 255 separate groups :-( */
# define NUMARMIES ((army_t)250)  /* max 255 */
/* shouldn't crash if NUMEYERECS too small, just will stop accepting moves */
# define NUMEYERECS ((eye_t)220)  /* max 255 */
/* won't crash if NUMNEWPATS is too small, just gets stupid, since can't remember all matches */
/* 2470 is most I have seen used */
# define NUMNEWPATS 2600
/* shouldn't crash if NUMCONNS is too small, just stops accepting moves */
/* 250 is plenty for ordinary games, but positions can be constructed with up to 1000 */
# define NUMCONNS 500


/* these values for PC-DOS where I try to go for minimim possible data area, leaving some
 * potential for crashes 
 */
#else
# define NUMMOVES 420
# define MAXMOVE (NUMMOVES-20)
# define MAXLADDER (NUMMOVES-10)
/* MAXLADDER must be greater than MAXMOVE! */
/* must have room for maximum number of generated moves in iscaptured */
# define NUMGROUPS 250  /* max 254 */
# define NUMSTRATS 400
# define NUMPLY 70
# define NUMPOTENTIAL 270
# define NUMARMIES 85  /* max 255 */
# define NUMEYERECS 200  /* max 255 */
# define NUMNEWPATS 300
# define NUMCONNS 250
#endif

# define MAXGROUP (NUMGROUPS-20)  /* max group when making a move - leave a few for iscaptured */
# define NUMPCLS (NUMMOVES)
# define ARMIESTOMOVE 20
# define ARMIESTOUPDATE 8
# define EYESTOMOVE 20
# define EYESTOUPDATE 8
# define CONNSTOMOVE 30
# define CONNSTOUPDATE 15 




/* for the PC there is a 64K limit on near memory, and I want list
 * elements to be near for speed.  +8000 is safe for most ordinary games
 * but many more list elements are needed for strange shapes. The worst I have found 
 * need 76,000 list elements at level 9.  Link is 16 bits, so 65,535 is biggest possible
 * value for NUMLIST
 */

# define NUMNBLB 1368
#ifdef PCDOS
# define NUMLIST (NUMNBLB+NUMEYERECS+NUMARMIES+NUMCONNS+8000)
#else
# define NUMLIST (50000)
#endif

/* numsquares has two extra for NOSQUARE and PASS */
# define NUMSQUARES (19*19+2)

# define NUMRUN 14
# define MAXOPENRUN 8
# define MAXEASYRUN 5
# define NEUTRALRUN 10
# define JUMPENEMY 13

# define G2ERROR 0xf000
# define EOL NUMLIST-1
# define NOCONN -1
# define NOSQUARE ((sqr_t)(NUMSQUARES-2))

# ifndef PASS
# define PASS (NOSQUARE+1)
# endif

# define NOGROUP ((group_t)(NUMGROUPS-1))
# define NOARMY ((army_t)(NUMARMIES-1))
# define NOCORNER 4
# define NOEDGE 20
# define BLACKCOLOR 0
# define WHITECOLOR 1
# define NOCOLOR 2
# define NOLD 99
# define NEUTRALLD 1
# define BIGNUM 32767
# define SMALLNUM (-BIGNUM)

/* for cntype[] */

# define CN_UNKNOWN 0
# define CN_ONEPOINTJUMP 1
# define CN_KNIGHTSMOVE 2
# define CN_TWOPOINTJUMP 3
# define CN_HANE 4
# define CN_BAMBOOJOINT 5
# define CN_DIAGONAL 6
# define CN_MULTIPLE 7
# define CN_ONESIDEDEAD 8
# define CN_THREAT 9
# define CN_HALFKNIGHT 10
# define CN_THREEPOINTJUMP 11
# define CN_LARGEKNIGHT 12
# define CN_HALFLARGEKNIGHT 13
# define CN_DOUBLEDIAG 14
# define CN_CORNER 15
# define CN_MULTIHALFKNIGHT 16 

/* for gralive[] */

# define NUMALIVE 26

# define DEAD 25
# define LIFEUNUSED 24
# define WEAK_GROUP 23
# define VERY_WEAK 23
# define MUST_BE_DEAD 22
# define LOOKS_DEAD 21
# define LOSE_SEMEAI 20
# define WEAK 19
# define WEAK_POTENTIAL 18
# define WEAK_SEMEAI 17
# define WEAK_LIMP 16
# define UNSETTLED 15
# define WEAK_KO 15
# define UNSETTLED_RUN 14
# define SEMEAI 13
# define UNSETTLED_DEAD 12
# define UNSETTLED_THREATENED 12
# define RUNNING_FIGHT 11
# define STRONG_KO 10
# define STRONG_SEMEAI 9
# define UNSETTLED_LIMP 8
# define ALIVE 7
# define RUN_NO_EYES 7
# define RUN_OR_LIVE 6
# define WINS_SEMEAI 5
# define SEKI 4
# define MIAI 3
# define BARELY_ALIVE 2
# define VERY_ALIVE 1
# define STRONG_MIAI 1
# define HAS_TWO_EYES 1
# define NEW_ALIVE 0

# define UNSET_RUN 6
# define SEMEAI_LIMP 6
# define SEMEAI_RUN 8
# define LIMP_RUN 10
# define EASY_RUN 14
# define OBVIOUS_RUN 10

/* for potential */
/* threat is actual, certain threat of capture, POTTHREAT is combined threat, or ko */
# define EXTEND 0
# define VITAL 1
# define THREAT 2
# define POTTHREAT 3
# define CONNECT 4
# define UNDERCUT 5
# define NOPOT 6

# define BAD_MOVE -20000

# define HP150 0
# define HP239X 2
# define HP264X 1

# define UP 0
# define LEFT 1
# define RIGHT 2
# define DOWN 3

/* for eyevitrec[] */

/* # define EYEMASK 0xff */
/* # define EYEVALSHIFT 8 */
/* # define EYEVALMASK (int)0x003f */

/* cached value in eyevitval is not valid */
# define EYEVALNONE 63

/* for eyevital list */
# define EYEPOINTMASK 0x3fff
# define EYEFLAGMASK 0xc000
# define EYEADDONLY 0x8000
# define EYERMONLY 0x4000
/*# define V_NOEYEVAL (EYEVALNONE<<EYEVALSHIFT) */
/* # define V_EYE(v) ((eye_t)(v&EYEMASK)) */
/* # define V_VAL(v) ((v>>EYEVALSHIFT) & EYEVALMASK) */

/* for eyetype[] */

# define NOEYE 0
# define ONEPOINTEYE 1
# define TWOPOINTEYE 2
# define DEADEYE 3
# define THRTEYE 4
# define BIGEYE 5
# define LINEEYE 6
# define FOURPTBLOCKEYE 7
# define OPENLINEEYE 8
# define CORNEREYE 9
# define NEAREDGEEYE 10
# define VERYBIGEYE 11

/* for eyestatus[] */

# define ACC 0
# define QUICK 1
# define SLOW 2

/* for move reasons */

# define ATTACK 1
# define DEFEND 2
# define PATTERN 4
# define DEFVAL1 8
# define DEFVAL2 16
# define RUN 32
# define ATKVAL1 64
# define ATKVAL2 128
# define JOSEKIMOVE 256
# define PATBETTER 512
# define NAMEGROUP 1024 

# define FUSEKI 0
# define MIDDLE 1
# define ENDGAME 2

/* for cnprot[] */

# define CANCONN(x) ((x) >= CAN_CONNECT && !PROTCVAL(c))
# define PROTCONN(x) (PROTCVAL(cnprot[x]))
# define PROTCVAL(x) ((x) > KO_CONNECT)
 /* 10/5/95 was >= KO_CONNECT! */

/* for cnprot[] */ 
/* cuttable connections */
/* can't connect must be zero for canconnlink */
/* any nonzero value must be able to connect */

# define CANT_CONNECT 0
# define MIGHT_CONNECT 1
# define CAN_CONNECT 2
# define SHARED_CONNECT 3
# define KO_CONNECT 4

/* uncuttable connections */

# define AJI_CONNECT 5
# define SOLID_CONNECT 6

# ifndef TRUE
# define FALSE 0
# define TRUE 1
# endif

# define NO 0
# define YES 1
# define MAYBE 2
  
# define MAXRTVAL 200
	/* divisor for adjusting radiated territory when done 
           MAXRTVAL is one point */
# define URGENT 1
# define NOT_URGENT 0

/* User interface types */

# define TERMINAL 0
# define X10 1
# define X11 2
# define IBMPC 3
# define MACINTOSH 4

/* data structure defines */

/* board */

# define S_EDGE(s) edge[(s)]
# define S_EDGE2(s) edge2[(s)]
# define S_XVAL(s) xval[(s)]
# define S_YVAL(S) yval[(s)]

# define S_GROUP(s) board[(s)]
# define S_ARMY(s) grarmy[board[(s)]]
# define S_COLOR(s) grcolor[board[(s)]]
# define S_EYE(s) eyerec[(s)]
# define S_URGENT(s) urgent[(s)]
# define S_SCORE(s) scoreval[(s)]
# define S_SHAPE_L(s) shapebrd[(s)]
# define S_ALIVE(s) gralive[board[(s)]]
# define S_NUMLIBS(s) grlibs[board[(s)]]
# define S_THREATENED(s) grthreatened[board[s]]
# define S_NEUTRAL(s) (ld[s] == NEUTRALLD)
# define S_EMPTYNBRS(s) (lnbn[s])

/* groups */

# define G_PIECE_L(g) grpieces[(g)]
# define G_ARMY(g) grarmy[(g)]
# define G_COLOR(g) grcolor[(g)]

# define G_SIZE(g) grsize[(g)]
# define G_LIB_L(g) grlbp[(g)]
# define G_NUMLIBS(g) grlibs[(g)]
# define G_NBR_L(g) grnbp[(g)]
# define G_ALIVE(g) gralive[(g)]
# define G_THREATENED(g) grthreatened[(g)]


/* armies */

# define A_GROUP_L(a) armygroups[(a)]
# define A_DEADGROUP_L(a) armydeadgroups[(a)]
# define A_GROUP(a) (list[armygroups(a)])
# define A_EYE_L(a) armyeyerec[(a)]
# define A_COLOR(a) grcolor[list[armygroups[(a)]]]

# define A_SIZE(a) armysize[(a)]
# define A_LIB_L(a) armylbp[(a)]
# define A_NUMLIBS(a) armylibs[(a)]
# define A_NBR_L(a) (list[armynbp[(a)]] == EOL? getarmynbp(a) : armynbp[a])
# define A_ALIVE(a) gralive[list[armygroups[(a)]]]
# define A_THREATENED(a) grthreatened[list[armygroups[(a)]]]
# define A_NUMEYES(a) armyeyes[(a)]

/* moves */

# define M_SQUARE(m) mvs[(m)]
# define M_CAPT_L(m) mvcapt[(m)]
# define M_CONN_L(m) mvconn[(m)]
# define M_COLOR(m) mvcolor[(m)]
# define M_NEXT(m) mvnext[(m)]
# define M_KOSAVE(m) kosave[(m)]

/* eyes */

# define E_TYPE(e) eyetype[(e)]
# define E_SQR_L(e) eyeptr[(e)]
# define E_VITAL_L(e) eyevital[(e)]
# define E_VAL(e) eyeval[(e)]
# define E_POT(e) eyepot[(e)]
# define E_MIN(e) eyemin[(e)]


# define ADDBITS(s,c) addbits(s,c)
# define DELBITS(s,c) delbits(s,c)

# define MAXBOXR 22
# define MAXERROR 180
# define ERRORLENGTH MAXBOXR


/* maximum distance to radiate influence */
# define MAXDIST 14

#endif