From b0725c21df3d7a2b63d0d9ea7af6ec393fb66ad1 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Fri, 22 Jul 2022 22:27:12 +0200 Subject: planetwars-client: configure bot config path and opponent name --- planetwars-client/src/main.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'planetwars-client/src/main.rs') diff --git a/planetwars-client/src/main.rs b/planetwars-client/src/main.rs index 30397a5..cafb956 100644 --- a/planetwars-client/src/main.rs +++ b/planetwars-client/src/main.rs @@ -2,6 +2,7 @@ pub mod pb { tonic::include_proto!("grpc.planetwars.bot_api"); } +use clap::Parser; use pb::bot_api_service_client::BotApiServiceClient; use planetwars_matchrunner::bot_runner::Bot; use serde::Deserialize; @@ -10,6 +11,15 @@ use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; use tonic::{metadata::MetadataValue, transport::Channel, Request, Status}; +#[derive(clap::Parser)] +struct PlayMatch { + #[clap(value_parser)] + bot_config_path: String, + + #[clap(value_parser)] + opponent_name: String, +} + #[derive(Deserialize)] struct BotConfig { #[allow(dead_code)] @@ -19,7 +29,9 @@ struct BotConfig { #[tokio::main] async fn main() { - let content = std::fs::read_to_string("simplebot.toml").unwrap(); + let play_match = PlayMatch::parse(); + + let content = std::fs::read_to_string(play_match.bot_config_path).unwrap(); let bot_config: BotConfig = toml::from_str(&content).unwrap(); let channel = Channel::from_static("http://localhost:50051") @@ -27,7 +39,9 @@ async fn main() { .await .unwrap(); - let created_match = create_match(channel.clone()).await.unwrap(); + let created_match = create_match(channel.clone(), play_match.opponent_name) + .await + .unwrap(); run_player(bot_config, created_match.player_key, channel).await; println!( "Match completed. Watch the replay at {}", @@ -36,12 +50,10 @@ async fn main() { tokio::time::sleep(Duration::from_secs(1)).await; } -async fn create_match(channel: Channel) -> Result { +async fn create_match(channel: Channel, opponent_name: String) -> Result { let mut client = BotApiServiceClient::new(channel); let res = client - .create_match(Request::new(pb::MatchRequest { - opponent_name: "simplebot".to_string(), - })) + .create_match(Request::new(pb::MatchRequest { opponent_name })) .await; res.map(|response| response.into_inner()) } -- cgit v1.2.3