From 2aab23c40f663a28fb361d6a7976493cb7bb5ea8 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 28 Aug 2022 17:12:07 +0200 Subject: [PATCH] run ranker on all maps --- planetwars-server/src/modules/ranking.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index 7661b71..90c4a56 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -16,8 +16,6 @@ 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, db_pool: DbPool) { // TODO: make this configurable // play at most one match every n seconds @@ -33,13 +31,18 @@ pub async fn run_ranker(config: Arc, db_pool: DbPool) { // not enough bots to play a match continue; } - let selected_bots: Vec<(Bot, BotVersion)> = { - let mut rng = &mut rand::thread_rng(); - bots.choose_multiple(&mut rng, 2).cloned().collect() + + let selected_bots: Vec<(Bot, BotVersion)> = bots + .choose_multiple(&mut rand::thread_rng(), 2) + .cloned() + .collect(); + + let maps = db::maps::list_maps(&db_conn).expect("could not load map"); + let map = match maps.choose(&mut rand::thread_rng()).cloned() { + None => continue, // no maps available + Some(map) => map, }; - 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"); }