mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
fix: returning empty vector when there was no captures available
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user