diff options
Diffstat (limited to 'planetwars-server/src/modules/ranking.rs')
-rw-r--r-- | planetwars-server/src/modules/ranking.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index cb699fe..90c4a56 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; @@ -25,22 +26,31 @@ 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; } - 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, }; - play_ranking_match(config.clone(), selected_bots, db_pool.clone()).await; + + 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 +63,7 @@ async fn play_ranking_match( players.push(player); } - let (_, handle) = RunMatch::from_players(config, players) + let (_, handle) = RunMatch::new(config, true, map, players) .run(db_pool.clone()) .await .expect("failed to run match"); |