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_final_round():
    flow = {
        'prints': [
            'Welcome to the Game of Greed!',
            'Game over! Your final score is 100',

        ],
        'prompts': [
            'Wanna play? Type y to roll ',
            'Would you like to keep 1? y for yes : n for no ',
            'Would you like to keep 2? y for yes : n for no ',
            'Would you like to keep 2? y for yes : n for no ',
            'Would you like to keep 3? y for yes : n for no ',
            'Would you like to keep 3? y for yes : n for no ',
            'Would you like to keep 4? y for yes : n for no ',
        
        ],
        'responses': [
            'y', 'y', 'y', 'y', 'y', 'y', 'y'
        ],
        'rolls': [
            [1, 2, 2, 3, 3, 4],
      
        ]
    }

    mp = MockPlayer(**flow)

    game = Game(mp.mock_print, mp.mock_input, 9)

    game.roll_dice = mp.mock_roll

    game.play_game()

    assert mp.mop_up()
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()
Esempio n. 5
0
    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_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()
Esempio n. 7
0
def test_def_validate_roll_fail(roll, expected_keepers):

    prints = ['No way pal', roll, 'No way pal',roll]

    inputs = ['0','0', str(expected_keepers[0])]

    def my_print(msg, *args):
        assert msg == prints.pop(0)

    def my_input(msg, *args):
        assert msg == 'Enter dice to keep: '
        return inputs.pop(0)

    game = Game(my_print, my_input)

    keepers = game.validate_roll(roll)

    assert keepers == expected_keepers
Esempio n. 8
0
def test_def_validate_roll_success(roll, expected_keepers):

    def my_print(msg, *args):
        assert msg == roll

    def my_input(msg, *args):
        assert msg == 'Enter dice to keep: '
        keeper_string = ''
        for val in expected_keepers:
            keeper_string += str(val)

        return keeper_string

    game = Game(my_print, my_input)

    keepers = game.validate_roll(roll)

    assert keepers == expected_keepers
def test_flow_zilch():

    flow = {
        'prints': [
            'Rolling 6 dice',
            'You rolled [2, 2, 3, 4, 6, 6]',
            'Oh noes! Zilch',
        ],
        'rolls': [[2, 2, 3, 4, 6, 6]],
    }

    mp = MockPlayer(**flow)

    game = Game(mp.mock_print, mp.mock_input)

    game._do_roll = mp.mock_roll

    # Easier to test with hitting _do_round directly,
    # no prob, but notice that protected method use is risky
    game.each_turn()

    assert mp.mop_up()
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()
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()
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()
Esempio n. 13
0
def test_calculate_score_simple():
    game = Game()
    actual = game.calculate_score((1, 2))
    expected = 100
    assert expected == actual
Esempio n. 14
0
def game():
    play = Game(mock_print, mock_input)
    return play
def game():
    return Game()
Esempio n. 16
0
def test_game():
    return Game(mock_print, mock_input)
def test_zilch():
    test_game = Game()
    actual = test_game.calculate_score((6, 3, 4, 2, 6, 2))
    assert 0 == actual
Esempio n. 18
0
def test_Game_instance():
    game = Game()
    assert game
Esempio n. 19
0
def test_three_unique_pairs(test_input, expected):
    my_game = Game()
    assert my_game.calculate_score(test_input) == expected
def test_game_one():
    game = Game()
    assert game
def test_3_pairs():
    test_game = Game()
    actual = test_game.calculate_score((6, 4, 4, 2, 6, 2))
    assert 1500 == actual
def test_roll():
    game = Game()
    game_roll = game.roll_set(6)
    assert max(game_roll) <= 6
    assert min(game_roll) > 0
def test_roll_case1():
    game = Game()
    game_roll = game.roll_set(1)
    assert max(game_roll) <= 6
    assert min(game_roll) > 0
Esempio n. 24
0
def test_zilch():
    my_game = Game()
    assert my_game.calculate_score((2, 3, 4, 6, 6, 3)) == 0
Esempio n. 25
0
def test_mcflurry(test_input, expected):
    my_game = Game()
    assert my_game.calculate_score(test_input) == expected
def test_1_and_5():
    test_game = Game()
    actual = test_game.calculate_score((6, 5, 4, 1, 4, 2))
    assert 150 == actual
Esempio n. 27
0
def test_straight(test_input, expected):
    my_game = Game()
    assert my_game.calculate_score(test_input) == expected
Esempio n. 28
0
        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)
Esempio n. 29
0
def test_two_trios(test_input, expected):
    my_game = Game()
    assert my_game.calculate_score(test_input) == expected
def test_straigt():
    test_game = Game()
    actual = test_game.calculate_score((6, 5, 4, 1, 3, 2))
    assert 1500 == actual