From f62f2414b0755afd4b1295b151e3dea60b81c9cb Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Mon, 16 Dec 2024 00:04:36 +0000 Subject: [PATCH] controller: Fix sudden death outcome and add last round in half --- controller/test_sm.py | 22 ++++++++++++++++------ controller/valconomy.py | 13 ++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/controller/test_sm.py b/controller/test_sm.py index 46a2974..10f700f 100644 --- a/controller/test_sm.py +++ b/controller/test_sm.py @@ -81,7 +81,8 @@ class TestSm: ('round_start', True, 2, 0, EconomyDecision.BONUS), ('round_start', False, 2, 1, EconomyDecision.MATCH_TEAM), ] + [ - ('round_start', False, 2, 2 + i, EconomyDecision.MATCH_TEAM) for i in range(8)] + [ + ('round_start', False, 2, 2 + i, EconomyDecision.MATCH_TEAM) for i in range(7)] + [ + ('round_start', False, 2, 9, EconomyDecision.BUY), # last round in half ('round_start', False, 2, 10, EconomyDecision.BUY), ('round_start', False, 2, 11, EconomyDecision.SAVE), ('round_start', False, 2, 12, EconomyDecision.BUY), @@ -112,7 +113,8 @@ class TestSm: ('round_start', True, 1, 0, EconomyDecision.BUY), ('round_start', False, 1, 1, EconomyDecision.SAVE), ] + [ - ('round_start', False, 1, 2 + i, EconomyDecision.MATCH_TEAM) for i in range(9)] + [ + ('round_start', False, 1, 2 + i, EconomyDecision.MATCH_TEAM) for i in range(8)] + [ + ('round_start', False, 1, 10, EconomyDecision.BUY), # last round in half ('round_start', False, 1, 11, EconomyDecision.BUY), ('round_start', False, 1, 12, EconomyDecision.BUY), ] + [ @@ -133,8 +135,10 @@ class TestSm: self.do(queue_type='swiftplay', game_state='PREGAME') self.do(queue_type='swiftplay', game_state='INGAME') - for i in range(5): + for i in range(4): self.do(queue_type='swiftplay', game_state='INGAME', enemy_score=1 + i) + for i in range(5): + self.do(queue_type='swiftplay', game_state='INGAME', score=1 + i, enemy_score=4) self.do(queue_type='swiftplay', game_state='INGAME') assert self.mock.seq == [ @@ -144,9 +148,15 @@ class TestSm: ('pregame', False), 'game_start', ('round_start', None, 0, 0, EconomyDecision.BUY), - ] + [ - ('round_start', False, 0, 1 + i, EconomyDecision.BUY) for i in range(4)] + [ - ('game_over', False), + ('round_start', False, 0, 1, EconomyDecision.BUY), + ('round_start', False, 0, 2, EconomyDecision.BUY), + ('round_start', False, 0, 3, EconomyDecision.BUY), + ('round_start', False, 0, 4, EconomyDecision.BUY), + ('round_start', True, 1, 4, EconomyDecision.BUY), + ('round_start', True, 2, 4, EconomyDecision.BUY), + ('round_start', True, 3, 4, EconomyDecision.BUY), + ('round_start', True, 4, 4, EconomyDecision.BUY), + ('game_over', True), ] def test_tdm(self): diff --git a/controller/valconomy.py b/controller/valconomy.py index 1238ab5..662a555 100644 --- a/controller/valconomy.py +++ b/controller/valconomy.py @@ -408,17 +408,16 @@ class ValconomyStateMachine: won_last = True if p.valorant.score > self.score else False self.round_history.append(won_last) + over = False if p.valorant.queue_type == 'swiftplay': if p.valorant.score == 5 or p.valorant.enemy_score == 5: - # Game is over - return + over = True eco = EconomyDecision.BUY else: if p.valorant.score > 12 or p.valorant.enemy_score > 12: if p.valorant.queue_type == 'unrated' or abs(p.valorant.score - p.valorant.enemy_score) >= 2: - # Match is over - return + over = True eco = EconomyDecision.MATCH_TEAM rounds_played = p.valorant.score + p.valorant.enemy_score @@ -443,8 +442,12 @@ class ValconomyStateMachine: elif rounds_played >= 24: # Sudden death or overtime (buy either way) eco = EconomyDecision.BUY + elif rounds_played == 11: + # Last round of half + eco = EconomyDecision.BUY - self.handler.round_start(p, won_last, eco) + if not over: + self.handler.round_start(p, won_last, eco) self.score = p.valorant.score self.score_enemy = p.valorant.enemy_score self.last = GameState.IN_GAME