diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-28 11:22:44 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-05-28 11:22:44 +0200 |
commit | 80c60ac69c9b0d86a4536eeac82cf266eb4430bc (patch) | |
tree | bc2ac0c803be27395c0297123f0794e1b8904676 /planetwars-matchrunner/src | |
parent | 643c0e7706ab927ef270e4a5b62ada0c38b651b9 (diff) | |
parent | fadcda850332f8adb0a4382da9f04f78db3f6d1a (diff) | |
download | planetwars.dev-80c60ac69c9b0d86a4536eeac82cf266eb4430bc.tar.xz planetwars.dev-80c60ac69c9b0d86a4536eeac82cf266eb4430bc.zip |
Merge branch 'feature/leaderboard'
Diffstat (limited to 'planetwars-matchrunner/src')
-rw-r--r-- | planetwars-matchrunner/src/lib.rs | 19 | ||||
-rw-r--r-- | planetwars-matchrunner/src/pw_match.rs | 6 |
2 files changed, 19 insertions, 6 deletions
diff --git a/planetwars-matchrunner/src/lib.rs b/planetwars-matchrunner/src/lib.rs index b7a9e53..5aff793 100644 --- a/planetwars-matchrunner/src/lib.rs +++ b/planetwars-matchrunner/src/lib.rs @@ -38,7 +38,6 @@ pub struct PlayerInfo { } pub struct MatchPlayer { - pub name: String, pub bot_spec: Box<dyn BotSpec>, } @@ -52,7 +51,11 @@ pub trait BotSpec: Send + Sync { ) -> Box<dyn PlayerHandle>; } -pub async fn run_match(config: MatchConfig) { +pub struct MatchOutcome { + pub winner: Option<usize>, +} + +pub async fn run_match(config: MatchConfig) -> MatchOutcome { let pw_config = PwConfig { map_file: config.map_path, max_turns: 100, @@ -103,8 +106,18 @@ pub async fn run_match(config: MatchConfig) { // ) // .unwrap(); - let match_state = pw_match::PwMatch::create(match_ctx, pw_config); + let mut match_state = pw_match::PwMatch::create(match_ctx, pw_config); match_state.run().await; + + let final_state = match_state.match_state.state(); + let survivors = final_state.living_players(); + let winner = if survivors.len() == 1 { + Some(survivors[0]) + } else { + None + }; + + MatchOutcome { winner } } // writing this as a closure causes lifetime inference errors diff --git a/planetwars-matchrunner/src/pw_match.rs b/planetwars-matchrunner/src/pw_match.rs index c9a7f7b..f5b803c 100644 --- a/planetwars-matchrunner/src/pw_match.rs +++ b/planetwars-matchrunner/src/pw_match.rs @@ -24,8 +24,8 @@ pub struct MatchConfig { } pub struct PwMatch { - match_ctx: MatchCtx, - match_state: PlanetWars, + pub match_ctx: MatchCtx, + pub match_state: PlanetWars, } impl PwMatch { @@ -39,7 +39,7 @@ impl PwMatch { } } - pub async fn run(mut self) { + pub async fn run(&mut self) { while !self.match_state.is_finished() { let player_messages = self.prompt_players().await; |