コード例 #1
0
    def test_perimeter_goal(self, board_16x16):
        correct_scores = [(COLOUR_LIST[0], 2), (COLOUR_LIST[1], 5),
                          (COLOUR_LIST[2], 4), (COLOUR_LIST[3], 5)]

        # Set up a goal for each colour and check results.
        for colour, expected in correct_scores:
            goal = PerimeterGoal(colour)
            assert goal.score(board_16x16) == expected
コード例 #2
0
def test_combine_game_board(game_board, renderer):
    renderer.draw_board(_block_to_squares(game_board))
    renderer.save_to_file('game_board1.png')
    game_board.children[0].children[3].combine()
    _flatten(game_board)
    renderer.clear()
    goal = PerimeterGoal(COLOUR_LIST[0])
    goal.score(game_board)
    renderer.draw_board(_block_to_squares(game_board))
    renderer.save_to_file('game_board_rotate_combine.png')
コード例 #3
0
 def test_smart_player(self, board_16x16) -> None:
     goal_smart = PerimeterGoal(COLOUR_LIST[1])
     player_smart = SmartPlayer(1, goal_smart, 1)
     print(player_smart.difficulty)
     goal_random = PerimeterGoal(COLOUR_LIST[0])
     player_random = RandomPlayer(10, goal_random)
     random_move = player_random.generate_move(board_16x16)
     #player_smart._proceed = True
     #x = player_smart.generate_move(board_16x16)
     assert 1
コード例 #4
0
ファイル: game.py プロジェクト: LilyYC/legendary-train
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.max_depth = max_depth
        self.num_human = num_human
        self.random_players = random_players
        self.smart_players = smart_players
        self.num_players = num_human + random_players + len(smart_players)

        # 1 create a Renderer for this game
        self.renderer = Renderer(self.num_players)

        # 2 Generate a random goal typr, for all players to share
        potential_goal = [
            BlobGoal(COLOUR_LIST[0]),
            PerimeterGoal(COLOUR_LIST[0])
        ]
        self.goal = potential_goal[random.randint(0, 1)]

        # 3 Generate a random board, with the given maximum depth
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), 750)

        # 4 Generate the right number of human players, random players,
        # and smart players
        self.players = []
        for human_id in range(num_human):
            self.players.append(HumanPlayer(self.renderer, human_id,
                                            self.goal))
        for ran_id in range(num_human, num_human + random_players):
            self.players.append(RandomPlayer(self.renderer, ran_id, self.goal))
        for smart_id in range(num_human + random_players, self.num_players):
            difficulty_level = smart_players[smart_id - num_human -
                                             random_players]
            self.players.append(
                SmartPlayer(self.renderer, smart_id, self.goal,
                            difficulty_level))

        for player in self.players:
            player.goal.colour = COLOUR_LIST[random.randint(0, 3)]
            if isinstance(self.goal, BlobGoal):
                player.goal = BlobGoal(player.goal.colour)
            else:
                player.goal = PerimeterGoal(player.goal.colour)
            if isinstance(player, HumanPlayer):
                self.renderer.display_goal(player)

        # 5 before returning, draw the board
        for player_id in range(len(self.players)):
            self.renderer.draw(self.board, player_id)
コード例 #5
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)
        self.players = []
        if random.random() < 0.5:
            for i in range(num_human):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(HumanPlayer(self.renderer, \
                                                len(self.players), \
                                                BlobGoal(target)))
            for i in range(random_players):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(RandomPlayer(self.renderer, \
                                                 len(self.players), \
                                                 BlobGoal(target)))
            for i in smart_players:
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(SmartPlayer(self.renderer, \
                                                len(self.players), \
                                                BlobGoal(target), \
                                                i))
        else:
            for i in range(num_human):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(HumanPlayer(self.renderer, \
                                                len(self.players), \
                                                PerimeterGoal(target)))
            for i in range(random_players):
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(RandomPlayer(self.renderer, \
                                                 len(self.players), \
                                                 PerimeterGoal(target)))
            for i in smart_players:
                target = \
                    COLOUR_LIST[int(random.random() * len(COLOUR_LIST))]
                self.players.append(SmartPlayer(self.renderer, \
                                                len(self.players), \
                                                PerimeterGoal(target), \
                                                i))
        self.renderer.draw(self.board, 0)
