extract matchrunner crate from planetwars-cli

This commit is contained in:
Ilion Beyst 2022-01-01 12:10:02 +01:00
parent e145947d05
commit 4a077c7c65
10 changed files with 28 additions and 12 deletions

View file

@ -2,6 +2,7 @@
members = [
"planetwars-rules",
"planetwars-matchrunner",
"planetwars-cli",
"planetwars-server",
]

View file

@ -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"] }

View file

@ -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?

View file

@ -1,5 +1,4 @@
mod commands;
mod match_runner;
mod web;
mod workspace;

View file

@ -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,

View file

@ -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"] }

View file

@ -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>)