diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-03-13 15:20:03 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-03-13 15:20:03 +0100 |
commit | fd52e266c6e25999a49c36f17342977b759a2612 (patch) | |
tree | 9c727cac949c9698343d003ee87cfe73c6c6204a /planetwars-matchrunner/src | |
parent | f7655005ff099e8314ecd31e95b26ad74d4efd02 (diff) | |
download | planetwars.dev-fd52e266c6e25999a49c36f17342977b759a2612.tar.xz planetwars.dev-fd52e266c6e25999a49c36f17342977b759a2612.zip |
apply clippy suggestions
Diffstat (limited to 'planetwars-matchrunner/src')
-rw-r--r-- | planetwars-matchrunner/src/bin/testmatch.rs | 25 | ||||
-rw-r--r-- | planetwars-matchrunner/src/bot_runner.rs | 6 | ||||
-rw-r--r-- | planetwars-matchrunner/src/lib.rs | 4 | ||||
-rw-r--r-- | planetwars-matchrunner/src/match_context.rs | 14 | ||||
-rw-r--r-- | planetwars-matchrunner/src/match_log.rs | 2 | ||||
-rw-r--r-- | planetwars-matchrunner/src/pw_match.rs | 4 |
6 files changed, 33 insertions, 22 deletions
diff --git a/planetwars-matchrunner/src/bin/testmatch.rs b/planetwars-matchrunner/src/bin/testmatch.rs index db160cf..4a9d10e 100644 --- a/planetwars-matchrunner/src/bin/testmatch.rs +++ b/planetwars-matchrunner/src/bin/testmatch.rs @@ -10,16 +10,9 @@ async fn main() { _run_match(map_path).await; } -const IMAGE: &'static str = "python:3.10-slim-buster"; +const IMAGE: &str = "python:3.10-slim-buster"; async fn _run_match(map_path: String) { - let code_dir_path = PathBuf::from("../simplebot"); - let bot_spec = DockerBotSpec { - image: IMAGE.to_string(), - code_path: code_dir_path, - argv: vec!["python".to_string(), "simplebot.py".to_string()], - }; - run_match(MatchConfig { map_path: PathBuf::from(map_path), map_name: "hex".to_string(), @@ -27,13 +20,25 @@ async fn _run_match(map_path: String) { players: vec![ MatchPlayer { name: "a".to_string(), - bot_spec: Box::new(bot_spec.clone()), + bot_spec: Box::new(DockerBotSpec { + image: IMAGE.to_string(), + // code_path: PathBuf::from("../simplebot"), + code_path: PathBuf::from("./bots/simplebot"), + argv: vec!["python".to_string(), "simplebot.py".to_string()], + }), }, MatchPlayer { name: "b".to_string(), - bot_spec: Box::new(bot_spec.clone()), + bot_spec: Box::new(DockerBotSpec { + image: IMAGE.to_string(), + code_path: PathBuf::from("./bots/broken_bot"), + argv: vec!["python".to_string(), "bot.py".to_string()], + }), }, ], }) .await; + + // TODO: use a joinhandle to wait for the logger to finish + tokio::time::sleep(std::time::Duration::from_secs(1)).await; } diff --git a/planetwars-matchrunner/src/bot_runner.rs b/planetwars-matchrunner/src/bot_runner.rs index adb5907..d40a133 100644 --- a/planetwars-matchrunner/src/bot_runner.rs +++ b/planetwars-matchrunner/src/bot_runner.rs @@ -35,7 +35,7 @@ pub fn run_local_bot(player_id: u32, event_bus: Arc<Mutex<EventBus>>, bot: Bot) }; tokio::spawn(runner.run()); - return LocalBotHandle { tx }; + LocalBotHandle { tx } } pub struct LocalBotRunner { @@ -90,11 +90,11 @@ impl Bot { let stdout = child.stdout.take().unwrap(); let reader = BufReader::new(stdout).lines(); - return BotProcess { + BotProcess { stdin: child.stdin.take().unwrap(), stdout: reader, child, - }; + } } } diff --git a/planetwars-matchrunner/src/lib.rs b/planetwars-matchrunner/src/lib.rs index 0be0b3d..b7a9e53 100644 --- a/planetwars-matchrunner/src/lib.rs +++ b/planetwars-matchrunner/src/lib.rs @@ -72,7 +72,7 @@ pub async fn run_match(config: MatchConfig) { start_bot( player_id, event_bus.clone(), - &player.bot_spec, + player.bot_spec.as_ref(), match_logger.clone(), ) }) @@ -111,7 +111,7 @@ pub async fn run_match(config: MatchConfig) { async fn start_bot( player_id: u32, event_bus: Arc<Mutex<EventBus>>, - bot_spec: &Box<dyn BotSpec>, + bot_spec: &dyn BotSpec, match_logger: MatchLogger, ) -> (u32, Box<dyn PlayerHandle>) { let player_handle = bot_spec.run_bot(player_id, event_bus, match_logger).await; diff --git a/planetwars-matchrunner/src/match_context.rs b/planetwars-matchrunner/src/match_context.rs index 6ea60c3..1dac09b 100644 --- a/planetwars-matchrunner/src/match_context.rs +++ b/planetwars-matchrunner/src/match_context.rs @@ -57,11 +57,11 @@ impl MatchCtx { timeout, }); - return Request { + Request { player_id, request_id, event_bus: self.event_bus.clone(), - }; + } } pub fn players(&self) -> Vec<u32> { @@ -97,6 +97,12 @@ impl EventBus { } } +impl Default for EventBus { + fn default() -> Self { + EventBus::new() + } +} + impl EventBus { pub fn resolve_request(&mut self, id: RequestId, result: RequestResult<Vec<u8>>) { if self.request_responses.contains_key(&id) { @@ -138,9 +144,9 @@ impl Future for Request { event_bus .wakers .entry(request_id) - .or_insert_with(|| AtomicWaker::new()) + .or_insert_with(AtomicWaker::new) .register(cx.waker()); - return Poll::Pending; + Poll::Pending } } diff --git a/planetwars-matchrunner/src/match_log.rs b/planetwars-matchrunner/src/match_log.rs index 9991f99..30751fd 100644 --- a/planetwars-matchrunner/src/match_log.rs +++ b/planetwars-matchrunner/src/match_log.rs @@ -29,7 +29,7 @@ pub async fn create_log_sink(log_file_path: &Path) -> MatchLogger { .await .expect("Could not create log file"); tokio::spawn(run_log_sink(rx, log_file)); - return tx; + tx } async fn run_log_sink(mut rx: mpsc::UnboundedReceiver<MatchLogMessage>, mut file: File) { diff --git a/planetwars-matchrunner/src/pw_match.rs b/planetwars-matchrunner/src/pw_match.rs index c114d78..c9a7f7b 100644 --- a/planetwars-matchrunner/src/pw_match.rs +++ b/planetwars-matchrunner/src/pw_match.rs @@ -74,7 +74,7 @@ impl PwMatch { .iter() .filter(|p| p.alive) .map(move |player| { - let state_for_player = pw_serializer::serialize_rotated(&state, player.id - 1); + let state_for_player = pw_serializer::serialize_rotated(state, player.id - 1); match_ctx .request( player.id.try_into().unwrap(), @@ -115,7 +115,7 @@ impl PwMatch { }) .collect(); - return proto::PlayerAction::Commands(commands); + proto::PlayerAction::Commands(commands) } } |