Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn gen_magic_table(pos: (u8, u8), orthogonal: bool) -> ArrayVec<u64, 4096> {
- let (x, y) = pos;
- let mut range_board = if orthogonal { gen_straight(x, y) } else { gen_diagonal(x, y) };
- // remove redundant ranks and files
- if x != 0 {
- range_board &= !column_left;
- }
- if x != 7 {
- range_board &= !(column_left >> 7);
- }
- if y != 0 {
- range_board &= !row_top;
- }
- if y != 7 {
- range_board &= !(row_top >> 56);
- }
- let mut table_sz: usize = 12;
- if x == 0 || x == 7 {
- table_sz -= 1;
- }
- if y == 0 || y == 7 {
- table_sz -= 1;
- }
- // store positions of each bit from the range board
- // which are going to be toggling
- let mut bit_positions = ArrayVec::<u32, 12>::new();
- while range_board != 0 {
- let next_pos = range_board.trailing_zeros();
- bit_positions.push(next_pos);
- range_board &= !(1u64 << next_pos);
- }
- // 1024, 2048, or 4096 permutations of rays
- for i in 0..2u64.pow(table_sz as u32) {
- // generate permutation of blockers along ray
- let mut blocker_board: u64 = 0;
- for j in 0..table_sz {
- blocker_board ^= (i & (1u64 << j)) << (bit_positions[j]);
- }
- }
- ArrayVec::new()
- }
Advertisement
Add Comment
Please, Sign In to add comment