Make output optional
This commit is contained in:
parent
fad9798aed
commit
ecec35b20f
3 changed files with 28 additions and 16 deletions
|
|
@ -9,7 +9,7 @@ fn compare(player_builders: &[Box<dyn PlayerBuilder>], games: usize) {
|
|||
let r = (0..games)
|
||||
.into_par_iter()
|
||||
.map_init(SmallRng::from_entropy, |rng, _| {
|
||||
herzen(player_builders, 0, rng)
|
||||
herzen::<false>(player_builders, 0, rng)
|
||||
})
|
||||
.fold(
|
||||
|| vec![[0_u64; 13]; player_builders.len()],
|
||||
|
|
@ -48,11 +48,11 @@ fn compare(player_builders: &[Box<dyn PlayerBuilder>], games: usize) {
|
|||
|
||||
fn main() {
|
||||
let player: Vec<Box<dyn PlayerBuilder>> = vec![
|
||||
Box::new(player::random::Random { seed: 0 }),
|
||||
Box::new(player::random::Random { seed: 0 }),
|
||||
Box::new(player::random::Random { seed: 0 }),
|
||||
Box::new(player::random::Random { seed: 0 }),
|
||||
Box::new(player::highest::Highest {}),
|
||||
Box::new(player::highest::Highest {}),
|
||||
Box::new(player::highest::Highest {}),
|
||||
Box::new(player::highest::Highest {}),
|
||||
];
|
||||
|
||||
compare(&player, 10000);
|
||||
compare(&player, 10000000);
|
||||
}
|
||||
|
|
|
|||
30
src/game.rs
30
src/game.rs
|
|
@ -89,7 +89,7 @@ pub fn playeble(card: Card, hand: &[Card], stack_color: Option<Color>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn herzen(
|
||||
pub fn herzen<const OUTPUT: bool>(
|
||||
player_builders: &[Box<dyn PlayerBuilder>],
|
||||
starting_player: usize,
|
||||
rng: &mut impl Rng,
|
||||
|
|
@ -125,12 +125,16 @@ pub fn herzen(
|
|||
for i in 0..hand_size {
|
||||
let mut stack = Vec::with_capacity(player.len());
|
||||
|
||||
println!("## Round {i}:");
|
||||
if OUTPUT {
|
||||
println!("## Round {i}:");
|
||||
}
|
||||
|
||||
for j in 0..player.len() {
|
||||
let index = (round_starting_player + j) % player.len();
|
||||
|
||||
println!("# Player {index}");
|
||||
if OUTPUT {
|
||||
println!("# Player {index}");
|
||||
}
|
||||
|
||||
let ai = AdditionalInformation {};
|
||||
|
||||
|
|
@ -146,7 +150,9 @@ pub fn herzen(
|
|||
|
||||
hands[index].remove(card_index);
|
||||
|
||||
println!("# Player {index} played {played_card:?}");
|
||||
if OUTPUT {
|
||||
println!("# Player {index} played {played_card:?}");
|
||||
}
|
||||
stack.push(played_card);
|
||||
}
|
||||
|
||||
|
|
@ -166,9 +172,11 @@ pub fn herzen(
|
|||
|
||||
let cost = stack.iter().map(|c| c.cost()).sum::<u8>();
|
||||
|
||||
println!(
|
||||
"## Player {winner} takes the stack {stack:?} with {winning_card:?}, {cost} points"
|
||||
);
|
||||
if OUTPUT {
|
||||
println!(
|
||||
"## Player {winner} takes the stack {stack:?} with {winning_card:?}, {cost} points"
|
||||
);
|
||||
}
|
||||
|
||||
points[winner] += cost;
|
||||
|
||||
|
|
@ -178,13 +186,17 @@ pub fn herzen(
|
|||
let remainder = &full_deck[hand_size * player.len()..];
|
||||
let remainder_cost = remainder.iter().map(|c| c.cost()).sum::<u8>();
|
||||
|
||||
println!(
|
||||
if OUTPUT {
|
||||
println!(
|
||||
"## Player {round_starting_player} takes the remaining cards {remainder:?}, {remainder_cost} points"
|
||||
);
|
||||
}
|
||||
|
||||
points[round_starting_player] += remainder_cost;
|
||||
|
||||
println!("## Game ended. Points: {points:?}");
|
||||
if OUTPUT {
|
||||
println!("## Game ended. Points: {points:?}");
|
||||
}
|
||||
|
||||
points
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,5 +130,5 @@ fn main() {
|
|||
|
||||
let mut rng = SmallRng::from_entropy();
|
||||
|
||||
game::herzen(&player, 0, &mut rng);
|
||||
game::herzen::<true>(&player, 0, &mut rng);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue