Exemple #1
0
def test_starting_score_better_color():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.RED, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.X),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER)
    ]
    hand = Hand(tiles_in_hand)
    assert hand.starting_score() == 3
Exemple #2
0
def test_starting_score_identical_tiles_color():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.RED, Shape.DIAMOND),
        Tile(Color.RED, Shape.X),
        Tile(Color.RED, Shape.STAR),
        Tile(Color.RED, Shape.CLOVER)
    ]
    hand = Hand(tiles_in_hand)
    assert hand.starting_score() == 5
Exemple #3
0
def test_starting_score_identical_tiles_shape():
    tiles_in_hand = [
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.X),
        Tile(Color.GREEN, Shape.X),
        Tile(Color.RED, Shape.X),
        Tile(Color.PURPLE, Shape.X)
    ]
    hand = Hand(tiles_in_hand)
    assert hand.starting_score() == 5
Exemple #4
0
def test_worst_starting_score():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER)
    ]
    hand = Hand(tiles_in_hand)
    assert hand.starting_score() == 1
Exemple #5
0
def test_starting_score_better_shape():
    tiles_in_hand = [
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.X),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.RED, Shape.STAR),
        Tile(Color.PURPLE, Shape.STAR)
    ]
    hand = Hand(tiles_in_hand)
    assert hand.starting_score() == 3
Exemple #6
0
def test_fill_empty_hand():
    tiles_for_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_hand)
    hand = Hand([])
    hand.fill_from(bag)
    assert len(hand.tiles) == hand.CAPACITY
    assert not bag.tiles
Exemple #7
0
def test_exchange_missing_tile_raises():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [
        Tile(Color.PURPLE, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.SQUARE),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.BLUE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    with pytest.raises(MissingTileError):
        hand.exchange_tiles(2 * [Tile(Color.YELLOW, Shape.DIAMOND)], bag)
    assert set(tiles_in_hand) == set(hand.tiles)
    assert set(bag.tiles) == set(tiles_for_bag)
Exemple #8
0
def test_early_play():
    tiles = [
        Tile(Color.RED, Shape.CLOVER),
        Tile(Color.RED, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.PURPLE, Shape.SQUARE),
        Tile(Color.YELLOW, Shape.STAR),
        Tile(Color.PURPLE, Shape.STAR)
    ]
    hand = Hand(tiles)
    player = Player(hand)
    board = Board([(Position(0, 0), Tile(Color.RED, Shape.DIAMOND))])
    bag = Bag([Tile(Color.GREEN, Shape.CIRCLE)])
    tiles_and_positions = [(Position(0, 1), Tile(Color.RED, Shape.CLOVER))]
    turn = BoardTurn(board, player, bag, tiles_and_positions)
    turn.execute()
    assert player.total_score() == 2
    expected_tiles_on_hand = [
        Tile(Color.RED, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.PURPLE, Shape.SQUARE),
        Tile(Color.YELLOW, Shape.STAR),
        Tile(Color.PURPLE, Shape.STAR),
        Tile(Color.GREEN, Shape.CIRCLE)
    ]
    assert set(expected_tiles_on_hand) == set(player.hand.tiles)
    assert not bag.tiles
Exemple #9
0
def test_normal_move():
    tiles = [Tile(Color.RED, Shape.CLOVER),
             Tile(Color.RED, Shape.DIAMOND),
             Tile(Color.GREEN, Shape.SQUARE),
             Tile(Color.PURPLE, Shape.SQUARE),
             Tile(Color.YELLOW, Shape.STAR),
             Tile(Color.PURPLE, Shape.STAR)]
    hand = Hand(tiles)
    player1 = Player(hand)
    player2 = Player([])  # TODO: Illegal
    board = Board([(Position(0, 0), Tile(Color.RED, Shape.DIAMOND))])
    bag = Bag([Tile(Color.GREEN, Shape.CIRCLE)])
    game = Game(bag, board, [player2, player1], player1)
    tiles_and_positions = [(Position(0, 1),
                           Tile(Color.RED, Shape.CLOVER))]
    game.make_move(tiles_and_positions)
    assert player1.total_score() == 2
    expected_tiles_on_hand = [
        Tile(Color.RED, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.PURPLE, Shape.SQUARE),
        Tile(Color.YELLOW, Shape.STAR),
        Tile(Color.PURPLE, Shape.STAR),
        Tile(Color.GREEN, Shape.CIRCLE)]
    assert set(expected_tiles_on_hand) == set(player1.hand.tiles)
    assert not bag.tiles
    assert player2 == game.current_player
Exemple #10
0
def test_fill_full_hand():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [
        Tile(Color.PURPLE, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.SQUARE),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.BLUE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    hand.fill_from(bag)
    assert set(hand.tiles) == set(tiles_in_hand)
    assert len(bag.tiles) == 6
    assert len(hand.tiles) == 6
Exemple #11
0
def test_fill_partially_filled_hand():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND)
    ]
    hand = Hand(tiles_in_hand)
    tiles_for_bag = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    hand.fill_from(bag)
    assert set(tiles_in_hand) == set(hand.tiles)
    assert hand.CAPACITY == len(hand.tiles)
    assert len(bag.tiles) == 3
Exemple #12
0
def test_passing_turn():
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    hand = Hand(tiles)
    player = Player(hand)
    bag = Bag([])
    board = MockBoard(moves=[], possible_moves=[1, 2, 3])
    turn = PassTurn(player, bag, board)
    turn.execute()
    points = player.total_score()
    assert points == 0
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    assert tiles == player.hand.tiles
Exemple #13
0
def test_illegal_attempt_at_passing_both():
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    hand = Hand(tiles)
    player = Player(hand)
    bag = Bag(['Tile in bag'])
    board = MockBoard(moves=['unwanted move'], possible_moves=[1, 2, 3])
    turn = PassTurn(player, bag, board)
    with pytest.raises(IllegalPass):
        turn.execute()
    points = player.total_score()
    assert points == 0
    assert tiles == player.hand.tiles
