@@ -144,7 +144,7 @@ impl Board {
144
144
_ => panic ! ( "Invalid FEN" ) ,
145
145
} ;
146
146
147
- self . add_piece ( color, piece, rank * 8 + file) ;
147
+ self . add_piece ( color, piece, rank * BOARD_WIDTH + file) ;
148
148
file += 1 ;
149
149
}
150
150
}
@@ -237,27 +237,27 @@ impl Board {
237
237
fn square_to_index ( square : & str ) -> usize {
238
238
let file = square. chars ( ) . nth ( 0 ) . unwrap ( ) as usize - 'a' as usize ;
239
239
let rank = square. chars ( ) . nth ( 1 ) . unwrap ( ) as usize - '1' as usize ;
240
- rank * 8 + file
240
+ rank * BOARD_WIDTH + file
241
241
}
242
242
243
243
fn index_to_square ( index : usize ) -> String {
244
- let file = ( index % 8 ) as u8 + b'a' ;
245
- let rank = ( index / 8 ) as u8 + b'1' ;
244
+ let file = ( index % BOARD_WIDTH ) as u8 + b'a' ;
245
+ let rank = ( index / BOARD_WIDTH ) as u8 + b'1' ;
246
246
format ! ( "{}{}" , file as char , rank as char )
247
247
}
248
248
249
249
fn is_square_empty ( & self , index : usize ) -> bool {
250
250
!self . white_occupancy . is_set ( index) && !self . black_occupancy . is_set ( index)
251
251
}
252
252
253
- pub fn is_index_in_bounds ( index : i64 ) -> bool {
254
- index >= 0 && index < 64
253
+ pub fn is_index_in_bounds ( index : i32 ) -> bool {
254
+ index >= 0 && index < BOARD_SIZE as i32
255
255
}
256
256
257
257
pub fn print ( & self ) {
258
- for rank in ( 0 ..8 ) . rev ( ) {
259
- for file in 0 ..8 {
260
- let index = rank * 8 + file;
258
+ for rank in ( 0 ..BOARD_WIDTH ) . rev ( ) {
259
+ for file in 0 ..BOARD_WIDTH {
260
+ let index = rank * BOARD_WIDTH + file;
261
261
let piece = if self . white_pieces . pawns . is_set ( index) {
262
262
'P'
263
263
} else if self . white_pieces . knights . is_set ( index) {
@@ -295,8 +295,8 @@ impl Board {
295
295
pub fn make_move ( & mut self , mv : & Move ) {
296
296
if mv. en_passant {
297
297
let direction = match mv. color {
298
- Color :: White => 8 ,
299
- Color :: Black => - 8 ,
298
+ Color :: White => MOVE_UP ,
299
+ Color :: Black => MOVE_DOWN ,
300
300
} ;
301
301
self . remove_piece ( mv. color , Piece :: Pawn , mv. from ) ;
302
302
self . add_piece ( mv. color , Piece :: Pawn , mv. to ) ;
@@ -350,10 +350,10 @@ impl Board {
350
350
351
351
if mv. en_passant {
352
352
let direction = match mv. color {
353
- Color :: White => 8 ,
354
- Color :: Black => - 8 ,
353
+ Color :: White => MOVE_UP ,
354
+ Color :: Black => MOVE_DOWN ,
355
355
} ;
356
- self . en_passant_square = Some ( ( mv. to as i64 - direction) as usize ) ;
356
+ self . en_passant_square = Some ( ( mv. to as i32 - direction) as usize ) ;
357
357
}
358
358
359
359
self . turn = match self . turn {
@@ -398,19 +398,19 @@ impl Board {
398
398
399
399
// TODO: Validate check
400
400
401
- for i in 0 ..64 {
401
+ for i in 0 ..BOARD_SIZE {
402
402
if !pawns. is_set ( i) {
403
403
continue ;
404
404
}
405
405
406
406
let direction = match self . turn {
407
- Color :: White => 8 ,
408
- Color :: Black => - 8 ,
407
+ Color :: White => MOVE_UP ,
408
+ Color :: Black => MOVE_DOWN ,
409
409
} ;
410
410
411
411
let pos = i;
412
412
let from = i;
413
- let possible_to = i as i64 + direction;
413
+ let possible_to = i as i32 + direction;
414
414
415
415
if !Board :: is_index_in_bounds ( possible_to) {
416
416
continue ;
@@ -419,10 +419,10 @@ impl Board {
419
419
let to = possible_to as usize ;
420
420
421
421
// DOUBLE PUSH
422
- if ( RANK_2 . is_set ( pos) && self . turn == Color :: White )
423
- || ( RANK_7 . is_set ( pos) && self . turn == Color :: Black )
422
+ if ( ROW_2 . is_set ( pos) && self . turn == Color :: White )
423
+ || ( ROW_7 . is_set ( pos) && self . turn == Color :: Black )
424
424
{
425
- let double = to as i64 + direction;
425
+ let double = to as i32 + direction;
426
426
if self . is_square_empty ( to) && self . is_square_empty ( double as usize ) {
427
427
moves. push ( Move {
428
428
from,
@@ -465,8 +465,8 @@ impl Board {
465
465
}
466
466
467
467
// PROMOTION
468
- if ( self . turn == Color :: White && RANK_7 . is_set ( pos) && self . is_square_empty ( to) )
469
- || ( self . turn == Color :: Black && RANK_2 . is_set ( pos) && self . is_square_empty ( to) )
468
+ if ( self . turn == Color :: White && ROW_7 . is_set ( pos) && self . is_square_empty ( to) )
469
+ || ( self . turn == Color :: Black && ROW_2 . is_set ( pos) && self . is_square_empty ( to) )
470
470
{
471
471
moves. push ( Move {
472
472
from,
0 commit comments