pub fn file_of(s: Square) -> FileExpand description
Return the file of a square.
Examples found in repository?
examples/pawn_debug.rs (line 33)
7fn main() {
8 atomic_movegen::attacks::init();
9 let args: Vec<String> = env::args().collect();
10 if args.len() < 2 {
11 eprintln!("Usage: pawn_debug <fen>");
12 return;
13 }
14 let fen = &args[1];
15 let board = Board::from_fen(fen).expect("Invalid FEN");
16
17 println!("Board side to move: {:?}", board.side_to_move());
18
19 // Manual check: iterate all pawns
20 let us = board.side_to_move();
21 let _them = us.flip();
22 let _occupied = board.occupied();
23
24 let pawns = board.pieces_color_pt(us, PieceType::Pawn);
25 println!("Pawns ({:?}): {}", us, pawns.count());
26 let mut p = pawns;
27 while !p.is_empty() {
28 let sq = p.pop_lsb();
29 println!(
30 " Pawn at {} (idx={}): file={} rank={}",
31 sq_str(sq),
32 sq as u8,
33 file_of(sq) as u8,
34 rank_of(sq) as u8
35 );
36 }
37
38 // Check what generate_legal produces
39 let mut moves = MoveList::new();
40 movegen::generate_legal(&board, &mut moves);
41
42 // Find all h3g2 moves
43 let h3 = Square::from_index(23);
44 let g2 = Square::from_index(14);
45 println!("\nAll h3g2 moves:");
46 for (i, &m) in moves.as_slice().iter().enumerate() {
47 if m.from_sq() == h3 && m.to_sq() == g2 {
48 println!(
49 " Move #{}: from={} to={} type={:?}",
50 i,
51 sq_str(m.from_sq()),
52 sq_str(m.to_sq()),
53 m.move_type()
54 );
55 }
56 }
57
58 // Also check how many times each move appears
59 use std::collections::HashMap;
60 let mut counts: HashMap<(u16, u16, u16), usize> = HashMap::new();
61 for &m in moves.as_slice() {
62 *counts
63 .entry((m.from_sq() as u16, m.to_sq() as u16, m.move_type() as u16))
64 .or_insert(0) += 1;
65 }
66 for ((from, to, mt), count) in &counts {
67 if *count > 1 {
68 println!(
69 "DUPLICATE: {}{} type={:?} appears {} times",
70 sq_str(Square::from_u8(*from as u8)),
71 sq_str(Square::from_u8(*to as u8)),
72 match mt {
73 0 => "Normal",
74 1 => "Promo",
75 2 => "EP",
76 3 => "Castle",
77 _ => "?",
78 },
79 count
80 );
81 }
82 }
83}