1 #define ushort unsigned short
2 #define uchar unsigned char
3 #define ull unsigned long long
4 #define ulong unsigned long
7 #define MAX_TT_SEARCH 30
20 #define WHITE_PLAYER 1 //player 1
21 #define BLACK_PLAYER 2 //player 2
36 uchar wallcol
, wallrow
;
40 typedef struct move_s move
;
43 //Basic game state at one point in time
62 //state stored in the transposition table
76 typedef struct state_s state
;
77 typedef struct state_t state_t
;
80 //Collection of all game states
97 //paths to game pieces & squares
100 char white_piece
[255];
101 char black_piece
[255];
112 int print_statistics
;
117 struct engine engine
;
118 struct images images
;
122 // Different player choices
128 /* intersting statistic globals */
140 int sean_heval(state
*s
);
141 move
savemove(state
*s
, move m
);
142 int mmselect(int oldval
, int newval
);
143 int test(state
*s
, uchar col
, uchar row
);
144 int xor(ull bd
[2], uchar col
, uchar row
);
146 move
search(state
*s
, int depth
, int alpha
, int beta
, int, int);
147 move
isearch(state
*s
, int);
148 move
getmove(state
*s
, int player
);
150 int moves(ushort q
[][13], int w
);
151 int minmoves(ushort q
[][13], int w
);
152 int maxmoves(ushort q
[][13], int w
);
153 int countmoves(ushort q
[][13], int w
);
154 int pbits(ushort q
[][13], int s
);
155 int children(state
*s
, move movelist
[]);
156 int countchildren(state
*s
);
157 int undomove(state
*s
, move m
);
160 int move_lookup(move
*m
, move movelist
[], int move_count
);
161 void dup_state(state
*s_old
, state
*s_new
);
164 void load_values_from_file();
165 void store_values_in_file();
166 int load_images_from_theme(char *theme
);
170 int makemove(state
*s
, move m
);
171 void print_usage_menu();
172 void parse_args(int argc
, char *argv
[]);
176 int get_forward_diag(ull board_l
, ull board_u
, int diag
);
177 int get_back_diag(ull board_l
, ull board_u
, int diag
);
178 void put_forward_diag(ull
*board_l
, ull
*board_u
, ushort stream
, int diag
);
179 void put_back_diag(ull
*board_l
, ull
*board_u
, ushort stream
, int diag
);
180 int calc_stream_moves(ushort stream
, ushort pos
, ushort len
);
181 int calc_moves(ull board_l
, ull board_u
, int pos
);
182 int count_contig_bits(ushort stream
, int len
);
184 ushort
gen_web_stream(ushort stream
, int pos
, int len
);
185 ushort
gen_web_stream_plus(ushort stream
, int pos
, int len
);
186 void gen_web_board(ull
*web_l
, ull
*web_u
, ull board_l
, ull board_u
, int pos
);
187 int gen_web_board_count(ull
*web_l
, ull
*web_u
, ull board_l
, ull board_u
, int pos
);
188 void gen_dirs_board(ull
*board_l
, ull
*board_u
, int pos
);
189 int count_bits(ull board_l
, ull board_u
);
193 int pbvec(ull l
, ull u
);
195 state_t
*tt_lookup(state
*s
);
196 void tt_store(state
*s
, short alpha
, short beta
);
197 void tt_update(state
*s
, short alpha
, short beta
);
199 int tt_compare(state
*s
, state_t
*t
);
204 //convert x,y coords to pos 0-99
205 #define XY_TO_POS(x,y) y*10 + x
207 /* Bit board stuff */
208 #define GET_ROW(board, row) (board >> (row%5) * 10) & 0x3ff
209 #define GET_COL(board_l, board_u, col) (GET_HALF_COL(board_l, col) | (GET_HALF_COL(board_u, col) << 5))
211 #define GET_HALF_COL(board, col) (((board >> col) &0x1) | ((board >> (col + 9)) &0x2) | ((board >> (col + 18)) &0x4) | ((board >> (col + 27)) &0x8) | ((board >> (col + 36)) &0x10))
213 /* These defines require a board number between 0-99 */
214 //Tells you where in a stream of 10 bits the position (x,y) would be (0-9)
215 #define GET_COL_POS(y) (int) y / 10
216 #define GET_ROW_POS(x) x % 10
217 //Tells you where in a stream of up to 10 bits the position (f,b) would be (0-9)
218 #define GET_FDIAG_POS(f) (f%10 > f/10) ? f/10 : f%10
219 #define GET_BDIAG_POS(b) (b/10 < (10 - b%10)) ? b/10 : 9 - b%10
221 //Gets diag numbers, for passing into get_forw_diag() & get_back_diag()
222 #define GET_FDIAG(f) (f%10 > f/10) ? f - ((f/10) * 11) : f - ((f%10) * 11)
223 #define GET_BDIAG(b) (b/10 < (10 - b%10)) ? b - ((b/10) * 9) : b - ((9 - (b%10)) * 9)
225 //Calculates length of a diagonal, pass in value from GET_FDIAG/GET_BDIAG
226 //Note: Don't call GET_[F,B]DIAG within GET_[F,B]DIAG_LEN, you get really weird results
227 //eg GET_FDIAG_LEN(GET_FDIAG(pos)). Instead, store it into a variable first:
228 //eg diag = GET_FDIAG(pos); len = GET_FDIAG_LEN(diag);
229 #define GET_FDIAG_LEN(fdiag) (fdiag < 10) ? (10 - fdiag) : (10 - fdiag/10)
230 #define GET_BDIAG_LEN(bdiag) (bdiag < 10) ? bdiag + 1 : (10 - bdiag/10)
232 #define PUT_ROW(board, row, stream) board |= ((ull) stream << ((row % 5) * 10))
233 #define PUT_COL(board_l, board_u, col, stream) PUT_HALF_COL(board_l, col, stream); PUT_HALF_COL(board_u, col, stream >> 5)
234 #define PUT_HALF_COL(board, col, stream) board |= ((((ull)stream & 0x1) << col) | \
235 (((ull)stream & 0x2) << (col + 9)) | \
236 (((ull)stream & 0x4) << (col + 18)) | \
237 (((ull)stream & 0x8) << (col + 27)) | \
238 (((ull)stream & 0x10) << (col + 36)))