fix: returning empty vector when there was no captures available

This commit is contained in:
2026-08-14 17:02:52 +02:00
parent b1b82cc1e5
commit 2e26c45e10
2 changed files with 20 additions and 4 deletions

View File

@@ -348,7 +348,11 @@ impl Board {
capturing_pawn,
);
Some(available_captures)
if available_captures.is_empty() {
None
} else {
Some(available_captures)
}
}
pub fn capture(&mut self, path: &CapturePath, capturing_player: &Player) -> bool {

View File

@@ -160,10 +160,8 @@ mod tests {
use log::info;
use rand::seq::IndexedMutRandom;
use rand::seq::IndexedRandom;
use rand::seq::SliceRandom;
#[test]
fn test_game_flow() {
fn run_game() {
let mut master: GameMaster = GameMaster::new("Morbius".to_string(), "Milo".to_string());
let mut turns = 0;
let max_turns = 2000;
@@ -200,9 +198,23 @@ mod tests {
master.move_pawn(from, *to);
turns += 1;
continue;
}
panic!("Test should never come to this place!");
}
assert!(turns < max_turns);
}
#[test]
fn test_game_flow() {
// random amount i pulled straight out of my ass
let game_amount = 100;
for game_number in 0..game_amount {
info!("Running game number: {}", game_number);
run_game();
}
}
}