Add debug prints for promotion checking.

This commit is contained in:
yukirij 2024-08-18 18:30:45 -07:00
parent 5d5892c66f
commit e55a6cb258
3 changed files with 10 additions and 12 deletions

View File

@ -85,14 +85,14 @@ impl Board {
]; ];
for (piece, hex) in &layout { for (piece, hex) in &layout {
self.set_piece(piece.clone(), hex.tile()); self.set_piece(piece.clone(), hex.tile);
} }
for (piece, hex) in &layout { for (piece, hex) in &layout {
let mut piece = piece.clone(); let mut piece = piece.clone();
piece.player = 1; piece.player = 1;
let hex = Hex::from_hex(8 - hex.x(), 8 - hex.y()); let hex = Hex::from_hex(8 - hex.x, 8 - hex.y);
self.set_piece(piece, hex.tile()); self.set_piece(piece, hex.tile);
} }
} }

View File

@ -73,7 +73,8 @@ impl Game {
// Check for target promotion. // Check for target promotion.
let hex = Hex::from_tile(play.to); let hex = Hex::from_tile(play.to);
if !target.promoted && !Hex::is_back(hex.x(), hex.y(), target.player) { if !target.promoted && !Hex::is_back(hex.x, hex.y, target.player) {
println!("promotion {} {} ({}, {})", target.class, play.to, hex.x, hex.y);
target.promoted = true; target.promoted = true;
} }
} }
@ -101,7 +102,8 @@ impl Game {
// Check for piece promotion. // Check for piece promotion.
let hex = Hex::from_tile(play.from); let hex = Hex::from_tile(play.from);
if !piece.promoted && !Hex::is_back(hex.x(), hex.y(), piece.player) { if !piece.promoted && !Hex::is_back(hex.x, hex.y, piece.player) {
println!("promotion {} {} ({}, {})", piece.class, play.to, hex.x, hex.y);
if let Some(piece) = &mut self.board.pieces[pid as usize] { if let Some(piece) = &mut self.board.pieces[pid as usize] {
piece.promoted = true; piece.promoted = true;
} }

View File

@ -1,9 +1,9 @@
const ROWS :[u8; 10] = [ 0, 5, 11, 18, 26, 35, 43, 50, 56, 61 ]; const ROWS :[u8; 10] = [ 0, 5, 11, 18, 26, 35, 43, 50, 56, 61 ];
pub struct Hex { pub struct Hex {
x:u8, pub x:u8,
y:u8, pub y:u8,
tile:u8, pub tile:u8,
} }
impl Hex { impl Hex {
pub fn new() -> Self pub fn new() -> Self
@ -79,8 +79,4 @@ impl Hex {
y == COLUMNS[x as usize][1 ^ player as usize] y == COLUMNS[x as usize][1 ^ player as usize]
} else { false } } else { false }
} }
pub fn x(&self) -> u8 { self.x }
pub fn y(&self) -> u8 { self.y }
pub fn tile(&self) -> u8 { self.tile }
} }