@@ -14,6 +14,29 @@ use std::ops::{Deref, DerefMut, Sub};
1414const RANKS : [ char ; 8 ] = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' ] ;
1515const FILES : [ char ; 8 ] = [ '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' ] ;
1616
17+ // Lookup tables for converting bit index (0-63) to board coordinates
18+ const SQUARE_TO_RANK : [ usize ; 64 ] = [
19+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
20+ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
21+ 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 ,
22+ 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ,
23+ 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 ,
24+ 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 ,
25+ 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 ,
26+ 7 , 7 , 7 , 7 , 7 , 7 , 7 , 7 ,
27+ ] ;
28+
29+ const SQUARE_TO_FILE : [ usize ; 64 ] = [
30+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
31+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
32+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
33+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
34+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
35+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
36+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
37+ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
38+ ] ;
39+
1740#[ derive( Clone , Copy ) ]
1841pub struct BoardMap {
1942 squares : [ [ Piece ; 8 ] ; 8 ] ,
@@ -1082,7 +1105,7 @@ impl BoardMap {
10821105 let square_idx = active_bits. trailing_zeros ( ) as usize ;
10831106 active_bits ^= 1u64 << square_idx; // Clear the bit
10841107
1085- let from_move = [ square_idx / 8 , square_idx % 8 ] ;
1108+ let from_move = [ SQUARE_TO_RANK [ square_idx] , SQUARE_TO_FILE [ square_idx] ] ;
10861109 let to_moves = self . gen_legal_positions ( from_move) ;
10871110 let moves = to_moves
10881111 . iter ( )
@@ -1106,7 +1129,7 @@ impl BoardMap {
11061129 let square_idx = opponent_bits. trailing_zeros ( ) as usize ;
11071130 opponent_bits ^= 1u64 << square_idx; // Clear the bit
11081131
1109- let pos = [ square_idx / 8 , square_idx % 8 ] ;
1132+ let pos = [ SQUARE_TO_RANK [ square_idx] , SQUARE_TO_FILE [ square_idx] ] ;
11101133 let positions = self . gen_to_positions ( pos) ;
11111134 opponent_positions. extend ( positions) ;
11121135 }
0 commit comments