From 5f7e4e4d051e4b57d3c9614e87af1e75c9c178df Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Sun, 1 Jul 2018 13:18:36 -0700 Subject: [PATCH] Revamp how gamemode votes work - Majority vote will still select that mode unconditionally - When there is no majority vote, the game mode is decided in a two-step process: 1. The bot will first try to select a game mode among those voted vs a random gamemode (for the purpose of this, all players who did not vote are considered to have voted for a random gamemode). For example, in an 8 player game if there are 2 votes for foolish, 2 votes for aleatoire, and 1 vote for default, one of `{foolish, foolish, aleatoire, aleatoire, default, random gamemode, random gamemode, random gamemode}` will be chosen (25% foolish, 25% alea, 12.5% default, 37.5% random gamemode) 2. If random gamemode is selected, a random mode is selected according to the base likelihoods. Votes do not modify this anymore Votes which are for majority-only modes or modes with incorrect player counts are not counted (and treated as votes for a random gamemode instead) --- src/wolfgame.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/wolfgame.py b/src/wolfgame.py index 8f2d85c..ae00932 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -4622,10 +4622,23 @@ def start(cli, nick, chan, forced = False, restart = ""): cgamemode(random.choice(voted)) else: possiblegamemodes = [] - for gamemode in var.GAME_MODES.keys() - var.DISABLED_GAMEMODES: - if len(villagers) >= var.GAME_MODES[gamemode][1] and len(villagers) <= var.GAME_MODES[gamemode][2] and var.GAME_MODES[gamemode][3] > 0: - possiblegamemodes += [gamemode]*(var.GAME_MODES[gamemode][3]+votes.get(gamemode, 0)*15) - cgamemode(random.choice(possiblegamemodes)) + numvotes = 0 + for gamemode, num in votes.items(): + if len(villagers) < var.GAME_MODES[gamemode][1] or len(villagers) > var.GAME_MODES[gamemode][2] or var.GAME_MODES[gamemode][3] == 0: + continue + possiblegamemodes += [gamemode] * num + numvotes += num + if len(villagers) - numvotes > 0: + possiblegamemodes += [None] * (len(villagers) - numvotes) + # check if we go with a voted mode or a random mode + gamemode = random.choice(possiblegamemodes) + if gamemode is None: + possiblegamemodes = [] + for gamemode in var.GAME_MODES.keys() - var.DISABLED_GAMEMODES: + if len(villagers) >= var.GAME_MODES[gamemode][1] and len(villagers) <= var.GAME_MODES[gamemode][2] and var.GAME_MODES[gamemode][3] > 0: + possiblegamemodes += [gamemode] * var.GAME_MODES[gamemode][3] + gamemode = random.choice(possiblegamemodes) + cgamemode(gamemode) else: cgamemode(restart)