Exemple #1
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
Exemple #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')
Exemple #3
0
def test_big_single_block():
    board = Block(
        0, children=[Block(1, r),
                     Block(1, r),
                     Block(1, r),
                     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

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

    board.rotate(1)

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

    board.rotate(3)

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

    board.swap(0)

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

    board.swap(1)

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

    board.smash()

    assert board.flatten() == [[r, r], [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) == 8
    assert pg.score(board) == 0
    assert pb.score(board) == 0
    assert py.score(board) == 0
    assert br.score(board) == 4
    assert bg.score(board) == 0
    assert bb.score(board) == 0
    assert by.score(board) == 0
Exemple #4
0
 def test_PG_no_perimeter(self) -> None:
     gol = PerimeterGoal(DAFFODIL_DELIGHT)
     borde = standard_borde()
     borde.children[1] = Block((0, 0), 200, OLD_OLIVE, 1, 3)
     borde.children[0].children[3] = \
         Block((300, 100), 100, OLD_OLIVE, 2, 3)
     assert gol.score(borde) == 0
Exemple #5
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
Exemple #6
0
    def test_perimeter_goal_2(self, child_block):
        correct_scores = [(COLOUR_LIST[0], 4), (COLOUR_LIST[1], 0),
                          (COLOUR_LIST[2], 0), (COLOUR_LIST[3], 0)]

        # Set up a goal for each colour and check results.
        for colour, expected in correct_scores:
            goal = PerimeterGoal(colour)
            assert goal.score(child_block) == expected
    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
Exemple #8
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
Exemple #9
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
Exemple #10
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
Exemple #11
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
Exemple #12
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
Exemple #13
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
Exemple #14
0
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)))
Exemple #15
0
 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
Exemple #16
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
Exemple #17
0
 def test_perimeter_goal(self, board_32x32) -> None:
     goal = PerimeterGoal(COLOUR_LIST[2])
     assert goal.score(board_32x32) == 9