コード例 #6
0
def test_perimeter_goal_single_board(single_board) -> None:
    correct_scores = [
        (COLOUR_LIST[0], 2),
        (COLOUR_LIST[1], 0),
        (COLOUR_LIST[2], 0),
        (COLOUR_LIST[3], 0)
    ]

    # Set up a goal for each colour and check the results
    for colour, expected in correct_scores:
        goal = PerimeterGoal(colour)
        assert goal.score(single_board) == expected
コード例 #7
0
def test_perimeter_goal_board_16x16(board_16x16) -> None:
    correct_scores = [
        (COLOUR_LIST[0], 5),
        (COLOUR_LIST[1], 9),
        (COLOUR_LIST[2], 8),
        (COLOUR_LIST[3], 10)
    ]

    # Set up a goal for each colour and check the results
    for colour, expected in correct_scores:
        goal = PerimeterGoal(colour)
        assert goal.score(board_16x16) == expected
コード例 #8
0
def test_perimeter_goal():
    """
    Test the blob goal for the given board
    """
    board, _ = construct_board()

    # On the hand-constructed board, these are the correct scores for
    # each colour.
    correct_scores = [(COLOUR_LIST[0], 2), (COLOUR_LIST[1], 5),
                      (COLOUR_LIST[2], 4), (COLOUR_LIST[3], 5)]

    # Set up a goal for each colour and check results.
    for colour, score in correct_scores:
        goal = PerimeterGoal(colour)
        assert goal.score(board) == score
