/* vi: set tabstop=4 shiftwidth=4: */ /* * $Id: chess.h,v 1.8 1997/05/29 16:30:27 schweikh Exp $ */ #ifndef CHESS_H #define CHESS_H #define LIBDIR "/opt/jj/lib" #define LANGUAGE_TAG "=" #define MATE_TAG "#" /* * __inline confuses lclint and compilers other than gcc. Define it empty. */ #if defined (__LCLINT__) || !defined (__GNUC__) #define __inline #endif #define BIT0 0x0001 #define BIT1 0x0002 #define BIT2 0x0004 #define BIT3 0x0008 #define BIT4 0x0010 #define BIT5 0x0020 #define BIT6 0x0040 #define BIT7 0x0080 #define BIT8 0x0100 #define BIT9 0x0200 #define BIT10 0x0400 #define BIT11 0x0800 #define BIT12 0x1000 #define BIT13 0x2000 #define BIT14 0x4000 #define BIT15 0x8000 #define BIT16 0x00010000 #define BIT17 0x00020000 #define BIT18 0x00040000 #define BIT19 0x00080000 #define BIT20 0x00100000 #define BIT21 0x00200000 #define BIT22 0x00400000 #define BIT23 0x00800000 #define BIT24 0x01000000 #define BIT25 0x02000000 #define BIT26 0x04000000 #define BIT27 0x08000000 #define BIT28 0x10000000 #define BIT29 0x20000000 #define BIT30 0x40000000 #define BIT31 0x80000000 #define FREE 0 #define KING BIT0 #define PAWN BIT1 #define KNIGHT BIT2 #define BISHOP BIT3 #define ROOK BIT4 #define QUEEN BIT5 #define BLACK BIT6 #define WHITE BIT7 #define IS_BLACK(x) ((x) & BLACK) #define IS_WHITE(x) ((x) & WHITE) #define MAX_P BIT5 #define MAX_MOVES 256 #define MOVE_CACHE_SIZE 8 #define MV_CAPT BIT9 #define MV_EP BIT19 #define MV_CHECK BIT20 #define MV_DOUBLE BIT21 #define MV_MATE BIT22 #define MV_STALE BIT23 #define MV_CANMATE BIT24 enum { no_piece, pawn, knight, bishop, rook, queen, king, bpawn }; /* * encoding of the variable `special' * * The en passant position is set when a pawn is moved 2 squares, regardless * of wheter there's an opponents's pawn right beside it. It is cleared when * the opponent's selected move is not to take it. */ #define SP_EP_POS 0x003f /* position (24-39) of pawn, MUST be * at bit0 */ #define SP_O_O_O 0x0040 /* castling */ #define SP_O_O 0x0080 /* long and */ #define SP_o_o_o 0x0100 /* short for */ #define SP_o_o 0x0200 /* white & black */ #define SP_BLACK2MV 0x0400 /* set if black is to move */ #define BLACK_TO_MOVE (s->sp & SP_BLACK2MV) enum { A1, B1, C1, D1, E1, F1, G1, H1, A2, B2, C2, D2, E2, F2, G2, H2, A3, B3, C3, D3, E3, F3, G3, H3, A4, B4, C4, D4, E4, F4, G4, H4, A5, B5, C5, D5, E5, F5, G5, H5, A6, B6, C6, D6, E6, F6, G6, H6, A7, B7, C7, D7, E7, F7, G7, H7, A8, B8, C8, D8, E8, F8, G8, H8 }; #define POSSIBLE_O_O_O (s->pos[0][0] == E1 && board[A1] == (WHITE|ROOK)) #define POSSIBLE_o_o_o (s->pos[1][0] == E8 && board[A8] == (BLACK|ROOK)) #define POSSIBLE_O_O (s->pos[0][0] == E1 && board[H1] == (WHITE|ROOK)) #define POSSIBLE_o_o (s->pos[1][0] == E8 && board[H8] == (BLACK|ROOK)) /* * These are only used when not checked, no need to test for that: */ #define CAN_O_O_O (POSSIBLE_O_O_O && (s->sp & SP_O_O_O) && board[B1] == FREE \ && board[C1] == FREE && board[D1] == FREE && !attacked[A1] \ && !attacked[B1] && !attacked[C1] && !attacked[D1]) #define CAN_o_o_o (POSSIBLE_o_o_o && (s->sp & SP_o_o_o) && board[B8] == FREE \ && board[C8] == FREE && board[D8] == FREE && !attacked[A8] \ && !attacked[B8] && !attacked[C8] && !attacked[D8]) #define CAN_O_O (POSSIBLE_O_O && (s->sp & SP_O_O) && board[F1] == FREE && \ board[G1] == FREE && !attacked[F1] && !attacked[G1] && !attacked[H1]) #define CAN_o_o (POSSIBLE_o_o && (s->sp & SP_o_o) && board[F8] == FREE && \ board[G8] == FREE && !attacked[F8] && !attacked[G8] && !attacked[H8]) #define IS_OPPONENTS_KING(x) (((x) == (BLACK|KING) && BLACK_TO_MOVE) || \ ((x) == (WHITE|KING) && !BLACK_TO_MOVE)) #define IS_QRB(x) ((x) & (QUEEN|ROOK|BISHOP)) #define ABS(x) ((x) >= 0 ? (x) : -(x)) #define ROW(x) ((x) >> 3) #define COL(x) ((x) & 7) #define INPUT_ERROR (-1) /* read_board return upon invalid input */ #define dump_attacks(x) do { int I; \ Printf (x); \ for (I = 63; I > 0; I -= 8) \ Printf ("%4hd %4hd %4hd %4hd %4hd %4hd %4hd %4hd\n", \ attacked[I-7], attacked[I-6], attacked[I-5], attacked[I-4], \ attacked[I-3], attacked[I-2], attacked[I-1], attacked[I]); \ } while (0) /* * bool: type used for boolean values 0 or 1. */ typedef int bool; /* * A bit vector with at least 32 bits. */ typedef unsigned long lbitvec; typedef struct Mlist { lbitvec mv; /* notation */ struct Mlist *answer; /* pointer to opponent's answer moves */ } Mlist; typedef struct { unsigned char index; /* index into fig[] (0..15) */ unsigned char dest; /* destination square (0..63) */ } move_t; typedef struct { unsigned char brd[64]; /* board info, MUST BE the first member */ unsigned char fig[2][16]; /* figure types for both parties */ unsigned char pos[2][16]; /* position of each figure for both parties */ int n[2]; /* number of pieces for both parties */ unsigned pm[2]; /* pawn masks for both parties */ unsigned lm[2]; /* long-range figure masks for both parties */ unsigned sp; /* specials: ep, castles. MUST BE last member */ } State; typedef struct { /* language dependent string and character * constants */ char *white, *black, *King, *Pawn, *impossible, *error, *errors, *no_w_king, *no_b_king, *no_w_pawn, *no_b_pawn, *cant_parse, *not_free, *ep, *allowed, *disallowed, *can_ep, *cant_ep, *solution, *no_solution, *mate, *stale, *move, *moves, *to_move_w, *to_move_b, *castling, *w_short, *b_short, *w_long, *b_long, *mate_in, *n_mate, *more_rows, *not8, *inv_piece, K, k, Q, q, R, r, B, b, N, n, P, p, cp, mv, mt, st, ch, db, white1, black1; } stringlist; typedef void handler_t (int); /* signal handler type */ #endif /* defined CHESS_H */