def test_player_should_keep_getting_hands_until_can_move(people, turtles):
    # Initial state:
    # First player cards: 0,1,2,3,4
    # Second player cards: 5,6,7,8,9
    #
    # First player plays 0 and takes next card (10)
    # Second player can't make any move, so he should take another hand:
    # 11, 12, 13, 14, 15
    # He still can't make any move so he takes another hand:
    # 16, 17, 18, 19, 20

    cards = [Card(i, 'GREEN', 'PLUS') for i in range(HAND_SIZE)]
    cards += [
        Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE, 3 * HAND_SIZE + 1)
    ]
    cards += [
        Card(i, 'GREEN', 'PLUS')
        for i in range(3 * HAND_SIZE, 4 * HAND_SIZE + 1)
    ]

    game = Game(people, turtles, cards)
    player = game.players[0]

    game.play(player.person, Action(Card(0, 'GREEN', 'PLUS')))

    assert game.players[1].cards == cards[3 * HAND_SIZE + 1:4 * HAND_SIZE + 1]
def test_first_player_should_be_active_after_three_moves(cards):
    people = [Person(0, 'Piotr'), Person(1, 'Marta'), Person(2, 'Ewa')]
    turtles = [Turtle('GREEN'), Turtle('RED'), Turtle('BLUE')]
    game = Game(people, turtles, cards)

    game.play(people[0], Action(Card(0, 'RED', 'PLUS')))
    game.play(people[1], Action(Card(5, 'RED', 'PLUS')))

    assert game.active_player == game.players[2]
def test_play_returns_ranking_when_autonomous_turtle_finishes(cards, people):
    turtles = [Turtle('GREEN'), Turtle('RED'), Turtle('YELLOW')]
    # we add one green card in order to make Piotr win
    all_cards = [Card(4 * HAND_SIZE, 'GREEN', 'PLUS')] + cards
    game = Game(people, turtles, all_cards)

    # one more move is required becuase we moved the green turtle once
    for _ in range(8 + 1):
        active = game.active_player
        game.play(active.person, Action(active.cards[0]))

    active = game.active_player
    ranking = game.play(active.person, Action(active.cards[0]))

    assert ranking == [Person(0, 'Piotr'), Person(1, 'Marta')]
def test_first_person_should_become_first_player():
    people = [Person(0, 'Piotr'), Person(1, 'Marta')]

    game = Game(people, [Turtle('GREEN'), Turtle('RED')],
                [Card(0, 'RED', 'PLUS') for _ in range(2 * HAND_SIZE)])

    assert game.active_player.person == people[0]
def test_first_player_should_get_another_hand_when_cant_move(people, turtles):
    cards = [Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE)]
    cards += [
        Card(i, 'GREEN', 'PLUS') for i in range(HAND_SIZE, 3 * HAND_SIZE)
    ]

    game = Game(people, turtles, cards)

    assert game.players[0].cards == cards[2 * HAND_SIZE:3 * HAND_SIZE]
def test_player_keeps_getting_another_hand_until_can_move(people, turtles):
    cards = [Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE)]
    cards += [
        Card(i, 'RAINBOW', 'MINUS') for i in range(HAND_SIZE, 2 * HAND_SIZE)
    ]
    cards += [
        Card(i, 'GREEN', 'PLUS') for i in range(2 * HAND_SIZE, 4 * HAND_SIZE)
    ]

    game = Game(people, turtles, cards)

    assert game.players[0].cards == cards[2 * HAND_SIZE:3 * HAND_SIZE]
def test_next_player_should_get_new_hand_if_he_cant_move(people, turtles):
    # Initial state:
    # First player cards: 0,1,2,3,4
    # Second player cards: 5,6,7,8,9
    #
    # First player plays 0 and takes next card (10)
    # Second player can't make any move, so he should take another hand:
    # 11, 12, 13, 14, 15

    cards = [Card(i, 'GREEN', 'PLUS') for i in range(HAND_SIZE)]
    cards += [Card(i, 'RED', 'MINUS') for i in range(HAND_SIZE, 2 * HAND_SIZE)]
    cards += [
        Card(i, 'GREEN', 'PLUS') for i in range(2 * HAND_SIZE, 4 * HAND_SIZE)
    ]

    game = Game(people, turtles, cards)
    player = game.players[0]

    game.play(player.person, Action(Card(0, 'GREEN', 'PLUS')))

    assert game.players[1].cards == cards[2 * HAND_SIZE + 1:3 * HAND_SIZE + 1]
def test_it_should_be_third_player_turn_after_removing_second_player(cards):
    turtles = [Turtle('GREEN'), Turtle('RED'), Turtle('BLUE')]
    people = (Person(0, 'Piotr'), Person(1, 'Marta'), Person(2, 'Other'))
    game = Game(people, turtles, cards)

    game.play(people[0], Action(Card(0, 'RED', 'PLUS')))
    game.remove_player(people[1])

    assert game.active_player.person == people[2]
def test_raises_when_plays_arrow_arrow_incorrect_color(people, cards, turtles):
    player = people[0]
    all_cards = [Card(4 * HAND_SIZE, 'RAINBOW', 'ARROW_ARROW')] + cards
    game = Game(people, turtles, all_cards)

    for _ in range(2):
        active = game.active_player
        game.play(active.person, Action(active.cards[-1]))

    with pytest.raises(ValueError):
        game.play(player,
                  Action(Card(4 * HAND_SIZE, 'RAINBOW', 'ARROW_ARROW'), 'RED'))
def test_players_should_correspond_to_people():
    people = [Person(0, 'Piotr'), Person(1, 'Marta')]
    game = Game(people, [Turtle('GREEN'), Turtle('RED')],
                [Card(0, 'RED', 'PLUS') for _ in range(2 * HAND_SIZE)])

    assert [player.person for player in game.players] == people
def game(people, turtles, cards):
    return Game(people, turtles, cards)
def test_game_with_not_enough_cards_should_fail():
    with pytest.raises(ValueError):
        Game([Person(0, 'Piotr'), Person(1, 'Marta')],
             [Turtle('GREEN'), Turtle('RED')],
             [Card(0, 'RED', 'PLUS') for _ in range(2 * HAND_SIZE - 1)])
def test_game_without_cards_should_fail():
    with pytest.raises(ValueError):
        Game([Person(0, 'Piotr'), Person(1, 'Marta')],
             [Turtle('GREEN'), Turtle('RED')], [])
def test_game_with_one_player_shoud_fail():
    with pytest.raises(ValueError):
        Game([Person(0, 'Piotr')], [], [])
def test_game_with_no_players_should_fail():
    with pytest.raises(ValueError):
        Game([], [], [])