aboutsummaryrefslogtreecommitdiff
path: root/planetwars-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-client/src')
-rw-r--r--planetwars-client/src/main.rs24
1 files changed, 18 insertions, 6 deletions
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<pb::CreatedMatch, Status> {
+async fn create_match(channel: Channel, opponent_name: String) -> Result<pb::CreatedMatch, Status> {
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())
}