aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-01-01 12:10:02 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-01-01 12:10:02 +0100
commit4a077c7c65eced447c45389acf05007dd571bf26 (patch)
treef291c61c6164a58fb1d3ab66952d07d0b7e4609c
parente145947d052450618af3ba094e66a27c3c7f86e4 (diff)
downloadplanetwars.dev-4a077c7c65eced447c45389acf05007dd571bf26.tar.xz
planetwars.dev-4a077c7c65eced447c45389acf05007dd571bf26.zip
extract matchrunner crate from planetwars-cli
-rw-r--r--Cargo.toml1
-rw-r--r--planetwars-cli/Cargo.toml2
-rw-r--r--planetwars-cli/src/commands/run_match.rs8
-rw-r--r--planetwars-cli/src/lib.rs1
-rw-r--r--planetwars-cli/src/web/mod.rs3
-rw-r--r--planetwars-matchrunner/Cargo.toml16
-rw-r--r--planetwars-matchrunner/src/bot_runner.rs (renamed from planetwars-cli/src/match_runner/bot_runner.rs)0
-rw-r--r--planetwars-matchrunner/src/lib.rs (renamed from planetwars-cli/src/match_runner/mod.rs)9
-rw-r--r--planetwars-matchrunner/src/match_context.rs (renamed from planetwars-cli/src/match_runner/match_context.rs)0
-rw-r--r--planetwars-matchrunner/src/pw_match.rs (renamed from planetwars-cli/src/match_runner/pw_match.rs)0
10 files changed, 28 insertions, 12 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 35061a8..cebf247 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,6 +2,7 @@
members = [
"planetwars-rules",
+ "planetwars-matchrunner",
"planetwars-cli",
"planetwars-server",
]
diff --git a/planetwars-cli/Cargo.toml b/planetwars-cli/Cargo.toml
index e1f0a8e..972a02b 100644
--- a/planetwars-cli/Cargo.toml
+++ b/planetwars-cli/Cargo.toml
@@ -15,10 +15,10 @@ rand = "0.6"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.5"
-planetwars-rules = { path = "../planetwars-rules" }
clap = { version = "3.0.0-rc.8", features = ["derive"] }
chrono = { version = "0.4", features = ["serde"] }
shlex = "1.1"
+planetwars-matchrunner = { path = "../planetwars-matchrunner" }
rust-embed = "6.3.0"
axum = { version = "0.4", features = ["ws"] }
diff --git a/planetwars-cli/src/commands/run_match.rs b/planetwars-cli/src/commands/run_match.rs
index 868e87c..03868ae 100644
--- a/planetwars-cli/src/commands/run_match.rs
+++ b/planetwars-cli/src/commands/run_match.rs
@@ -1,9 +1,8 @@
use std::io;
use clap::Parser;
+use planetwars_matchrunner::{run_match, MatchConfig, MatchPlayer};
-use crate::match_runner::MatchConfig;
-use crate::match_runner::{self, MatchPlayer};
use crate::workspace::Workspace;
#[derive(Parser)]
pub struct RunMatchCommand {
@@ -26,7 +25,8 @@ impl RunMatchCommand {
let bot = workspace.get_bot(&bot_name)?;
players.push(MatchPlayer {
name: bot_name.clone(),
- bot,
+ path: bot.path.clone(),
+ argv: bot.config.get_run_argv(),
});
}
@@ -37,7 +37,7 @@ impl RunMatchCommand {
players,
};
- match_runner::run_match(match_config).await;
+ run_match(match_config).await;
println!("match completed successfully");
// TODO: maybe print the match result as well?
diff --git a/planetwars-cli/src/lib.rs b/planetwars-cli/src/lib.rs
index e5566b0..f67b67f 100644
--- a/planetwars-cli/src/lib.rs
+++ b/planetwars-cli/src/lib.rs
@@ -1,5 +1,4 @@
mod commands;
-mod match_runner;
mod web;
mod workspace;
diff --git a/planetwars-cli/src/web/mod.rs b/planetwars-cli/src/web/mod.rs
index a0e452e..f66b0c6 100644
--- a/planetwars-cli/src/web/mod.rs
+++ b/planetwars-cli/src/web/mod.rs
@@ -8,6 +8,7 @@ use axum::{
AddExtensionLayer, Json,
};
use mime_guess;
+use planetwars_matchrunner::MatchMeta;
use rust_embed::RustEmbed;
use serde::{Deserialize, Serialize};
use std::{
@@ -18,7 +19,7 @@ use std::{
sync::Arc,
};
-use crate::{match_runner::MatchMeta, workspace::Workspace};
+use crate::workspace::Workspace;
struct State {
workspace: Workspace,
diff --git a/planetwars-matchrunner/Cargo.toml b/planetwars-matchrunner/Cargo.toml
new file mode 100644
index 0000000..da05f13
--- /dev/null
+++ b/planetwars-matchrunner/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "planetwars-matchrunner"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+futures-core = "0.3"
+futures = "0.3"
+tokio = { version = "1", features = ["full"] }
+rand = "0.6"
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
+planetwars-rules = { path = "../planetwars-rules" }
+chrono = { version = "0.4", features = ["serde"] } \ No newline at end of file
diff --git a/planetwars-cli/src/match_runner/bot_runner.rs b/planetwars-matchrunner/src/bot_runner.rs
index 70fc060..70fc060 100644
--- a/planetwars-cli/src/match_runner/bot_runner.rs
+++ b/planetwars-matchrunner/src/bot_runner.rs
diff --git a/planetwars-cli/src/match_runner/mod.rs b/planetwars-matchrunner/src/lib.rs
index fdd02d5..50c6518 100644
--- a/planetwars-cli/src/match_runner/mod.rs
+++ b/planetwars-matchrunner/src/lib.rs
@@ -12,8 +12,6 @@ use match_context::MatchCtx;
use planetwars_rules::PwConfig;
use serde::{Deserialize, Serialize};
-use crate::workspace::bot::WorkspaceBot;
-
use self::match_context::{EventBus, PlayerHandle};
pub struct MatchConfig {
@@ -37,7 +35,8 @@ pub struct PlayerInfo {
pub struct MatchPlayer {
pub name: String,
- pub bot: WorkspaceBot,
+ pub path: PathBuf,
+ pub argv: Vec<String>,
}
pub async fn run_match(config: MatchConfig) {
@@ -56,8 +55,8 @@ pub async fn run_match(config: MatchConfig) {
.map(|(player_id, player)| {
let player_id = (player_id + 1) as u32;
let bot = bot_runner::Bot {
- working_dir: player.bot.path.clone(),
- argv: player.bot.config.get_run_argv(),
+ working_dir: player.path.clone(),
+ argv: player.argv.clone(),
};
let handle = bot_runner::run_local_bot(player_id, event_bus.clone(), bot);
(player_id, Box::new(handle) as Box<dyn PlayerHandle>)
diff --git a/planetwars-cli/src/match_runner/match_context.rs b/planetwars-matchrunner/src/match_context.rs
index 466da13..466da13 100644
--- a/planetwars-cli/src/match_runner/match_context.rs
+++ b/planetwars-matchrunner/src/match_context.rs
diff --git a/planetwars-cli/src/match_runner/pw_match.rs b/planetwars-matchrunner/src/pw_match.rs
index 42bc9d2..42bc9d2 100644
--- a/planetwars-cli/src/match_runner/pw_match.rs
+++ b/planetwars-matchrunner/src/pw_match.rs