Exemple #1
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 #2
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 #3
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 #4
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
def test_three_1_2_2():
    player1 = MockPlayer(1)
    player2 = MockPlayer(2)
    player3 = MockPlayer(2)
    players = [player1, player2, player3]
    result = Game.determine_starting_player(players)
    assert result in [player2, player3]
def test_three_3_2_1():
    player1 = MockPlayer(3)
    player2 = MockPlayer(2)
    player3 = MockPlayer(1)
    players = [player1, player2, player3]
    result = Game.determine_starting_player(players)
    assert player1 == result
Exemple #7
0
 def __init__(self, ai_player):
     self.game = Game.make_new_game(num_players=1)
     self.ai = ai_player(self.game)
     self.log = {
         'tiles on board at start of round': [],
         'playable positions total': [],
         'completely forbidden positions': [],
         'number of legal moves for hand': [],
         'number of legal moves of max score for hand': [],
         'unique tiles on hand': [],
         'score of move': [],
         'tiles played in move': []
     }
Exemple #8
0
def main():
    scores = set()
    for i in range(300):
        print(i)
        game = Game.make_new_game(num_players=1)
        played_game = run_single_player_AI(game, BestMultiMoveAI)
        player = played_game.players[0]
        score = player.total_score()
        rounds = len(player.scores)
        scores.add(score / rounds)
    mean = np.mean(list(scores))
    std = np.std(list(scores))
    print(mean)
    print(std)
Exemple #9
0
def test_racks():
    game = Game.make_new_game(num_players=2, seed=0)
    player_1 = game.get_tiles(player=0)
    expected = [Tile(Color.RED, Shape.X),
                Tile(Color.YELLOW, Shape.DIAMOND),
                Tile(Color.ORANGE, Shape.X),
                Tile(Color.BLUE, Shape.CIRCLE),
                Tile(Color.GREEN, Shape.CIRCLE),
                Tile(Color.PURPLE, Shape.STAR)]
    assert set(player_1) == set(expected)
    player_2 = game.get_tiles(player=1)
    expected = [Tile(Color.ORANGE, Shape.DIAMOND),
                Tile(Color.GREEN, Shape.CLOVER),
                Tile(Color.PURPLE, Shape.SQUARE),
                Tile(Color.BLUE, Shape.SQUARE),
                Tile(Color.ORANGE, Shape.SQUARE),
                Tile(Color.PURPLE, Shape.X)]
    assert set(player_2) == set(expected)
Exemple #10
0
def test_make_game():
    Game.make_new_game(num_players=2)
def test_two_first_best():
    player1 = MockPlayer(2)
    player2 = MockPlayer(1)
    result = Game.determine_starting_player([player1, player2])
    assert player1 == result
def test_one_player():
    player = MockPlayer(1)
    result = Game.determine_starting_player([player])
    assert player == result