]> git.scottworley.com Git - pluta-lesnura/commitdiff
Composable strategies
authorScott Worley <scottworley@scottworley.com>
Tue, 18 Jul 2023 19:41:26 +0000 (12:41 -0700)
committerScott Worley <scottworley@scottworley.com>
Tue, 18 Jul 2023 19:41:26 +0000 (12:41 -0700)
src/lib.rs
src/main.rs

index 1ee5f0bfe5fe2fc76bc54bcd13043fd46e4fc961..8f7949a57de7ea2cb4e343c4b4b7c997d36fec53 100644 (file)
@@ -440,10 +440,9 @@ pub fn random_player(draw_chance: f64) -> Player {
     }))
 }
 
-/// When available, make plays that grant momentum.  Otherwise, play randomly.
+/// When available, make plays that grant momentum.
 #[must_use]
-pub fn momentum_player(draw_chance: f64) -> Player {
-    let mut fallback = random_player(draw_chance);
+pub fn momentum_player(mut fallback: Player) -> Player {
     Player(Box::new(move |game: &Game| -> Play {
         match (&game.phase, game.discard.top().and_then(Card::suit)) {
             (Phase::Play, Some(suit)) => {
index c7d55335d490654c2fb3bbaff2d3494bfb65e03a..31d95878815930d663acefc8ddbd74ff73144677 100644 (file)
@@ -45,7 +45,7 @@ fn main() -> Result<(), &'static str> {
         }) => {
             let player = || match strategy {
                 Strategy::Random => random_player(*draw_chance),
-                Strategy::Momentum => momentum_player(*draw_chance),
+                Strategy::Momentum => momentum_player(random_player(*draw_chance)),
             };
             for _ in 0..*num_games {
                 let players: Vec<_> = std::iter::from_fn(|| Some(player()))