From 450d22758ec169ece8f71bc6bd6c79603c136874 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 27 Apr 2022 20:08:48 +0200 Subject: return winner when running a match --- planetwars-matchrunner/src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'planetwars-matchrunner/src/lib.rs') diff --git a/planetwars-matchrunner/src/lib.rs b/planetwars-matchrunner/src/lib.rs index b7a9e53..1f1a4c7 100644 --- a/planetwars-matchrunner/src/lib.rs +++ b/planetwars-matchrunner/src/lib.rs @@ -52,7 +52,11 @@ pub trait BotSpec: Send + Sync { ) -> Box; } -pub async fn run_match(config: MatchConfig) { +pub struct MatchOutcome { + pub winner: Option, +} + +pub async fn run_match(config: MatchConfig) -> MatchOutcome { let pw_config = PwConfig { map_file: config.map_path, max_turns: 100, @@ -103,8 +107,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 -- cgit v1.2.3 From 7b142554d808a494df4ba9e616c58861370ccd93 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Thu, 28 Apr 2022 21:31:49 +0200 Subject: move match running logic to separate module --- planetwars-matchrunner/src/lib.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'planetwars-matchrunner/src/lib.rs') diff --git a/planetwars-matchrunner/src/lib.rs b/planetwars-matchrunner/src/lib.rs index 1f1a4c7..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, } -- cgit v1.2.3