Exemple #18
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
Exemple #19
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
class TestPerimeterGoal(A2TestStep6):
    def setUp(self) -> None:
        super().setUp()
        self.goal_colour = None
        self.goal = PerimeterGoal(self.goal_colour)
        self.set_colour = lambda colour: setattr(self.goal, "colour", colour)

    def tearDown(self) -> None:
        super().tearDown()
        self.goal_colour = None
        self.goal = PerimeterGoal(self.goal_colour)
        self.set_colour = lambda colour: setattr(self.goal, "colour", colour)

    def test_goal_1(self):
        """
             ____________
            |           |
            |           |
            |___________|
        colour:(10, 10, 10)
        """
        for i in range(100, 200):
            self.goal_colour = (i, i, i)
            self.goal.colour = self.goal_colour
            res = self.goal.score(self.leaf_block)
            self.assertEqual(
                0, res,
                "You shoud return 0 since the colour of the block is not equal to the colour of the parameter"
            )

    def test_goal_2(self):
        """
            ____________
            |           |
            |           |
            |___________|
        colour:(10, 10, 10)
        Expected Return Value 4
        Piazza Id:1780
        """
        self.set_colour((10, 10, 10))
        res = self.goal.score(self.leaf_block)
        self.assertEqual(
            4, res,
            "You should return 4 since every corner is touched and every corner has the same colour of the target colour"
        )

    def test_goal_3(self):
        """
            ____________
            |           |
            |           |
            |___________|
        colour:(10, 10, 10)
        """

        self.set_colour((10, 10, 10))
        exps = [8, 16, 32, 64, 128, 256, 512, 1024, 2048]
        res = []
        for i in range(1, 10):
            self.leaf_block.max_depth = i
            res.append(self.goal.score(self.leaf_block))
        self.assertEqual(exps, res)

    def test_goal_4(self):
        """
        (0, 0, (30, 30, 30))      (5, 0, (20, 20, 20))
                        ___________________________
                        |            |             |
                        |            |             |
                        |            |             |
            (0, 5, (40, 40, 40))           (5, 5, (50, 50, 50))
                        |____________|____________ |
                        |            |             |
                        |            |             |
                        |            |             |
                        |____________|_____________|
        """
        corner_colours = [(i, i, i) for i in range(20, 60, 10)]
        for colour in corner_colours:
            self.set_colour(colour)
            res = self.goal.score(self.one_level)
            exp = 2
            self.assertEqual(
                exp, res, "Every corner count twice so you should return 2")
        self.set_colour((20, 20, 20))
        for i in range(4):
            self.one_level.children[i].colour = (20, 20, 20)
            res = self.goal.score(self.one_level)
            exp = 2 * (i + 1)
            self.assertEqual(exp, res,
                             "You should accumulate the count of the corner")
        self.one_level.combine()
        res = self.goal.score(self.one_level)
        exp = 8
        self.assertEqual(exp, res)

    def test_goal_5(self):
        """
            E_____________B_____A______
            |            |      |      |
            |            C _____D______|
            |            |/ /  /|      |
            F___________G|/_/_/_|______|
            |            |             |
            |            |             |
            |            |             |
            |____________|_____________|
            A:(75, 0, (40, 40, 40))
            B:(50, 0, (30, 30, 30))
            C:(50, 25, (20, 20, 20))
            D:(75, 25, (10, 10, 10))
            E:(0, 0, (80, 80, 80))
            F:(0, 50, (70, 70, 70))
            G:(50, 50, (60, 60, 60))
        """
        self.set_colour((20, 20, 20))
        exp = 0
        res = self.goal.score(self.one_internal)
        self.assertEqual(
            exp, res,
            "The block not in the outside of the board does not count to the score"
        )

    def test_goal_6(self):
        """
            E____________B_____A______
            |/  /  /   / |/ / / |/ / / |
            |/  /  /   / C/ /_/_D______|
            |/  /  /  /  |/ / / |      |
            F/__/__/__/__G/_/_/_|______|
            |            |             |
            |            |             |
            |            |             |
            |____________|_____________|
            A:(75, 0, (80, 80, 80))
            B:(50, 0, (80, 80, 80))
            C:(50, 25, (80, 80, 80))
            D:(75, 25, (10, 10, 10))
            E:(0, 0, (80, 80, 80))
            F:(0, 50, (70, 70, 70))
            G:(50, 0, (60, 60, 60))
        """
        self.set_colour((80, 80, 80))
        for i in range(3):
            self.one_internal.children[0].children[i].colour = (80, 80, 80)
        res = self.goal.score(self.one_internal)
        exp = 7
        self.assertEqual(exp, res, "score of E = 4, B = 1, A = 2")

    def test_goal_7(self):
        """
                        F_____E______B_______A______
                        |     |      |       |      |
                        G_____H______C_______D______|
                        |     |/ / / |/ / / /|      |
                        J_____I/_/_/_N/__/__/M______|
                        |     |/ / / |/ / /  |      |
                        K_____L/_/_/_O/_/_/__P______|
                        |     |      |       |      |
                        |_____|______|_______|______|
        A:(40, 40, 40)
        B:(30, 30, 30)
        C:(20, 20, 20)
        D:(10, 10, 10)
        E:(50, 50, 50)
        F:(40, 40, 40)
        G:(30, 30, 30)
        H:(20, 20, 20)
        I:(20, 20, 20)
        J:(30, 30, 30)
        K:(40, 40, 40)
        L:(50, 50, 50)
        M:(10, 10, 10)
        N:(20, 20, 20)
        O:(30, 30, 30)
        P:(40, 40, 40)
        """
        self.set_colour((20, 20, 20))
        self.set_children(self.one_internal.children[1],
                          [(i, i, i) for i in range(50, 10, -10)])
        self.set_children(self.one_internal.children[2],
                          [(i, i, i) for i in range(20, 60, 10)])
        self.set_children(self.one_internal.children[3],
                          [(i, i, i) for i in range(10, 50, 10)])
        exp = 0
        res = self.goal.score(self.one_internal)
        self.assertEqual(
            exp, res,
            "The blocks not in the outside of the board does not count")

    def test_goal_8(self):
        """
                        F_____E______B_______A______
                        |     |      |/ / / /|      |
                        G_____H______C_______D______|
                        |     |/ / / |       |      |
                        J_____I/_/_/_N_______M______|
                        |     |      |/ / /  |      |
                        K_____L______O/_/_/__P______|
                        |     |/ / / |       |      |
                        |_____|/_/_/_|_______|______|
        A:(40, 40, 40)
        B:(30, 30, 30)
        C:(20, 20, 20)
        D:(10, 10, 10)
        E:(60, 60, 60)
        F:(50, 50, 50)
        G:(40, 40, 40)
        H:(30, 30, 30)
        I:(60, 60, 60)
        J:(50, 50, 50)
        K:(40, 40, 40)
        L:(30, 30, 30)
        M:(40, 40, 40)
        N:(30, 30, 30)
        O:(20, 20, 20)
        P:(10, 10, 10)
        """
        self.set_colour((30, 30, 30))
        self.set_children(self.one_internal.children[1],
                          [(i, i, i) for i in range(60, 20, -10)])
        self.set_children(self.one_internal.children[2],
                          [(i, i, i) for i in range(60, 20, -10)])
        self.set_children(self.one_internal.children[3],
                          [(i, i, i) for i in range(40, 0, -10)])
        exp = 2
        res = self.goal.score(self.one_internal)
        self.assertEqual(exp, res, "B = 1, L  = 1")

    def test_score_9(self):
        """
                                F_____E______B_______A______
                                |     |      |       |      |
                                G_____H______C_______D______|
                                |     |      |       |      |
                                J_____I______N_______M______|
                                |     |/ / / |/ / /  |      |
                                K_____L/_/_/_O/_/_/__P______|
                                |/ / /|      |       |/ / / |
                                |/ /_/|______|_______|/_/_/_|
                A:(40, 40, 40)
                B:(30, 30, 30)
                C:(20, 20, 20)
                D:(10, 10, 10)
                E:(60, 60, 60)
                F:(50, 50, 50)
                G:(40, 40, 40)
                H:(30, 30, 30)
                I:(100, 100, 100)
                J:(200, 200, 200)
                K:(100, 100, 100)
                L:(200, 200, 200)
                M:(200, 200, 200)
                N:(100, 100, 100)
                O:(200, 200, 200)
                P:(100, 100, 100)
                """
        self.set_colour((100, 100, 100))
        self.set_children(self.one_internal.children[1],
                          [(i, i, i) for i in range(60, 20, -10)])
        self.set_children(self.one_internal.children[2],
                          [(i, i, i) for i in range(100, 500, 100)])
        self.set_children(self.one_internal.children[3],
                          [(i, i, i) for i in range(100, 500, 100)])
        self.one_internal.children[2].children[2].colour = (100, 100, 100)
        self.one_internal.children[2].children[3].colour = (200, 200, 200)
        self.one_internal.children[3].children[0].colour = (200, 200, 200)
        self.one_internal.children[3].children[1].colour = (100, 100, 100)
        self.one_internal.children[3].children[2].colour = (200, 200, 200)
        self.one_internal.children[3].children[3].colour = (100, 100, 100)
        exp = 4
        res = self.goal.score(self.one_internal)
        self.assertEqual(exp, res, "K = 2, P  = 2")

    def test_score_10(self):
        """
                                F_____E______B_______A______
                                |     |      |       |      |
                                G_____H______C_______D______|
                                |     |      |       |      |
                                J_____I______N_______M______|
                                |     |/ / / |       |/ / / |
                                K_____L/_/_/_O_______P/_/_/_|
                                |/ / /|      |/ / /  |      |
                                |/ /_/|______|/_/_/__|______|
                A:(40, 40, 40)
                B:(30, 30, 30)
                C:(20, 20, 20)
                D:(10, 10, 10)
                E:(60, 60, 60)
                F:(50, 50, 50)
                G:(40, 40, 40)
                H:(30, 30, 30)
                I:(100, 100, 100)
                J:(200, 200, 200)
                K:(100, 100, 100)
                L:(200, 200, 200)
                M:(100, 100, 100)
                N:(200, 200, 200)
                O:(100, 100, 100)
                P:(200, 200, 200)
        """
        self.set_colour((100, 100, 100))
        self.set_children(self.one_internal.children[1],
                          [(i, i, i) for i in range(60, 20, -10)])
        self.set_children(self.one_internal.children[2],
                          [(i, i, i) for i in range(100, 500, 100)])
        self.set_children(self.one_internal.children[3],
                          [(i, i, i) for i in range(100, 500, 100)])
        self.one_internal.children[2].children[2].colour = (100, 100, 100)
        self.one_internal.children[2].children[3].colour = (200, 200, 200)
        self.one_internal.children[3].children[2].colour = (100, 100, 100)
        self.one_internal.children[3].children[3].colour = (200, 200, 200)
        exp = 4
        res = self.goal.score(self.one_internal)
        self.assertEqual(exp, res, "K = 2, M  = 1, O = 1")

    def test_goal_11(self):
        """
                        F_____E______B_______A______
                        |/ / /|      |       |      |
                        G/_/_/H______C_______D______|
                        |     |/ / / |       |      |
                        J_____I/_/_/_N_______M______|
                        |     |      |/ / /  |      |
                        K_____L______O/_/_/__P______|
                        |     |      |       |/ / / |
                        |_____|______|_______|/_/_/_|
        A:(40, 40, 40)
        B:(30, 30, 30)
        C:(20, 20, 20)
        D:(10, 10, 10)
        E:(100, 100, 100)
        F:(200, 200, 200)
        G:(100, 100, 100)
        H:(200, 200, 200)
        I:(60, 60, 60)
        J:(50, 50, 50)
        K:(40, 40, 40)
        L:(30, 30, 30)
        M:(100, 100, 100)
        N:(200, 200, 200)
        O:(100, 100, 100)
        P:(200, 200, 200)
        """
        self.set_colour((200, 200, 200))
        self.set_children(self.one_internal.children[1],
                          [(i, i, i) for i in range(100, 500, 100)])
        self.set_children(self.one_internal.children[2],
                          [(i, i, i) for i in range(60, 20, -10)])
        self.set_children(self.one_internal.children[3],
                          [(i, i, i) for i in range(100, 500, 100)])
        self.one_internal.children[1].children[0].colour = (100, 100, 100)
        self.one_internal.children[1].children[1].colour = (200, 200, 200)
        self.one_internal.children[1].children[2].colour = (100, 100, 100)
        self.one_internal.children[1].children[3].colour = (200, 200, 200)
        self.one_internal.children[3].children[0].colour = (100, 100, 100)
        self.one_internal.children[3].children[1].colour = (200, 200, 200)
        self.one_internal.children[3].children[2].colour = (100, 100, 100)
        self.one_internal.children[3].children[3].colour = (200, 200, 200)
        exp = 4
        res = self.goal.score(self.one_internal)
        self.assertEqual(exp, res, "F = 2, P = 2")

    def test_goal_12(self):
        """
                                F_____E______B_______A______
                                |/ / /|      |       |/ / / |
                                G/_/_/H______C_______D/_/_/_|
                                |     |      |       |      |
                                J_____I______N_______M______|
                                |     |      |       |      |
                                K_____L______O_______P______|
                                |/ / /|      |       |/ / / |
                                |/ /_/|______|_______|/_/_/_|
                A:(40, 40, 40)
                B:(30, 30, 30)
                C:(20, 20, 20)
                D:(10, 10, 10)
                E:(50, 50, 50)
                F:(40, 40, 40)
                G:(30, 30, 30)
                H:(20, 20, 20)
                I:(60, 60, 60)
                J:(50, 50, 50)
                K:(40, 40, 40)
                L:(30, 30, 30)
                M:(70, 70, 70)
                N:(60, 60, 60)
                O:(50, 50, 50)
                P:(40, 40, 40)
        """
        self.set_colour((40, 40, 40))
        self.set_children(self.one_internal.children[1],
                          [(i, i, i) for i in range(50, 10, -10)])
        self.set_children(self.one_internal.children[2],
                          [(i, i, i) for i in range(60, 20, -10)])
        self.set_children(self.one_internal.children[3],
                          [(i, i, i) for i in range(70, 30, -10)])
        exp = 8
        res = self.goal.score(self.one_internal)
        self.assertEqual(
            exp, res,
            "Every corner counts twice so in total you need to have 4 * 2 = 8")
Exemple #21
0
 def test_PG_with_corner(self) -> None:
     gol = PerimeterGoal(DAFFODIL_DELIGHT)
     borde = standard_borde()
     assert gol.score(borde) == 10
Exemple #22
0
 def test_PG_no_corner(self) -> None:
     gol = PerimeterGoal(REAL_RED)
     borde = standard_borde()
     assert gol.score(borde) == 4
Exemple #23
0
 def test_perimeter_goal_swap(self, board_32x32_swap0) -> None:
     goal = PerimeterGoal(COLOUR_LIST[1])
     assert goal.score(board_32x32_swap0) == 12