Beispiel #1
0
def test_duplicate_position():
    board = Board()
    tile1 = Tile(Color.RED, Shape.X)
    tile2 = Tile(Color.RED, Shape.DIAMOND)
    move = [(Position(0, 0), tile1), (Position(0, 0), tile2)]
    result = board.is_allowed(move)
    assert not result
Beispiel #2
0
def test_different_color_and_shape():
    board = Board()
    tile1 = Tile(Color.RED, Shape.X)
    tile2 = Tile(Color.GREEN, Shape.CIRCLE)
    move = [(Position(0, 0), tile1), (Position(0, 1), tile2)]
    result = board.is_allowed(move)
    assert not result
Beispiel #3
0
def test_non_contiguous2():
    board = Board()
    tile1 = Tile(Color.RED, Shape.X)
    tile2 = Tile(Color.RED, Shape.CIRCLE)
    move = [(Position(0, 0), tile1), (Position(2, 0), tile2)]
    result = board.is_allowed(move)
    assert not result
Beispiel #4
0
def testRepeatedMovePosition():
    tile1 = Tile(Color.RED, Shape.CIRCLE)
    tile2 = Tile(Color.RED, Shape.CLOVER)
    board = Board()
    move = [(Position(0, 0), tile1), (Position(0, 0), tile2)]
    result = board.is_allowed(move)
    assert not result
Beispiel #5
0
def test_illegal_multi_tile_column():
    tile1 = Tile(Color.RED, Shape.X)
    tile2 = Tile(Color.RED, Shape.CIRCLE)
    board = Board([(Position(0, 0), tile1), (Position(0, 1), tile2)])
    tile1 = Tile(Color.YELLOW, Shape.X)
    tile2 = Tile(Color.YELLOW, Shape.CLOVER)
    result = board.is_allowed([(Position(1, 0), tile1), (Position(1,
                                                                  1), tile2)])
    assert not result
Beispiel #6
0
def test_valid_move():
    tile1 = Tile(Color.RED, Shape.X)
    board = Board([(Position(0, 0), tile1)])
    tile2 = Tile(Color.RED, Shape.CIRCLE)
    score = board.make_move([(Position(0, 1), tile2)])
    assert score == 2
    tiles = board.tiles
    expected = [(Position(0, 0), tile1), (Position(0, 1), tile2)]
    assert expected == tiles
Beispiel #7
0
def test_illegal_move():
    tile1 = Tile(Color.RED, Shape.X)
    board = Board([(Position(0, 0), tile1)])
    tile2 = Tile(Color.GREEN, Shape.CIRCLE)
    with pytest.raises(ValueError):
        board.make_move([(Position(0, 1), tile2)])
    tiles = board.tiles
    expected = [Position(Position(0, 0), tile1)]
    assert expected == tiles
Beispiel #8
0
def testMoveOvershadowsExistingTile():
    tile1 = Tile(Color.RED, Shape.CIRCLE)
    tile2 = Tile(Color.RED, Shape.CLOVER)
    board = Board([(Position(0, 0), tile1), (Position(0, 1), tile2)])
    tile1 = Tile(Color.RED, Shape.DIAMOND)
    tile2 = Tile(Color.RED, Shape.SQUARE)
    move = [(Position(0, 1), tile1), (Position(1, 1), tile2)]
    result = board.is_allowed(move)
    assert not result
Beispiel #9
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
Beispiel #10
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
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
 def get_total_tiles(self):
     tile_types = [
         Tile(color, shape)
         for color, shape in itertools.product(Color, Shape)
     ]  # TODO: Use remaining unseen_tiles.
     total_tiles = {tile: 3 for tile in tile_types}
     return total_tiles
Beispiel #14
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
Beispiel #15
0
 def make_default(cls, seed=None):
     bag = []
     for color in Color:
         for shape in Shape:
             bag.extend(3 * [Tile(color, shape)])
     random.seed(seed)
     random.shuffle(bag)
     return cls(bag)
Beispiel #16
0
 def remaining_tiles(self):
     """Returns a set of tiles that could still be played,
     that is less than three instances of it is found on the board.
     """
     tiles = Tile.set_of_all_tiles()
     result = set()
     count = Counter(self.tiles_list)
     for tile in tiles:
         if count[tile] < 3:
             result.add(tile)
     return result
Beispiel #17
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)
Beispiel #18
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
Beispiel #19
0
def L_shaped_board():
    tile1 = Tile(Color.RED, Shape.X)
    tile2 = Tile(Color.RED, Shape.CIRCLE)
    tile3 = Tile(Color.RED, Shape.SQUARE)
    tile4 = Tile(Color.RED, Shape.CLOVER)
    tile5 = Tile(Color.GREEN, Shape.CLOVER)
    tile6 = Tile(Color.ORANGE, Shape.CLOVER)
    tile7 = Tile(Color.YELLOW, Shape.CLOVER)
    return Board([(Position(0, 0), tile1), (Position(1, 0), tile2),
                  (Position(2, 0), tile3), (Position(3, 0), tile4),
                  (Position(3, 1), tile5), (Position(3, 2), tile6),
                  (Position(3, 3), tile7)])
Beispiel #20
0
def make_one_with_each():
    result = [
        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)]
    return result
Beispiel #21
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
Beispiel #22
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
Beispiel #23
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
Beispiel #24
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
Beispiel #25
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
Beispiel #26
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
Beispiel #27
0
def test_second_column_strike():
    tile1 = Tile(Color.RED, Shape.CIRCLE)
    tile2 = Tile(Color.RED, Shape.CLOVER)
    tile3 = Tile(Color.RED, Shape.DIAMOND)
    tile4 = Tile(Color.RED, Shape.CLOVER)
    placements = [(Position(0, 1), tile1), (Position(0, 0), tile2),
                  (Position(0, -1), tile3), (Position(1, -1), tile4)]
    board = Board(placements)
    tile5 = Tile(Color.RED, Shape.CLOVER)
    tile6 = Tile(Color.RED, Shape.CIRCLE)
    move = [(Position(1, 1), tile5), (Position(1, 2), tile6)]
    result = board.is_allowed(move)
    assert result
Beispiel #28
0
def test_qwirkle_score():
    tile1 = Tile(Color.RED, Shape.CIRCLE)
    tile2 = Tile(Color.RED, Shape.CLOVER)
    tile3 = Tile(Color.RED, Shape.DIAMOND)
    tile4 = Tile(Color.RED, Shape.SQUARE)
    tile5 = Tile(Color.RED, Shape.STAR)
    tile6 = Tile(Color.RED, Shape.X)
    board = Board()
    move = [(Position(0, 0), tile1), (Position(1, 0), tile2),
            (Position(2, 0), tile3), (Position(3, 0), tile4),
            (Position(4, 0), tile5), (Position(5, 0), tile6)]
    score = board.make_move(move)
    assert score == 12
Beispiel #29
0
def test_exchange_no_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)]
    bag = Bag(tiles_for_bag)
    with pytest.raises(NonMoveError):
        hand.exchange_tiles([], bag)
    assert set(tiles_in_hand) == set(hand.tiles)

    expected_tiles_in_bag = [Tile(Color.PURPLE, Shape.CIRCLE)]
    assert set(bag.tiles) == set(expected_tiles_in_bag)
Beispiel #30
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