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 ***************************************************************************/
28 //-------------------------------------------------------------------------------------
29 //-------------------------------------------------------------------------------------
31 void Board::set_as_default()
33 memcpy(&data
[0],b_start
,128);
34 memcpy(&castle_adj
[0],b_castle_adj
,128);
38 castle_passing_mask
= 0xfc;
40 color_to_move
= WHITE
;
47 second_rank
[1] = 0x10;
48 second_rank
[0] = 0x60;
49 passant_rank
[1] = 0x40;
50 passant_rank
[0] = 0x30;
51 seventh_rank
[1] = 0x60;
52 seventh_rank
[0] = 0x10;
56 recalc_mat_tracking();
64 void Board::set_as_default()
66 static uint8_t b_start55
[] =
71 WR
,WN
,WB
,WQ
,WK
,STONE
,STONE
,STONE
,SENDL
,
72 WP
,WP
,WP
,WP
,WP
,STONE
,STONE
,STONE
,SENDL
,
73 __
,__
,__
,__
,__
,STONE
,STONE
,STONE
,SENDL
,
74 BP
,BP
,BP
,BP
,BP
,STONE
,STONE
,STONE
,SENDL
,
75 BR
,BN
,BB
,BQ
,BK
,STONE
,STONE
,STONE
,SENDL
77 static uint8_t b_castle_adj55
[] =
79 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
80 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
81 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
82 0xd0,0xf0,0xf0,0xf0,0xc0,0xf0,0xf0,0xf0,ENDL
,
83 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
84 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
85 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
86 0x70,0xf0,0xf0,0xf0,0x30,0xf0,0xf0,0xf0,ENDL
89 memcpy(data
,b_start55
,128);
90 memset(data
+128, 0xff, 128);
91 memcpy(castle_adj
,b_castle_adj55
,128);
98 castle_passing_mask
= 0xfc;
100 color_to_move
= WHITE
;
105 first_rank
[1] = 0x30;
106 first_rank
[0] = 0x70;
107 second_rank
[1] = 0x40;
108 second_rank
[0] = 0x60;
109 passant_rank
[1] = 0x40;
110 passant_rank
[0] = 0x60;
111 seventh_rank
[1] = 0x60;
112 seventh_rank
[0] = 0x40;
115 recalc_mat_tracking();
120 void Board::set_as_default()
122 static uint8_t b_start68
[] =
125 WR
,WN
,WB
,WQ
,WK
,WB
,WN
,WR
,SENDL
,
126 WP
,WP
,WP
,WP
,WP
,WP
,WP
,WP
,SENDL
,
127 __
,__
,__
,__
,__
,__
,__
,__
,SENDL
,
128 __
,__
,__
,__
,__
,__
,__
,__
,SENDL
,
129 BP
,BP
,BP
,BP
,BP
,BP
,BP
,BP
,SENDL
,
130 BR
,BN
,BB
,BQ
,BK
,BB
,BN
,BR
,SENDL
,
133 static uint8_t b_castle_adj68
[] =
135 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
136 0xd0,0xf0,0xf0,0xf0,0xc0,0xf0,0xf0,0xe0,ENDL
,
137 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
138 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
139 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
140 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
,
141 0x70,0xf0,0xf0,0xf0,0x30,0xf0,0xf0,0xb0,ENDL
,
142 0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,ENDL
145 memcpy(data
,b_start68
,128);
146 memset(data
+128, 0xff, 128);
147 memcpy(castle_adj
,b_castle_adj68
,128);
154 castle_passing_mask
= 0xfc;
156 color_to_move
= WHITE
;
161 first_rank
[1] = 0x10;
162 first_rank
[0] = 0x60;
163 second_rank
[1] = 0x20;
164 second_rank
[0] = 0x50;
165 passant_rank
[1] = 0x30;
166 passant_rank
[0] = 0x40;
167 seventh_rank
[1] = 0x50;
168 seventh_rank
[0] = 0x20;
171 recalc_mat_tracking();
179 /*******************************************************************************
180 initialize a table with all possible horse moves
181 *******************************************************************************/
183 void Board::init_knight_moves()
185 char poss_hmoves
[8][2] = {{1,2},{-1,2},{1,-2},{-1,-2},
186 {2,1},{-2,1},{2,-1},{-2,-1}};
190 knightmoves
= new KnightMove
[128];
192 // For every square just check all moves;
196 KnightMove
* current
= &knightmoves
[ POS_XY(x
,y
) ];
201 int a
= x
+ poss_hmoves
[i
][0];
202 int b
= y
+ poss_hmoves
[i
][1];
204 if( (a
>= 0) && (a
< 8) && (b
>= 0) && (b
< 8) )
205 current
->jump
[c
++] = POS_XY(a
,b
);
208 current
->jump
[i
] = 0xff;
213 //-------------------------------------------------------------------------------------
216 /* create the hashkeys.cpp file from a raw file with random data (ie /dev/urandom) */
217 void Board::init_hash_keys(const char* file
)
219 HashKey
*hash_keys
= new HashKey
[14*128];
220 FILE *f
= fopen(file
, "r");
223 printf("Error, could not read hash keys file!\n");
227 //printf("loaded \"hashkeys.dat\"\n");
228 if(fread(hash_keys
, sizeof(HashKey
), 14*128, f
) != 14*128)
229 printf("Error, could not read hash keys file!\n");
232 FILE *s
= fopen("hashkeys.cpp", "w");
234 fprintf(s
, "/* Automatically generated, do not edit */\n");
235 fprintf(s
, "#include \"board.h\"\n");
236 fprintf(s
, "HashKey Board::hash_keys[14*128] = {\n");
238 for(int i
=0;i
<14*128;i
++)
240 fprintf(s
, " HashKey( 0x%016llxULL, 0x%08x )",
241 (unsigned long long)hash_keys
[i
].check
, hash_keys
[i
].index
);
250 printf("hashkeys.cpp generated!\n");