Exemple #14
0
def test_exchanging_one_of_one():
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    hand = Hand(tiles)
    player = Player(hand)
    bag = Bag([Tile(Color.GREEN, Shape.CLOVER)])
    tiles_to_exchange = [Tile(Color.RED, Shape.CIRCLE)]
    turn = ExchangeTilesTurn(player, bag, tiles_to_exchange)
    turn.execute()
    expected_hand = [Tile(Color.GREEN, Shape.CLOVER)]
    assert expected_hand == player.hand.tiles
    expected_bag = [Tile(Color.RED, Shape.CIRCLE)]
    assert expected_bag == bag.tiles
    assert player.total_score() == 0
Exemple #15
0
def test_late_play():
    tiles = [Tile(Color.RED, Shape.CLOVER), Tile(Color.RED, Shape.DIAMOND)]
    hand = Hand(tiles)
    player = Player(hand)
    board = Board([(Position(0, 0), Tile(Color.RED, Shape.DIAMOND))])
    bag = Bag([])
    tiles_and_positions = [(Position(0, 1), Tile(Color.RED, Shape.CLOVER))]
    turn = BoardTurn(board, player, bag, tiles_and_positions)
    turn.execute()
    assert player.total_score() == 2
    expected_tiles_on_hand = [Tile(Color.RED, Shape.DIAMOND)]
    assert set(expected_tiles_on_hand) == set(player.hand.tiles)
    assert not bag.tiles
Exemple #16
0
def test_init():
    tiles_in_bag = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER)
    ]
    bag = Bag(tiles_in_bag)
    hand = Hand.init_from(bag)
    expected = set(tiles_in_bag)
    result = set(hand.tiles)
    assert expected == result
Exemple #17
0
def test_pass_once():
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    hand = Hand(tiles)
    player1 = Player(hand)
    player2 = Player([])
    player3 = Player([])
    bag = Bag([])
    board = MockBoard(moves=[], possible_moves=[1, 2, 3])
    game = Game(bag, board, [player2, player3, player1], player1)
    game.pass_round()
    points = player1.total_score()
    assert points == 0
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    assert tiles == player1.hand.tiles
    assert player2 == game.current_player
Exemple #18
0
def test_exchange_tiles():
    tiles = [Tile(Color.RED, Shape.CIRCLE)]
    hand = Hand(tiles)
    player1 = Player(hand)
    player2 = Player([])  # TODO: Illegal state.
    bag = Bag([Tile(Color.GREEN, Shape.CLOVER)])
    board = Board([(Position(0, 0), Tile(Color.RED, Shape.DIAMOND))])
    game = Game(bag, board, [player2, player1], player1)
    tiles_to_exchange = [Tile(Color.RED, Shape.CIRCLE)]
    game.exchange_tiles(tiles_to_exchange)
    expected_hand = [Tile(Color.GREEN, Shape.CLOVER)]
    assert expected_hand == player1.hand.tiles
    expected_bag = [Tile(Color.RED, Shape.CIRCLE)]
    assert expected_bag == bag.tiles
    assert player1.total_score() == 0
    assert player2 == game.current_player
Exemple #19
0
def test_last_move():
    tiles = [Tile(Color.RED, Shape.CLOVER)]
    hand = Hand(tiles)
    player1 = Player(hand, [1, 1])
    player2 = Player([])  # TODO: Illegal state
    board = Board([(Position(0, 0), Tile(Color.RED, Shape.DIAMOND))])
    bag = Bag([])
    game = Game(bag, board, [player2, player1], player1)
    tiles_and_positions = [(Position(0, 1),
                           Tile(Color.RED, Shape.CLOVER))]
    game.make_move(tiles_and_positions)
    assert 2+6+2 == player1.total_score()
    expected_tiles_on_hand = []
    assert set(expected_tiles_on_hand) == set(player1.hand.tiles)
    assert not bag.tiles
    assert game.current_player is None
Exemple #20
0
def test_exchange_one_tile():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [Tile(Color.PURPLE, Shape.CIRCLE)]
    bag = Bag(tiles_for_bag)
    hand.exchange_tiles([Tile(Color.RED, Shape.CIRCLE)], bag)
    expected_tiles_in_hand = tiles_in_hand[1:]
    expected_tiles_in_hand.append(Tile(Color.PURPLE, Shape.CIRCLE))
    assert set(expected_tiles_in_hand) == set(hand.tiles)

    expected_tiles_in_bag = [Tile(Color.RED, Shape.CIRCLE)]
    assert set(bag.tiles) == set(expected_tiles_in_bag)
Exemple #21
0
def test_exchange_all_tiles():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [
        Tile(Color.PURPLE, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.SQUARE),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.BLUE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    hand.exchange_tiles(copy(tiles_in_hand), bag)
    assert set(tiles_for_bag) == set(hand.tiles)
    assert set(bag.tiles) == set(tiles_in_hand)
Exemple #22
0
 def init_from(cls, bag):
     hand = Hand.init_from(bag)
     return cls(hand)
Exemple #23
0
def test_is_empty():
    hand = Hand([])
    assert hand.is_empty()
Exemple #24
0
def test_is_not_empty():
    hand = Hand([Tile(Color.RED, Shape.CIRCLE)])
    assert not hand.is_empty()