diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-23 23:40:25 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-23 23:40:25 +0200 |
commit | 4a582e8079178a7ac11f2a492e7988fcdaa210cd (patch) | |
tree | 1403b3e409e184bb53e0349d7e68e673fe7d7b3c /planetwars-server/src/modules/ranking.rs | |
parent | f19a70e710b8bf4605625516aa7e4c0cc7ace2e4 (diff) | |
download | planetwars.dev-4a582e8079178a7ac11f2a492e7988fcdaa210cd.tar.xz planetwars.dev-4a582e8079178a7ac11f2a492e7988fcdaa210cd.zip |
store active version id in bots table
Diffstat (limited to 'planetwars-server/src/modules/ranking.rs')
-rw-r--r-- | planetwars-server/src/modules/ranking.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/planetwars-server/src/modules/ranking.rs b/planetwars-server/src/modules/ranking.rs index a9f6419..d508d6c 100644 --- a/planetwars-server/src/modules/ranking.rs +++ b/planetwars-server/src/modules/ranking.rs @@ -1,3 +1,4 @@ +use crate::db::bots::BotVersion; use crate::{db::bots::Bot, DbPool, GlobalConfig}; use crate::db; @@ -22,12 +23,12 @@ 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::find_all_bots(&db_conn).unwrap(); + let bots = db::bots::all_active_bots_with_version(&db_conn).unwrap(); if bots.len() < 2 { // not enough bots to play a match continue; } - let selected_bots: Vec<Bot> = { + let selected_bots: Vec<(Bot, BotVersion)> = { let mut rng = &mut rand::thread_rng(); bots.choose_multiple(&mut rng, 2).cloned().collect() }; @@ -36,15 +37,16 @@ pub async fn run_ranker(config: Arc<GlobalConfig>, db_pool: DbPool) { } } -async fn play_ranking_match(config: Arc<GlobalConfig>, selected_bots: Vec<Bot>, db_pool: DbPool) { - let db_conn = db_pool.get().await.expect("could not get db pool"); +async fn play_ranking_match( + config: Arc<GlobalConfig>, + selected_bots: Vec<(Bot, BotVersion)>, + db_pool: DbPool, +) { let mut players = Vec::new(); - for bot in &selected_bots { - let version = db::bots::active_bot_version(bot.id, &db_conn) - .expect("could not get active bot version"); + for (bot, bot_version) in selected_bots { let player = MatchPlayer::BotVersion { - bot: Some(bot.clone()), - version, + bot: Some(bot), + version: bot_version, }; players.push(player); } |