aboutsummaryrefslogtreecommitdiff
path: root/planetwars-matchrunner
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-01-23 13:23:23 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-01-23 13:23:23 +0100
commita79b338e90db1948f6587ab02e149e73bb1842f0 (patch)
tree42e0e3d5458f7cef76514960e4ff0de872c11646 /planetwars-matchrunner
parentf62196d983c04a94b892086a4ea6926bd7b6e4fb (diff)
downloadplanetwars.dev-a79b338e90db1948f6587ab02e149e73bb1842f0.tar.xz
planetwars.dev-a79b338e90db1948f6587ab02e149e73bb1842f0.zip
run all bots in python docker for now
Diffstat (limited to 'planetwars-matchrunner')
-rw-r--r--planetwars-matchrunner/src/lib.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/planetwars-matchrunner/src/lib.rs b/planetwars-matchrunner/src/lib.rs
index 2e4200c..7eff489 100644
--- a/planetwars-matchrunner/src/lib.rs
+++ b/planetwars-matchrunner/src/lib.rs
@@ -42,7 +42,7 @@ pub struct MatchPlayer {
}
#[async_trait]
-pub trait BotSpec {
+pub trait BotSpec : Send + Sync{
async fn run_bot(
&self,
player_id: u32,
@@ -66,10 +66,7 @@ pub async fn run_match(config: MatchConfig) {
.enumerate()
.map(|(player_id, player)| {
let player_id = (player_id + 1) as u32;
- player
- .bot_spec
- .run_bot(player_id, event_bus.clone())
- .map(move |handle| (player_id, handle))
+ start_bot(player_id, event_bus.clone(), &player.bot_spec)
})
.collect::<FuturesOrdered<_>>()
// await all results
@@ -101,3 +98,13 @@ pub async fn run_match(config: MatchConfig) {
let match_state = pw_match::PwMatch::create(match_ctx, pw_config);
match_state.run().await;
}
+
+// writing this as a closure causes lifetime inference errors
+async fn start_bot(
+ player_id: u32,
+ event_bus: Arc<Mutex<EventBus>>,
+ bot_spec: &Box<dyn BotSpec>,
+) -> (u32, Box<dyn PlayerHandle>) {
+ let player_handle = bot_spec.run_bot(player_id, event_bus).await;
+ (player_id, player_handle)
+}