1 /***************************************************************************
2 chess.cpp - description
4 begin : Fri Jan 11 2002
5 copyright : (C) 2002-2005 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
25 flags_stack
= new uint8_t[4096];
26 old_hashes
= new HashKey
[4096];
31 //-------------------------------------------------------------------------------------
32 //-------------------------------------------------------------------------------------
34 void Board::set_as_default()
36 memcpy(&data
[0],b_start
,128);
37 memcpy(&castle_adj
[0],b_castle_adj
,128);
44 castle_passing_mask
= 0xfc;
46 color_to_move
= WHITE
;
53 second_rank
[1] = 0x10;
54 second_rank
[0] = 0x60;
55 passant_rank
[1] = 0x40;
56 passant_rank
[0] = 0x30;
57 seventh_rank
[1] = 0x60;
58 seventh_rank
[0] = 0x10;
62 recalc_mat_tracking();
70 void Board::set_as_default()
72 static uint8_t b_start55
[] =
77 WR
,WN
,WB
,WQ
,WK
,STONE
,STONE
,STONE
,SENDL
,
78 WP
,WP
,WP
,WP
,WP
,STONE
,STONE
,STONE
,SENDL
,
79 __
,__
,__
,__
,__
,STONE
,STONE
,STONE
,SENDL
,
80 BP
,BP
,BP
,BP
,BP
,STONE
,STONE
,STONE
,SENDL
,
81 BR
,BN
,BB
,BQ
,BK
,STONE
,STONE
,STONE
,SENDL
83 static uint8_t b_castle_adj55
[] =
85 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
86 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
87 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
88 0xd0,0xf0,0xf0,0xf0,0xc0,0xf0,0xf0,0xf0,ENDL
,
89 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
90 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
91 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
92 0x70,0xf0,0xf0,0xf0,0x30,0xf0,0xf0,0xf0,ENDL
95 memcpy(data
,b_start55
,128);
96 memset(data
+128, 0xff, 128);
97 memcpy(castle_adj
,b_castle_adj55
,128);
104 castle_passing_mask
= 0xfc;
106 color_to_move
= WHITE
;
111 first_rank
[1] = 0x30;
112 first_rank
[0] = 0x70;
113 second_rank
[1] = 0x40;
114 second_rank
[0] = 0x60;
115 passant_rank
[1] = 0x40;
116 passant_rank
[0] = 0x60;
117 seventh_rank
[1] = 0x60;
118 seventh_rank
[0] = 0x40;
121 recalc_mat_tracking();
126 void Board::set_as_default()
128 static uint8_t b_start68
[] =
131 WR
,WN
,WB
,WQ
,WK
,WB
,WN
,WR
,SENDL
,
132 WP
,WP
,WP
,WP
,WP
,WP
,WP
,WP
,SENDL
,
133 __
,__
,__
,__
,__
,__
,__
,__
,SENDL
,
134 __
,__
,__
,__
,__
,__
,__
,__
,SENDL
,
135 BP
,BP
,BP
,BP
,BP
,BP
,BP
,BP
,SENDL
,
136 BR
,BN
,BB
,BQ
,BK
,BB
,BN
,BR
,SENDL
,
139 static uint8_t b_castle_adj68
[] =
141 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
142 0xd0,0xf0,0xf0,0xf0,0xc0,0xf0,0xf0,0xe0,ENDL
,
143 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
144 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
145 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
146 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
147 0x70,0xf0,0xf0,0xf0,0x30,0xf0,0xf0,0xb0,ENDL
,
148 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
151 memcpy(data
,b_start68
,128);
152 memset(data
+128, 0xff, 128);
153 memcpy(castle_adj
,b_castle_adj68
,128);
160 castle_passing_mask
= 0xfc;
162 color_to_move
= WHITE
;
167 first_rank
[1] = 0x10;
168 first_rank
[0] = 0x60;
169 second_rank
[1] = 0x20;
170 second_rank
[0] = 0x50;
171 passant_rank
[1] = 0x30;
172 passant_rank
[0] = 0x40;
173 seventh_rank
[1] = 0x50;
174 seventh_rank
[0] = 0x20;
177 recalc_mat_tracking();
185 /*******************************************************************************
186 initialize a table with all possible horse moves
187 *******************************************************************************/
189 void Board::init_knight_moves()
191 char poss_hmoves
[8][2] = {{1,2},{-1,2},{1,-2},{-1,-2},
192 {2,1},{-2,1},{2,-1},{-2,-1}};
196 knightmoves
= new KnightMove
[128];
198 // For every square just check all moves;
202 KnightMove
* current
= &knightmoves
[ POS_XY(x
,y
) ];
207 int a
= x
+ poss_hmoves
[i
][0];
208 int b
= y
+ poss_hmoves
[i
][1];
210 if( (a
>= 0) && (a
< 8) && (b
>= 0) && (b
< 8) )
211 current
->jump
[c
++] = POS_XY(a
,b
);
214 current
->jump
[i
] = 0xff;
219 //-------------------------------------------------------------------------------------
222 /* create the hashkeys.cpp file from a raw file with random data (ie /dev/urandom) */
223 void Board::init_hash_keys(const char* file
)
225 HashKey
*hash_keys
= new HashKey
[14*128];
226 FILE *f
= fopen(file
, "r");
229 printf("Error, could not read hash keys file!\n");
233 //printf("loaded \"hashkeys.dat\"\n");
234 if(fread(hash_keys
, sizeof(HashKey
), 14*128, f
) != 14*128)
235 printf("Error, could not read hash keys file!\n");
238 FILE *s
= fopen("hashkeys.cpp", "w");
240 fprintf(s
, "/* Automatically generated, do not edit */\n");
241 fprintf(s
, "#include \"board.h\"\n");
242 fprintf(s
, "HashKey Board::hash_keys[14*128] = {\n");
244 for(int i
=0;i
<14*128;i
++)
246 fprintf(s
, " HashKey( 0x%016llxULL, 0x%08x )",
247 (unsigned long long)hash_keys
[i
].check
, hash_keys
[i
].index
);
256 printf("hashkeys.cpp generated!\n");