def test_flow_scenario_2(): flow = { 'prints': [ 'Welcome to Game of Greed', 'Rolling 6 dice', 'You rolled [1, 1, 1, 1, 5, 2]', 'You can bank 2050 points or try for more', 'You have 1 dice remaining', 'You banked 2050 points in round 1', 'You have 2050 points total', 'Thanks for playing!', ], 'prompts': ['Wanna play? ', 'Enter dice to keep: ', 'Roll again? '], 'responses': ['y', '11115', 'n'], 'rolls': [ [1, 1, 1, 1, 5, 2], ], } mp = MockPlayer(**flow) game = Game(mp.mock_print, mp.mock_input) game._do_roll = mp.mock_roll game.play() assert mp.mop_up()
def test_welcome(): prints = [ "Welcome to Game of Greed!", "Wanna play? ", "OK. Maybe another time", "Great! Check back tomorrow!", ] def print_for_testing(message): assert message == prints.pop(0) game = Game(print_for_testing, print_for_testing) game.play()
def play(cls, num_games=1): mega_total = 0 for i in range(num_games): player = cls() game = Game() game.play() mega_total += player.total_score player.reset() print( f"{num_games} games (maybe) played with average score of {mega_total // num_games}" )
def test_flow_yes(): prints = ['Welcome to Game of Greed', 'Great! Check back tomorrow'] prompts = ['Wanna play? Please type y to start game Type: '] responses = ['y'] def mock_print(*args): if len(prints): current_print = prints.pop(0) assert args[0] == current_print def mock_input(*args): if len(prompts): current_prompt = prompts.pop(0) assert args[0] == current_prompt if len(responses): current_response = responses.pop(0) return current_response game = Game(mock_print, mock_input) game.play()
def test_flow_no(): prints = ['Welcome to Game of Greed', 'OK. Maybe another time'] prompts = ['Wanna play? Please type y to start game Type: '] responses = ['n'] def mock_print(*args): if len(prints): current_print = prints.pop(0) assert args[0] == current_print def mock_input(*args): if len(prompts): current_prompt = prompts.pop(0) assert args[0] == current_prompt if len(responses): current_response = responses.pop(0) return current_response game = Game(mock_print, mock_input) game.play()
if msg.startswith('You rolled'): self.roll = [int(char) for char in msg if char.isdigit()} print(args[0]) def _input(self, *args): prompt = arg[0] if prompt == 'Wanna play? Please type y to start game Type: ': print(prompt, 'y') return 'y' if prompt == 'Roll again: ': print(prompt, 'n') return 'n' # if prompt == 'Which would like to keep? ': # score = self.game.calculate_score(self.roll) if 1 in self.roll: return '1' if __name__ == "__main__": bot = LazyPlayer() bot = BondPlayer() game = Game(bot._print, bot._input) bot.game = game game.play(1)
target_score = self.game.calculate_score(self.roll) if target_score < 401 and 1 in self.roll: self.round_score += 100 return "1" elif target_score < 401 and 5 in self.roll: self.round_score += 50 return "5" else: self.round_score += target_score keeping = "" for i in self.roll: val = self.roll.pop(0) if target_score > self.game.calculate_score(self.roll): keeping += f"{val}, " self.roll.append(val) return keeping def wanna_reroll(self, numdice): if numdice < 3 and self.round_score > 201: self.round_score = 0 return 'n' else: return 'y' if __name__ == "__main__": bot = AllThePointsPlayer() game = Game(bot._print, bot._input) bot.game = game game.play()