From c43fc4e924afb6d546f3fef046aebbdfa3ef7944 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 15 May 2023 06:13:01 -0400 Subject: [PATCH] GP: New difficulty increase algorithm Before, it did level up based on how much the status quo was messed up (if a loser bot got pushed in front, or a rival bot got pushed ahead). Now, bots will additionally level up based on the best of the 4 players' overall performance, and the performance of the human player that beat them. This means that back of the pack bots will level up more often and the rival won't level up if you place poorly. The new formula ensures ALL bots are guaranteed at least 1 level up if you come in first place, whereas the old formula had a decent chance of not leveling up some bots. However, loser Chao getting boosted from 12th into 1st, or your rival getting sent to 7th, will still wildly piss them off :B --- src/k_grandprix.c | 86 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/src/k_grandprix.c b/src/k_grandprix.c index 52c82d7a3..6b19b8f06 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -469,8 +469,22 @@ static UINT8 K_BotExpectedStanding(player_t *bot) --------------------------------------------------*/ void K_IncreaseBotDifficulty(player_t *bot) { - UINT8 expectedstanding; - INT16 standingdiff; + UINT8 playerCount = 0; + UINT8 wonCount = 0; + + UINT8 humanThatBeatUs = 0; + INT16 beatenDelta = 0; + + UINT8 winnerHuman = UINT8_MAX; + INT16 winnerDelta = 0; + + UINT8 statusQuo = 1; + INT16 disruptDelta = 0; + + INT16 increase = 1; + size_t i = SIZE_MAX; + + bot->botvars.diffincrease = 0; if (bot->botvars.difficulty >= MAXBOTDIFFICULTY) { @@ -478,33 +492,65 @@ void K_IncreaseBotDifficulty(player_t *bot) return; } - // Increment bot difficulty based on what position you were meant to come in! - expectedstanding = K_BotExpectedStanding(bot); - standingdiff = expectedstanding - bot->position; + // Increment bot difficulty based on + // how much they were beaten by a player! - if (standingdiff >= -2) + // Find the worst-placing player that still beat us. + for (i = 0; i < MAXPLAYERS; i++) { - UINT8 increase; + player_t *other = NULL; - if (standingdiff > 5) + if (playeringame[i] == false) { - increase = 3; - } - else if (standingdiff > 2) - { - increase = 2; - } - else - { - increase = 1; + continue; } - bot->botvars.diffincrease = increase; + other = &players[i]; + if (other->spectator == true) + { + continue; + } + + playerCount++; + if (other->bot == true) + { + continue; + } + + if (other->position <= bot->position && other->position > humanThatBeatUs) + { + humanThatBeatUs = other->position; + } + + if (other->position < winnerHuman) + { + winnerHuman = other->position; + } } - else + + wonCount = playerCount / 2; + if (playerCount & 1) { - bot->botvars.diffincrease = 0; + // Round up + wonCount++; } + + statusQuo = K_BotExpectedStanding(bot); + + // How many levels they gain depends on how hard they beat us, + // and how much the status quo was disturbed. + beatenDelta = bot->position - humanThatBeatUs; + winnerDelta = wonCount - winnerHuman; + disruptDelta = abs(statusQuo - bot->position); + + increase = (beatenDelta + winnerDelta + disruptDelta - 2) / 3; + if (increase <= 0) + { + // No increase... + return; + } + + bot->botvars.diffincrease = increase; } /*--------------------------------------------------