def test_flow_scenario_1(): flow = { 'prints': [ 'Welcome to Game of Greed', 'Rolling 6 dice', 'You rolled [1, 2, 3, 4, 1, 2]', 'You can bank 100 points or try for more', 'You have 5 dice remaining', 'Rolling 5 dice', 'You rolled [3, 3, 3, 4, 1]', 'You can bank 500 points or try for more', 'You have 1 dice remaining', 'You banked 500 points in round 1', 'You have 500 points total', 'Thanks for playing!' ], 'prompts': ['Wanna play? ', 'Enter dice to keep: ', 'Roll again? '], 'responses': ['y', '1', 'y', '3331', 'n'], 'rolls': [[1, 2, 3, 4, 1, 2], [3, 3, 3, 4, 1]], } mp = MockPlayer(**flow) game = Game(mp.mock_print, mp.mock_input) game._do_roll = mp.mock_roll game.begin(1) assert mp.mop_up()
def test_flow_no(): flow = { 'prints': ['Welcome to Game of Greed', 'OK. Maybe later'], 'prompts': ['Wanna play? '], 'responses': ['no'], } mp = MockPlayer(**flow) game = Game(mp.mock_print, mp.mock_input) game.do_roll = mp.mock_roll game.begin() assert mp.mop_up()
def test_flow_yes(): prints = ['Welcome to Game of Greed', 'Check back tomorrow :D'] prompts = ['Wanna play? '] 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.begin()
msg = args[0] if msg.startswith('You rolled '): self.roll = [int(char) for char in msg if char.isdigit()] print(msg) def _input(self, *args): prompt = args[0] if prompt == 'Wanna play? ': print(prompt, 'y') return 'y' if prompt == 'which would you like to keep? ': score = self.game.calculate_score(self.roll) #figure this out if 1 in self.roll: return '1' if 5 in self.roll: return '5' if __name__ == "__main__": bot = ParticipationTrophy() game = Game(bot._print, bot._input) game.begin()