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_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_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_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_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_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]