use crate::bitboard::BitBoard;
use crate::game::pieces::{Color, FILE_A, FILE_B, FILE_G, FILE_H};
use crate::game::position::Position;
use crate::game::Board;
const KNIGHT_MOVES: [BitBoard; 64] = compile_knight_moves();
pub fn get_knight_moves(board: &Board, color: Color, origin: Position) -> BitBoard {
let side = board.get_side(color);
let own_pieces = &side.pieces;
let grid = &KNIGHT_MOVES[origin.to_int() as usize];
grid & !own_pieces
}
const fn compile_knight_moves() -> [BitBoard; 64] {
let mut moves: [BitBoard; 64] = [BitBoard(0); 64];
let mut i = 0usize;
loop {
let center = 1u64 << i;
moves[i].0 |= (center << 17) & !FILE_A.0;
moves[i].0 |= (center << 10) & !FILE_A.0 & !FILE_B.0;
moves[i].0 |= (center >> 6) & !FILE_A.0 & !FILE_B.0;
moves[i].0 |= (center >> 15) & !FILE_A.0;
moves[i].0 |= (center >> 17) & !FILE_H.0;
moves[i].0 |= (center >> 10) & !FILE_H.0 & !FILE_G.0;
moves[i].0 |= (center << 6) & !FILE_H.0 & !FILE_G.0;
moves[i].0 |= (center << 15) & !FILE_H.0;
i += 1;
if i == 64 {
break;
}
}
moves
}