diff options
author | metamuffin <metamuffin@disroot.org> | 2024-08-11 19:22:29 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-08-11 19:22:29 +0200 |
commit | 98ac3be875a30ad97162949aa929c7363d0bf2b3 (patch) | |
tree | 028ab01c471ca4d13ab659a7d5b9fd3a45a03e90 /server/bot/src/main.rs | |
parent | 012fbc3e6382a92de60a191690000b0e83653cc6 (diff) | |
download | hurrycurry-98ac3be875a30ad97162949aa929c7363d0bf2b3.tar hurrycurry-98ac3be875a30ad97162949aa929c7363d0bf2b3.tar.bz2 hurrycurry-98ac3be875a30ad97162949aa929c7363d0bf2b3.tar.zst |
improve framework and start work on simple algo
Diffstat (limited to 'server/bot/src/main.rs')
-rw-r--r-- | server/bot/src/main.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs index 0e202894..08d17d19 100644 --- a/server/bot/src/main.rs +++ b/server/bot/src/main.rs @@ -20,6 +20,7 @@ pub mod algos; pub mod pathfinding; use anyhow::Result; +use clap::Parser; use hurrycurry_client_lib::{network::sync::Network, Game}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, @@ -38,17 +39,30 @@ pub trait BotAlgo { fn tick(&mut self, me: PlayerID, game: &Game, dt: f32) -> BotInput; } +#[derive(Parser)] +struct Args { + algo: String, + address: String, +} + fn main() -> Result<()> { env_logger::init_from_env("LOG"); rustls::crypto::ring::default_provider() .install_default() .unwrap(); - let mut network = Network::connect( - &std::env::args() - .nth(1) - .expect("usage: bot <websocket address>"), - )?; + let args = Args::parse(); + + let algo = args.algo.to_owned(); + let init_algo = move || -> Box<dyn BotAlgo> { + match algo.as_str() { + "test" => Box::new(algos::Test::default()), + "simple" => Box::new(algos::Simple::default()), + _ => panic!("unknown algo {algo:?}"), + } + }; + + let mut network = Network::connect(&args.address)?; let mut game = Game::default(); @@ -69,7 +83,7 @@ fn main() -> Result<()> { PacketC::Joined { id } => bots.push(BotDriver { id: *id, interacting: false, - state: Box::new(algos::test::Test::default()), + state: init_algo(), }), PacketC::Error { message } => { warn!("server error message: {message}"); |