コード例 #9
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Each player has a random target colour, and all players share the
        same goal(Players might have same target colour.)

        Precondition:
            2 <= max_depth <= 5
        """
        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        num_player = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_player)
        self.players = []

        random_num = random.randint(0, 1)
        for i in range(num_player):
            if random_num == 0:
                goal = BlobGoal(COLOUR_LIST[random.randint(0, 3)])
            else:
                goal = PerimeterGoal(COLOUR_LIST[random.randint(0, 3)])
            if i < num_human:
                self.players.append(HumanPlayer(self.renderer, i, goal))
            elif num_human <= i < num_human + random_players:
                self.players.append(RandomPlayer(self.renderer, i, goal))
            else:
                self.players.append(
                    SmartPlayer(
                        self.renderer, i, goal,
                        smart_players[i - (num_human + random_players)]))
        # Display each player's goal before starting game.
        for i in range(num_player):
            self.renderer.display_goal(self.players[i])
コード例 #10
0
ファイル: game.py プロジェクト: StphnKeith/block_game
    def _generate_players(self, num_players: int, player_type: str,
                          goal_type: str, start_id: int) -> List[Player]:
        """Generate a list of players with the given number of players,
        of the given type, with the given <goal_type>, with ids incrementing
        from <start_id>.

        Preconditions:
            player_type == 'human', 'random', or 'smart'
            goal_type == 'blob', or 'perimeter'
        """
        player_list = []
        player_count = 0
        id_count = start_id

        while player_count < num_players:
            # Generate a blob goal or a perimeter goal with a random colour
            if goal_type == 'blob':
                goal = BlobGoal(COLOUR_LIST[random.randint(0, 3)])
            else:
                goal = PerimeterGoal(COLOUR_LIST[random.randint(0, 3)])

            # Generate a player of the given type, using goal
            if player_type == 'human':
                player = HumanPlayer(self.renderer, id_count, goal)
            elif player_type == 'random':
                player = RandomPlayer(self.renderer, id_count, goal)
            else:
                player = SmartPlayer(self.renderer, id_count, goal)

            # Add player to the player list, iterate counts by one
            player_list.append(player)
            player_count += 1
            id_count += 1

        return player_list
コード例 #11
0
ファイル: a2_playground.py プロジェクト: cycv5/Blocky
def goal_playground():
    from goal import generate_goals, _flatten, PerimeterGoal, BlobGoal
    goals = generate_goals(3)
    print([g.description() for g in goals])

    b = block_three_level1()
    print(block_graph(b))
    print(_flatten(b))

    pg = PerimeterGoal(COLOUR_LIST[0])
    print(pg.score(b))

    bg = BlobGoal(COLOUR_LIST[0])
    print(bg.score((b)))

    bg = BlobGoal(COLOUR_LIST[1])
    print(bg.score((b)))
コード例 #12
0
def test_perimeter_score():
    g = PerimeterGoal(COLOUR_LIST[0])
    # depth 0
    b1 = Block((0, 0), 750, COLOUR_LIST[0], 0, 0)
    assert g.score(b1) == 4
    # depth 1
    b1 = Block((0, 0), 750, None, 0, 1)
    b2 = Block((0, 0), 375, COLOUR_LIST[0], 1, 1)
    b3 = Block((0, 0), 375, COLOUR_LIST[1], 1, 1)
    b4 = Block((0, 0), 375, COLOUR_LIST[2], 1, 1)
    b5 = Block((0, 0), 375, COLOUR_LIST[3], 1, 1)
    b1.children = [b2, b3, b4, b5]
    assert g.score(b1) == 2
    b1.children = [b2, b2.create_copy(), b2.create_copy(), b2.create_copy()]
    assert g.score(b1) == 8
    # depth 2
    b6 = Block((0, 0), 375, None, 0, 2)
    b7 = Block((0, 0), 375, None, 1, 2)
    b8 = Block((0, 0), 375, COLOUR_LIST[2], 1, 2)
    b9 = Block((0, 0), 375, COLOUR_LIST[3], 1, 2)
    b10 = Block((0, 0), 375, COLOUR_LIST[0], 1, 2)
    b6.children = [b7, b8, b9, b10]
    b7a = Block((0, 0), 375, COLOUR_LIST[0], 2, 2)
    b8a = Block((0, 0), 375, COLOUR_LIST[2], 2, 2)
    b9a = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b10a = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b7.children = [b7a, b8a, b9a, b10a]
    assert g.score(b6) == 6
    # 4 corners only
    b11 = Block((0, 0), 375, None, 0, 2)
    b12 = Block((0, 0), 375, None, 1, 2)
    b13 = Block((0, 0), 375, None, 1, 2)
    b14 = Block((0, 0), 375, None, 1, 2)
    b15 = Block((0, 0), 375, None, 1, 2)
    b11.children = [b12, b13, b14, b15]
    # top right
    b12a = Block((0, 0), 375, COLOUR_LIST[0], 2, 2)
    b13a = Block((0, 0), 375, COLOUR_LIST[2], 2, 2)
    b14a = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b15a = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b12.children = [b12a, b13a, b14a, b15a]
    # top left
    b12b = Block((0, 0), 375, COLOUR_LIST[1], 2, 2)
    b13b = Block((0, 0), 375, COLOUR_LIST[0], 2, 2)
    b14b = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b15b = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b13.children = [b12b, b13b, b14b, b15b]
    # bottom left
    b12c = Block((0, 0), 375, COLOUR_LIST[1], 2, 2)
    b13c = Block((0, 0), 375, COLOUR_LIST[2], 2, 2)
    b14c = Block((0, 0), 375, COLOUR_LIST[0], 2, 2)
    b15c = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b14.children = [b12c, b13c, b14c, b15c]
    # bottom right
    b12d = Block((0, 0), 375, COLOUR_LIST[1], 2, 2)
    b13d = Block((0, 0), 375, COLOUR_LIST[2], 2, 2)
    b14d = Block((0, 0), 375, COLOUR_LIST[3], 2, 2)
    b15d = Block((0, 0), 375, COLOUR_LIST[0], 2, 2)
    b15.children = [b12d, b13d, b14d, b15d]
    assert g.score(b11) == 8
コード例 #13
0
def test_score_perimeter_goal() -> None:
    b = Block((0, 0), 500, None, 0, 2)
    b.children = [Block(b._children_positions()[0], 250, None, 1, 2),
                  Block(b._children_positions()[1], 250, COLOUR_LIST[1], 1, 2),
                  Block(b._children_positions()[2], 250, COLOUR_LIST[2], 1, 2),
                  Block(b._children_positions()[3], 250, COLOUR_LIST[3], 1, 2)]
    b.children[0].children = [Block(b.children[0]._children_positions()[0], 125,
                                    COLOUR_LIST[2], 2, 2),
                              Block(b.children[0]._children_positions()[1],
                                    125, COLOUR_LIST[0], 2, 2),
                              Block(b.children[0]._children_positions()[2], 125,
                                    COLOUR_LIST[2], 2, 2),
                              Block(b.children[0]._children_positions()[3], 125,
                                    COLOUR_LIST[3], 2, 2)]
    P = PerimeterGoal(COLOUR_LIST[3])
    assert P.score(b) == 5
    b.children[0].children[0].paint(COLOUR_LIST[3])
    assert P.score(b) == 7
コード例 #14
0
def test_score_perimeter_goal() -> None:
    block1 = Block((0, 0), 16, None, 0, 2)
    c1 = Block((8, 0), 8, (1, 128, 181), 1, 2)
    c2 = Block((0, 0), 8, (199, 44, 58), 1, 2)
    c3 = Block((0, 8), 8, None, 1, 2)
    c4 = Block((8, 8), 8, None, 1, 2)
    block1.children = [c1, c2, c3, c4]
    b31 = Block((4, 8), 4, (1, 128, 181), 2, 2)
    b32 = Block((0, 8), 4, (199, 44, 58), 2, 2)
    b33 = Block((0, 12), 4, (255, 211, 92), 2, 2)
    b34 = Block((4, 12), 4, (199, 44, 58), 2, 2)
    c3.children = [b31, b32, b33, b34]
    b41 = Block((12, 8), 4, (255, 211, 92), 2, 2)
    b42 = Block((8, 8), 4, (199, 44, 58), 2, 2)
    b43 = Block((8, 12), 4, (255, 211, 92), 2, 2)
    b44 = Block((12, 12), 4, (199, 44, 58), 2, 2)
    c4.children = [b41, b42, b43, b44]
    block2 = Block((0, 0), 16, None, 0, 2)
    c1 = Block((8, 0), 8, (1, 128, 181), 1, 2)
    c2 = Block((0, 0), 8, (199, 44, 58), 1, 2)
    c3 = Block((0, 8), 8, (255, 211, 92), 1, 2)
    c4 = Block((8, 8), 8, (1, 128, 181), 1, 2)
    block2.children = [c1, c2, c3, c4]
    block3 = Block((0, 0), 16, None, 0, 2)
    c1 = Block((8, 0), 8, (1, 128, 181), 1, 2)
    c2 = Block((0, 0), 8, (199, 44, 58), 1, 2)
    c3 = Block((0, 8), 8, None, 1, 2)
    c4 = Block((8, 8), 8, (199, 44, 58), 1, 2)
    block3.children = [c1, c2, c3, c4]
    b31 = Block((4, 8), 4, (1, 128, 181), 2, 2)
    b32 = Block((0, 8), 4, (199, 44, 58), 2, 2)
    b33 = Block((0, 12), 4, (255, 211, 92), 2, 2)
    b34 = Block((4, 12), 4, (0, 0, 0), 2, 2)
    c3.children = [b31, b32, b33, b34]
    b41 = Block((12, 8), 4, (255, 211, 92), 2, 2)
    b42 = Block((8, 8), 4, (199, 44, 58), 2, 2)
    b43 = Block((8, 12), 4, (0, 0, 0), 2, 2)
    b44 = Block((12, 12), 4, (199, 44, 58), 2, 2)
    c4.children = [b41, b42, b43, b44]
    goal1 = PerimeterGoal((199, 44, 58))
    goal2 = PerimeterGoal((255, 211, 92))
    goal3 = PerimeterGoal((0, 0, 0))
    assert goal1.score(block1) == 8
    assert goal2.score(block1) == 4
    assert goal2.score(block2) == 4
    assert goal3.score(block3) == 2
    assert goal3.score(block1) == 0
コード例 #15
0
def test_JEN_smart_player_not_smart_moves(board_16x16) -> None:
    goal = PerimeterGoal((199, 44, 58))
    player = SmartPlayer(3, goal, 10)
    player._proceed = True
    move = player.generate_move(board_16x16)
    assert move is not COMBINE
    assert move is not ROTATE_CLOCKWISE
    assert move is not ROTATE_COUNTER_CLOCKWISE
    assert move is not SWAP_HORIZONTAL
    assert move is not SWAP_VERTICAL
    assert move is PASS or SMASH
コード例 #16
0
ファイル: game.py プロジェクト: Sepeghh/Bocky-Game
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        self.players = []
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)
        decider = random.randint(0, 1)
        # the random value ( 0 or 1 ) which we use it to
        # determine the goal of the game

        for i in range(num_players):
            c = COLOUR_LIST[random.randint(0, len(COLOUR_LIST) - 1)]
            # creating the random colour to assign to the player

            if decider == 0:
                # determining the random goal to the game
                goal = BlobGoal(c)
            else:
                goal = PerimeterGoal(c)

            if i < num_human:
                # first adding the human players
                self.players.append(HumanPlayer(self.renderer, i, goal))
                self.renderer.display_goal(self.players[i])
                # shows the goal of the player to him/her

            elif i < num_human + random_players:
                # adding the random players
                self.players.append(RandomPlayer(self.renderer, i, goal))
                self.renderer.display_goal(self.players[i])
                # shows the goal of the player

            else:

                level = smart_players[i - (num_human + random_players)]
                # it determines the difficulty level of the smartplayer which
                # is actualy the value of the smartplayer[index]

                # adding the smart players
                self.players.append(SmartPlayer(self.renderer, i, goal, level))
                self.renderer.display_goal(self.players[i])
                # shows the goal of the player

        self.board = random_init(0, max_depth)
        # make the board game with the given max_depth
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
コード例 #17
0
    def __init__(self, max_depth: int, num_human: int, random_players: int,
                 smart_players: List[int]) -> None:
        """Initialize this game, as described in the Assignment 2 handout.

        Precondition:
            2 <= max_depth <= 5
        """
        game_goal = []
        self.players = []
        num_players = num_human + random_players + len(smart_players)
        self.renderer = Renderer(num_players)

        # rand_num = random.randint(0, 1)
        # for i in range(num_players):
        #     game_goal.append([
        #                       PerimeterGoal(
        #                           COLOUR_LIST[random.randint(0, 3)]
        #                                     ),
        #                       BlobGoal(
        #                           COLOUR_LIST[random.randint(0, 3)]
        #                                 )
        #                       ][rand_num]
        #                      )

        if random.randint(0, 1) == 0:
            for i in range(num_players):
                game_goal.append(
                    PerimeterGoal(COLOUR_LIST[random.randint(0, 3)]))
        else:
            for i in range(num_players):
                game_goal.append(BlobGoal(COLOUR_LIST[random.randint(0, 3)]))

        self.board = random_init(0, max_depth)
        self.board.update_block_locations((0, 0), BOARD_WIDTH)
        for i in range(num_players):
            if i < num_human:
                self.players.append(HumanPlayer(self.renderer, i,
                                                game_goal[i]))
            elif i < random_players + num_human:
                self.players.append(
                    RandomPlayer(self.renderer, i, game_goal[i]))
            else:
                self.players.append(
                    SmartPlayer(self.renderer, i, game_goal[i],
                                smart_players[i - random_players - num_human]))
        for player in self.players:
            self.renderer.display_goal(player)
        # self.renderer.draw(self.board, 0)
        for i in range(num_players):
            self.renderer.draw(self.board, i)
コード例 #18
0
def test_perimeter_goal_score() -> None:
    """ Test the score method of the PerimeterGoal class. """
    goal = PerimeterGoal((255, 255, 255))

    assert goal.score(Block((0, 0), 1000, (255, 255, 255), 0, 0)) == 4

    assert goal.score(Block((0, 0), 1000, (0, 255, 255), 0, 0)) == 0

    goal2 = PerimeterGoal((0, 0, 0))
    b1 = Block((1000, 0), 500, None, 0, 2)
    b1.children = [Block((1250, 0), 250, (0, 0, 0), 1, 2),
                   Block((0, 0), 250, (0, 0, 0), 1, 2),
                   Block((0, 1250), 250, (55, 0, 0), 1, 2),
                   Block((1250, 1250), 250, None, 1, 2)]
    b1.children[3].children = [Block((1375, 0), 125, (0, 255, 0), 2, 2),
                               Block((1250, 0), 125, (0, 0, 0), 2, 2),
                               Block((1250, 1375), 125, (155, 0, 0), 2, 2),
                               Block((1375, 1375), 125, (0, 0, 0), 2, 2)]

    assert goal.score(b1) == 0
    assert goal2.score(b1) == 10
コード例 #19
0
ファイル: A2_testing_suite.py プロジェクト: jaspermai/Blocky
 def test_perimeter_goal_swap(self, board_32x32_swap0) -> None:
     goal = PerimeterGoal(COLOUR_LIST[1])
     assert goal.score(board_32x32_swap0) == 12
コード例 #20
0
ファイル: A2_testing_suite.py プロジェクト: jaspermai/Blocky
 def test_perimeter_goal_rotate(self, board_32x32_rotate1) -> None:
     goal1 = PerimeterGoal(COLOUR_LIST[2])
     goal2 = PerimeterGoal(COLOUR_LIST[3])
     assert goal1.score(board_32x32_rotate1) == 9
     assert goal2.score(board_32x32_rotate1) == 10
コード例 #21
0
 def test_perimeter_description(self):
     perimeter = PerimeterGoal(COLOUR_LIST[0])
     self.assertTrue(str(perimeter) != 'DESCRIPTION')
コード例 #22
0
def test_moves_game_board2(game_board2, renderer):
    goal1 = PerimeterGoal(COLOUR_LIST[1])
    goal2 = BlobGoal(COLOUR_LIST[1])
    renderer.draw_board(_block_to_squares(game_board2))
    renderer.save_to_file('game_board2_ref.png')
    assert goal1.score(game_board2) == 26
    assert goal2.score(game_board2) == 4 * 3 + 3 * 2 + 4 * 4 + 2 * 4**3
    lst_of_game_boards = []
    for i in range(10):
        lst_of_game_boards.append(game_board2.create_copy())
    lst_of_game_boards[0].rotate(1)
    renderer.clear()
    renderer.draw_board(_block_to_squares(lst_of_game_boards[0]))
    renderer.save_to_file("game_board_2_rotate1.png")
    assert goal1.score(lst_of_game_boards[0]) == 26
    assert goal2.score(
        lst_of_game_boards[0]) == 3 * 2 + 4 * 3 + 4**2 + 2 * 4**3
    renderer.clear()
    lst_of_game_boards[1].rotate(3)
    renderer.draw_board(_block_to_squares(lst_of_game_boards[1]))
    renderer.save_to_file("game_board_2_rotate3.png")
    assert goal1.score(lst_of_game_boards[1]) == 26
    assert goal2.score(
        lst_of_game_boards[1]) == 3 * 2 + 4 * 3 + 4**2 + 2 * 4**3
    renderer.clear()
    lst_of_game_boards[2].children[1].smash()
    renderer.draw_board(_block_to_squares(lst_of_game_boards[2]))
    renderer.save_to_file("game_board_2_smash.png")
    assert goal1.score(lst_of_game_boards[2]) == sum(
        [1, 2, 1, 1, 8, 7, 7, 2, 8])
    assert goal2.score(
        lst_of_game_boards[2]) == 2 * 4**3 + 4 + 6 + 4**2 + 4 + 4
    renderer.clear()
    lst_of_game_boards[3].swap(1)
    renderer.draw_board(_block_to_squares(lst_of_game_boards[3]))
    renderer.save_to_file("game_board_2_swap1.png")
    assert goal1.score(lst_of_game_boards[3]) == sum([8, 8, 8, 1, 1, 2, 1, 1])
    assert goal2.score(lst_of_game_boards[3]) == 4 * 4 * 4 + 4 * 4 * 2 + 4 + 3
    renderer.clear()
    lst_of_game_boards[4].swap(0)
    renderer.draw_board(_block_to_squares(lst_of_game_boards[4]))
    renderer.save_to_file("game_board_2_swap0.png")
    assert goal1.score(lst_of_game_boards[4]) == sum(
        [3, 3, 2, 4, 8, 8, 8, 4, 2])
    assert goal2.score(
        lst_of_game_boards[4]) == 4 * 2 + 3 * 2 + 4**2 + 2 * 4**3
    renderer.clear()
    assert lst_of_game_boards[5].children[0].children[0].children[0].children[
        0].paint(COLOUR_LIST[3]) == False
    lst_of_game_boards[5].children[0].children[0].children[0].children[
        0].children[0].paint(COLOUR_LIST[3])
    renderer.draw_board(_block_to_squares(lst_of_game_boards[5]))
    renderer.save_to_file("game_board_2_paint.png")
    renderer.clear()
    lst_of_game_boards[6].children[2].children[3].children[1].children[
        3].combine()
    lst_of_game_boards[6].children[2].children[3].children[1].children[
        2].combine()
    renderer.draw_board(_block_to_squares(lst_of_game_boards[6]))
    renderer.save_to_file("game_board_2_combine.png")
    assert goal1.score(lst_of_game_boards[6]) == 26
    assert goal2.score(
        lst_of_game_boards[6]) == 4 * 4 * 4 * 2 + 4 * 4 + 4 + 4 + 3 + 3 + 4
コード例 #23
0
def test_big_block():
    board = Block(0,
                  children=[
                      Block(1,
                            children=[
                                Block(2, r),
                                Block(2, g),
                                Block(2, g),
                                Block(2, g)
                            ]),
                      Block(1,
                            children=[
                                Block(2, r),
                                Block(2, r),
                                Block(2, r),
                                Block(2, r)
                            ]),
                      Block(1, b),
                      Block(1,
                            children=[
                                Block(2, g),
                                Block(2, b),
                                Block(2, r),
                                Block(2, b)
                            ])
                  ])

    board.max_depth = 2
    board.children[0].max_depth = 2
    board.children[1].max_depth = 2
    board.children[2].max_depth = 2
    board.children[3].max_depth = 2
    board.children[0].children[0].max_depth = 2
    board.children[0].children[1].max_depth = 2
    board.children[0].children[2].max_depth = 2
    board.children[0].children[3].max_depth = 2
    board.children[1].children[0].max_depth = 2
    board.children[1].children[1].max_depth = 2
    board.children[1].children[2].max_depth = 2
    board.children[1].children[3].max_depth = 2
    board.children[3].children[0].max_depth = 2
    board.children[3].children[1].max_depth = 2
    board.children[3].children[2].max_depth = 2
    board.children[3].children[3].max_depth = 2

    assert board.flatten() == [[r, r, b, b], [r, r, b, b], [g, g, b, r],
                               [r, g, g, b]]

    board.rotate(1)

    assert board.flatten() == [[b, b, r, b], [b, b, b, g], [r, r, g, g],
                               [r, r, g, r]]

    board.rotate(3)

    assert board.flatten() == [[r, r, b, b], [r, r, b, b], [g, g, b, r],
                               [r, g, g, b]]

    board.swap(0)

    assert board.flatten() == [[g, g, b, r], [r, g, g, b], [r, r, b, b],
                               [r, r, b, b]]

    board.swap(0)

    assert board.flatten() == [[r, r, b, b], [r, r, b, b], [g, g, b, r],
                               [r, g, g, b]]

    board.swap(1)

    assert board.flatten() == [[b, b, r, r], [b, b, r, r], [b, r, g, g],
                               [g, b, r, g]]

    board.swap(1)

    assert board.flatten() == [[r, r, b, b], [r, r, b, b], [g, g, b, r],
                               [r, g, g, b]]

    pr = PerimeterGoal(r)
    pg = PerimeterGoal(g)
    pb = PerimeterGoal(b)
    py = PerimeterGoal(y)
    br = BlobGoal(r)
    bg = BlobGoal(g)
    bb = BlobGoal(b)
    by = BlobGoal(y)

    assert pr.score(board) == 7
    assert pg.score(board) == 3
    assert pb.score(board) == 6
    assert py.score(board) == 0
    assert br.score(board) == 4
    assert bg.score(board) == 4
    assert bb.score(board) == 5
    assert by.score(board) == 0
コード例 #24
0
def test_single_block():
    board = Block(0, r)

    assert board.flatten() == [[r]]

    board.rotate(1)

    assert board.flatten() == [[r]]

    board.rotate(3)

    assert board.flatten() == [[r]]

    board.swap(0)

    assert board.flatten() == [[r]]

    board.swap(1)

    assert board.flatten() == [[r]]

    board.smash()

    assert board.flatten() == [[r]]

    pr = PerimeterGoal(r)
    pg = PerimeterGoal(g)
    pb = PerimeterGoal(b)
    py = PerimeterGoal(y)
    br = BlobGoal(r)
    bg = BlobGoal(g)
    bb = BlobGoal(b)
    by = BlobGoal(y)

    assert pr.score(board) == 2
    assert pg.score(board) == 0
    assert pb.score(board) == 0
    assert py.score(board) == 0
    assert br.score(board) == 1
    assert bg.score(board) == 0
    assert bb.score(board) == 0
    assert by.score(board) == 0
コード例 #25
0
def test_generate_move_random_player() -> None:
    b2 = generate_board(3, 750)
    P = RandomPlayer(2, PerimeterGoal(COLOUR_LIST[2]))
    P._proceed = True
    assert P.generate_move(b2)[0] in ['swap', 'rotate',
                                      'paint', 'combine', 'smash']
コード例 #26
0
def test_score_perimeter_goal_no_children_max_depth_3() -> None:
    b = Block((0, 0), 500, COLOUR_LIST[1], 0, 3)
    P = PerimeterGoal(COLOUR_LIST[1])
    assert P.score(b) == 32
コード例 #27
0
ファイル: test.py プロジェクト: Fenil-P/Blocky
 def test_PG_no_corner(self) -> None:
     gol = PerimeterGoal(REAL_RED)
     borde = standard_borde()
     assert gol.score(borde) == 4
コード例 #28
0
def test_mixed_big_block():
    board = Block(
        0, children=[Block(1, r),
                     Block(1, r),
                     Block(1, g),
                     Block(1, r)])

    board.max_depth = 1
    board.children[0].max_depth = 1
    board.children[1].max_depth = 1
    board.children[2].max_depth = 1
    board.children[3].max_depth = 1

    print(board.flatten())

    assert board.flatten() == [[r, g], [r, r]]

    board.rotate(1)

    assert board.flatten() == [[g, r], [r, r]]

    board.rotate(3)

    assert board.flatten() == [[r, g], [r, r]]

    board.swap(0)

    assert board.flatten() == [[r, r], [r, g]]

    board.swap(0)

    assert board.flatten() == [[r, g], [r, r]]

    board.swap(1)

    assert board.flatten() == [[g, r], [r, r]]

    board.swap(1)

    assert board.flatten() == [[r, g], [r, r]]

    board.smash()

    assert board.flatten() == [[r, g], [r, r]]

    pr = PerimeterGoal(r)
    pg = PerimeterGoal(g)
    pb = PerimeterGoal(b)
    py = PerimeterGoal(y)
    br = BlobGoal(r)
    bg = BlobGoal(g)
    bb = BlobGoal(b)
    by = BlobGoal(y)

    assert pr.score(board) == 6
    assert pg.score(board) == 2
    assert pb.score(board) == 0
    assert py.score(board) == 0
    assert br.score(board) == 3
    assert bg.score(board) == 1
    assert bb.score(board) == 0
    assert by.score(board) == 0
コード例 #29
0
def test_perimeter_goal_description() -> None:
    """ Test the PerimeterGoal class' description method. """
    g1 = PerimeterGoal((1, 128, 181))

    assert isinstance(g1.description(), str)
コード例 #30
0
ファイル: test.py プロジェクト: Fenil-P/Blocky
 def test_PG_with_corner(self) -> None:
     gol = PerimeterGoal(DAFFODIL_DELIGHT)
     borde = standard_borde()
     assert gol.score(borde) == 10