def handleDeath(initialState, nightInNDeaths): """ Output: Returns list of GameStates Input: initialState: initialGameState. Mainly for the playersToDie nightInNDeaths: to keep a shooter from activating Thermal """ results = [] if initialState is None: raise TypeError("None was passed in place of a GameState") elif not isinstance(initialState, GameState): raise TypeError("State was of incorrect type. Was of type %s", initialState.__name__) if type(nightInNDeaths) is not int: raise TypeError( "Night counter is of incorrect type. Was %s, but expected %s", type(nightInNDeaths).__name__, int.__name__ ) elif nightInNDeaths < 0: raise ValueError("Night counter must be positive. Was %s.", nightInNDeaths) if initialState.playersToDie is not None and len(initialState.playersToDie) == 0: return [initialState] currentPlayerToDie = initialState.playersToDie[0] if currentPlayerToDie not in initialState.players: initialState.playersToDie.pop(0) return handleDeath(initialState, nightInNDeaths - 1) if ( initialState.protectedPlayer == currentPlayerToDie or currentPlayerToDie == "ackbar" or currentPlayerToDie == "guard" ): initialState.playersToDie.pop(0) results = handleDeath(initialState, len(initialState.playersToDie)) else: newGameState = GameState( newPlayerList=removeFirst(initialState.players, currentPlayerToDie), otherState=initialState ) newGameState.playersToDie.pop(0) remainingPlayersToDie = len(newGameState.playersToDie) if currentPlayerToDie not in swSets.shooters or currentPlayerToDie == newGameState.disabledPlayer: if nightInNDeaths > 0 and currentPlayerToDie == "thermal": highestSith = "emperor" if "emperor" in initialState.players else "darth" newGameState.playersToDie.insert(0, highestSith) remainingPlayersToDie += 1 if currentPlayerToDie == "storm": newGameState.resurectStorm = True results = handleDeath(newGameState, remainingPlayersToDie) else: shooterResults = [] for player in newGameState.players: shooterResponseGameState = GameState(otherState=newGameState) shooterResponseGameState.playersToDie.append(player) shooterResults += handleDeath(shooterResponseGameState, remainingPlayersToDie) results = shooterResults for state in results: state.evaluateEndConditions() return results