aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/modules/ranking.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-08-26 19:21:30 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-08-26 19:21:30 +0200
commite26f13c8bba24e6f966888d5909f2803665c55a0 (patch)
tree6d156e0dd18d695103d00d12111ee26e73e8d3a0 /planetwars-server/src/modules/ranking.rs
parent624fa99fad0d41bfbd0f249ab054745a990a5d8c (diff)
downloadplanetwars.dev-e26f13c8bba24e6f966888d5909f2803665c55a0.tar.xz
planetwars.dev-e26f13c8bba24e6f966888d5909f2803665c55a0.zip
add maps to matches api
Diffstat (limited to 'planetwars-server/src/modules/ranking.rs')
-rw-r--r--planetwars-server/src/modules/ranking.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs
index dff3a72..7661b71 100644
--- a/planetwars-server/src/modules/ranking.rs
+++ b/planetwars-server/src/modules/ranking.rs
@@ -1,4 +1,5 @@
use crate::db::bots::BotVersion;
+use crate::db::maps::Map;
use crate::{db::bots::Bot, DbPool, GlobalConfig};
use crate::db;
@@ -15,6 +16,8 @@ use tokio;
const RANKER_INTERVAL: u64 = 60;
const RANKER_NUM_MATCHES: i64 = 10_000;
+const RANKER_MAP_NAME: &str = "hex";
+
pub async fn run_ranker(config: Arc<GlobalConfig>, db_pool: DbPool) {
// TODO: make this configurable
// play at most one match every n seconds
@@ -25,7 +28,7 @@ pub async fn run_ranker(config: Arc<GlobalConfig>, db_pool: DbPool) {
.expect("could not get database connection");
loop {
interval.tick().await;
- let bots = db::bots::all_active_bots_with_version(&db_conn).unwrap();
+ let bots = db::bots::all_active_bots_with_version(&db_conn).expect("could not load bots");
if bots.len() < 2 {
// not enough bots to play a match
continue;
@@ -34,13 +37,17 @@ pub async fn run_ranker(config: Arc<GlobalConfig>, db_pool: DbPool) {
let mut rng = &mut rand::thread_rng();
bots.choose_multiple(&mut rng, 2).cloned().collect()
};
- play_ranking_match(config.clone(), selected_bots, db_pool.clone()).await;
+
+ let map =
+ db::maps::find_map_by_name(RANKER_MAP_NAME, &db_conn).expect("could not load map");
+ play_ranking_match(config.clone(), map, selected_bots, db_pool.clone()).await;
recalculate_ratings(&db_conn).expect("could not recalculate ratings");
}
}
async fn play_ranking_match(
config: Arc<GlobalConfig>,
+ map: Map,
selected_bots: Vec<(Bot, BotVersion)>,
db_pool: DbPool,
) {
@@ -53,7 +60,7 @@ async fn play_ranking_match(
players.push(player);
}
- let (_, handle) = RunMatch::from_players(config, true, players)
+ let (_, handle) = RunMatch::new(config, true, map, players)
.run(db_pool.clone())
.await
.expect("failed to run match");