Exemplo n.º 1
0
def test_get_block_bottom_right(board_16x16) -> None:
    bottom_right = (board_16x16.size, board_16x16.size)
    middle = (round(board_16x16.size / 2), round(board_16x16.size / 2))
    board = _get_block(board_16x16, bottom_right, 0)
    board3 = _get_block(board_16x16, middle, 1)
    assert board is None
    assert board3 == board_16x16.children[3]
Exemplo n.º 2
0
   def test_get_block_2(self):
       """
       (0, 0)      (50, 0) (75, 0) (99, 0)
           ___________________________
           |            |      |      |
           |    (50, 25)|______|______| (99, 25)
           |            |      |      |
 (0, 50)   |____________|______|______| (99, 50)
           |            |             |
           |            |             |
           |            |             |
           |____________|_____________| (99, 99)
       """
       for i in range(50):
           for j in range(50):
               temp = _get_block(self.one_internal, (i, j), 1)
               self.assertBlock(temp, [(0, 0), 50, (80, 80, 80), 1, 2, 0],
                                True, True)
       for i in range(50, 100):
           for j in range(0, 50):
               temp = _get_block(self.one_internal, (i, j), 1)
               self.assertBlock(temp, [(50, 0), 50, None, 1, 2, 4], False,
                                False)
       for i in range(50):
           for j in range(50, 100):
               temp = _get_block(self.one_internal, (i, j), 1)
               self.assertBlock(temp, [(0, 50), 50, (70, 70, 70), 1, 2, 0],
                                True, True)
       for i in range(50, 100):
           for j in range(50, 100):
               temp = _get_block(self.one_internal, (i, j), 1)
               self.assertBlock(temp, [(50, 50), 50, (60, 60, 60), 1, 2, 0],
                                True, True)
 def test_get_block_top_left(self, board_16x16) -> None:
     """Test that the correct block is retrieved from the reference board
     when requesting the top-left corner of the board.
     """
     top_left = (0, 0)
     assert _get_block(board_16x16, top_left, 0) == board_16x16
     assert _get_block(board_16x16, top_left, 1) == board_16x16.children[1]
Exemplo n.º 4
0
def test_get_block(board_16x16) -> None:
    new_block = _get_block(board_16x16, (0, 0), 1)
    assert new_block.colour == COLOUR_LIST[1]
    assert new_block.level == 1
    block2 = _get_block(board_16x16, (350, 0), 8)
    assert block2.colour == COLOUR_LIST[1]
    assert block2.level == 1
Exemplo n.º 5
0
def test_get_block_top_top_left(board_16x16) -> None:
    top_left = (0, 0)
    board0 = _get_block(board_16x16, top_left, 0)
    board1 = _get_block(board_16x16, top_left, 1)
    board2 = _get_block(board_16x16, top_left, 2)
    assert board0 == board_16x16
    assert board1 == board_16x16.children[1]
    assert board2 is None
 def test_get_block_top_right(self, board_16x16) -> None:
     """Test that the correct block is retrieved from the reference board
     when requesting the top-right corner of the board.
     """
     top_right = (board_16x16.size - 1, 0)
     assert _get_block(board_16x16, top_right, 0) == board_16x16
     assert _get_block(board_16x16, top_right, 1) == board_16x16.children[0]
     assert _get_block(board_16x16, top_right, 2) == \
         board_16x16.children[0].children[0]
 def test_get_block_bottom_right(self, board_16x16) -> None:
     """Test that the correct block is retrieved from the reference board
     when requesting the bottom-right corner of the board.
     """
     bottom_right = (board_16x16.size - 1, board_16x16.size - 1)
     assert _get_block(board_16x16, bottom_right, 0) == board_16x16
     assert _get_block(board_16x16, bottom_right, 1) == board_16x16.children[3]
     assert _get_block(board_16x16, bottom_right, 2) == \
         board_16x16.children[3] # Works when children are defined
Exemplo n.º 8
0
def player_playground():
    from player import RandomPlayer, SmartPlayer, create_players, _get_block
    b = block_three_level1()

    found = _get_block(b, (0, 0), 0)
    print(block_graph(found))

    found = _get_block(b, (0, 0), 1)
    print(block_graph(found))

    players = create_players(1, 1, [10])
    print(players)
Exemplo n.º 9
0
def test_get_block_middle(board_16x16) -> None:
    middle = (round(board_16x16.size / 2), 0)
    board0 = _get_block(board_16x16, middle, 0)
    board1 = _get_block(board_16x16, middle, 1)
    board2 = _get_block(board_16x16, middle, 2)
    board3 = _get_block(board_16x16, middle, 3)
    board4 = _get_block(board_16x16, middle, 4)
    assert board0 == board_16x16
    assert board1 == board_16x16.children[0]
    assert board2 == board_16x16.children[0].children[1]
    assert board3 == board_16x16.children[0].children[1].children[1]
    assert board4 is None
Exemplo n.º 10
0
def test_depth_5_board(renderer):
    random.seed(1002)
    board = generate_board(5, BOARD_SIZE)
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_ref.png')
    renderer.clear()
    goal1 = BlobGoal(COLOUR_LIST[0])  # blue
    goal2 = BlobGoal(COLOUR_LIST[1])  # red
    player1 = RandomPlayer(1, goal1)
    player2 = RandomPlayer(2, goal2)
    player1._proceed = True
    move1 = player1.generate_move(board)
    move1_block = move1[2]
    to_do = _get_block(board, move1_block.position, move1_block.level)
    assert move1[0] == "swap" and move1[1] == 0
    assert to_do.swap(0)
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_move1.png')
    renderer.clear()
    afterfirst1 = goal1.score(board)
    afterfirst2 = goal2.score(board)
    player2._proceed = True
    move2 = player2.generate_move(board)
    move2_block = move2[2]
    to_do_2 = _get_block(board, move2_block.position, move2_block.level)
    assert move2[0] == "smash"
    assert to_do_2.smash()
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_move2.png')
    renderer.clear()
    aftersecond1 = goal1.score(board)
    aftersecond2 = goal2.score(board)
    player1._proceed = True
    move3 = player1.generate_move(board)
    move3_block = move3[2]
    to_do_3 = _get_block(board, move3_block.position, move3_block.level)
    assert move3[0] == "rotate" and move3[1] == 3
    assert to_do_3.rotate(3)
    renderer.draw_board(_block_to_squares(board))
    renderer.save_to_file('board_5_move3.png')
    renderer.clear()
    afterthird1 = goal1.score(board)
    afterthird2 = goal2.score(board)
Exemplo n.º 11
0
 def test_get_block_1(self):
     """
 (10, 10)        (19, 10)
     ____________
     |           |
     |           |
     |___________|
 (10, 19)        (19, 19)
     """
     block = self.leaf_block
     corners = [(10, 10), (19, 10), (10, 19), (19, 19)]
     for corner in corners:
         act = _get_block(block, corner, 0)
         self.assertBlock(act, [(10, 10), 10, (10, 10, 10), 0, 0, 0], True, True)
     outbounds = [9, 20, 20, 100]
     for outbound in outbounds:
         for i in range(100):
             act = _get_block(block, (outbound, i), 0)
             self.assertIsNone(act, "The coordinates are out of bound you should return None")
Exemplo n.º 12
0
def test__get_block() -> None:
    """Test _get_block and my helper function _location_in_block.
    - helper:
    - when location is in block
    - when location is not in block
    - when location is on the edge of a block
    - function:
    - base case
    - children case
    """
    block = Block((0, 0), 100, (0, 0, 0), 0, 1)
    l1 = (50, 50)
    l2 = (200, 200)
    l3 = (100, 0)
    l4 = (99, 0)
    l5 = (0, 100)
    l6 = (30, 100)
    assert _location_in_block(block, l1)
    assert _location_in_block(block, l2) is False
    assert _location_in_block(block, l3) is False
    assert _location_in_block(block, l4)
    assert _location_in_block(block, l5) is False
    assert _location_in_block(block, l6) is False
    assert _get_block(block, l1, 1) == block
    assert _get_block(block, l2, 0) is None
    assert block.smash()
    child = _get_block(block, l1, 1)
    assert child == block.children[3]
    assert _get_block(block, l1, 0) == block
    assert _get_block(block, l2, 1) is None
    new_block = Block((0, 0), 100, (0, 0, 0), 0, 3)
    assert new_block.smash()
    child = _get_block(new_block, (60, 70), 2)
    assert child.level >= 1
Exemplo n.º 13
0
def test_get_block() -> None:
    block = Block((0, 0), 16, None, 0, 5)
    b1 = Block((8, 0), 8, (1, 128, 181), 1, 5)
    b2 = Block((0, 0), 8, (199, 44, 58), 1, 5)
    b3 = Block((0, 8), 8, None, 1, 5)
    b4 = Block((8, 8), 8, (255, 211, 92), 1, 5)
    block.children = [b1, b2, b3, b4]
    b31 = Block((4, 8), 4, (1, 128, 181), 2, 5)
    b32 = Block((0, 8), 4, (199, 44, 58), 2, 5)
    b33 = Block((0, 12), 4, (255, 211, 92), 2, 5)
    b34 = Block((4, 12), 4, (199, 44, 58), 2, 5)
    b3.children = [b31, b32, b33, b34]
    x = _get_block(block, (3, 7), 2)
    y = _get_block(block, (7, 10), 2)
    a = _get_block(block, (8, 8), 1)
    b = _get_block(block, (16, 8), 1)
    z = _get_block(block, (15, 13), 5)
    assert b is None
    assert a.position == (8, 8)
    assert y.position == (4, 8)
    assert x.position == (0, 0)
    assert z.position == (8, 8)
Exemplo n.º 14
0
 def test_get_block_level_none5(self, board_32x32) -> None:
     get_block = _get_block(board_32x32, (244, 750), 0)
     assert get_block is None
Exemplo n.º 15
0
   def test_get_block_3(self):
       """
       (0, 0)      (50, 0) (75, 0) (99, 0)
           ___________________________
           |            |      |      |
           |    (50, 25)|______|______| (99, 25)
           |            |      |      |
 (0, 50)   |____________|______|______| (99, 50)
           |            |             |
           |            |             |
           |            |             |
           |____________|_____________| (99, 99)
       """
       act = _get_block(self.one_internal, (50, 0), 0)
       self.assertBlock(act, [(0, 0), 100, None, 0, 2, 4], False, False)
       act1 = _get_block(self.one_internal, (50, 0), 1)
       self.assertBlock(act1, [(50, 0), 50, None, 1, 2, 4], False, False)
       act2 = _get_block(self.one_internal, (49, 0), 1)
       self.assertBlock(act2, [(0, 0), 50, (80, 80, 80), 1, 2, 0], True, True)
       act3 = _get_block(self.one_internal, (49, 50), 1)
       self.assertBlock(act3, [(0, 50), 50, (70, 70, 70), 1, 2, 0], True,
                        True)
       act4 = _get_block(self.one_internal, (50, 50), 1)
       self.assertBlock(act4, [(50, 50), 50, (60, 60, 60), 1, 2, 0], True,
                        True)
       act5 = _get_block(self.one_internal, (75, 0), 2)
       self.assertBlock(act5, [(75, 0), 25, (40, 40, 40), 2, 2, 0], True,
                        True)
       act6 = _get_block(self.one_internal, (75, 25), 2)
       self.assertBlock(act6, [(75, 25), 25, (10, 10, 10), 2, 2, 0], True,
                        True)
       act7 = _get_block(self.one_internal, (99, 25), 2)
       self.assertBlock(act7, [(75, 25), 25, (10, 10, 10), 2, 2, 0], True,
                        True)
       act8 = _get_block(self.one_internal, (74, 25), 2)
       self.assertBlock(act8, [(50, 25), 25, (20, 20, 20), 2, 2, 0], True,
                        True)
       act9 = _get_block(self.one_internal, (50, 0), 2)
       self.assertBlock(act9, [(50, 0), 25, (30, 30, 30), 2, 2, 0], True,
                        True)
       act11 = _get_block(self.one_internal, (75, 25), 1)
       self.assertBlock(act11, [(50, 0), 50, None, 1, 2, 4], False, False)
       act10 = _get_block(self.one_internal, (50, 50), 2)
       self.assertBlock(act10, [(50, 50), 50, None, 1, 2, 0], False, False)
Exemplo n.º 16
0
 def test_get_block_level_under(self, board_32x32) -> None:
     get_block = _get_block(board_32x32, (0, 0), 2)
     assert get_block == Block((0, 0), 375, COLOUR_LIST[2], 1, 3)
Exemplo n.º 17
0
def test_get_block_middle2(board_16x16) -> None:
    middle = (round(board_16x16.size / 2) + round(board_16x16.size / 8), round(board_16x16.size / 8))
    board = _get_block(board_16x16, middle, 3)
    assert board == board_16x16.children[0].children[1].children[3]
Exemplo n.º 18
0
 def test_get_block(self, board_32x32) -> None:
     get_block = _get_block(board_32x32, (0, 0), 1)
     the_block = Block((0, 0), 375, COLOUR_LIST[2], 1, 3)
     assert get_block == the_block
Exemplo n.º 19
0
 def test_get_block_max_level(self) -> None:
     borde = standard_borde()
     # print(_get_block(borde, (50, 50), 3))
     assert _get_block(borde, (50, 50), 3) is None
Exemplo n.º 20
0
 def test_get_block_level_0(self) -> None:
     borde = standard_borde()
     assert _get_block(borde, (0, 0), 0) == borde
Exemplo n.º 21
0
 def test_get_block_level_none4(self, board_32x32) -> None:
     get_block = _get_block(board_32x32, (750, 375), 0)
     assert get_block is None
Exemplo n.º 22
0
 def test_get_block_middle(self, board_2x2) -> None:
     middle = (board_2x2.size / 2, board_2x2.size / 2)
     assert _get_block(board_2x2, middle, 0) == board_2x2
     assert _get_block(board_2x2, middle, 1) == board_2x2.children[3]
Exemplo n.º 23
0
 def test_get_block_middle1(self, board_2x2_2) -> None:
     middle = (board_2x2_2.size / 2, board_2x2_2.size / 2)
     left_middle = (0, board_2x2_2.size / 2)
     assert _get_block(board_2x2_2, middle, 2) == board_2x2_2.children[3]
     assert _get_block(board_2x2_2, left_middle) == board_2x2_2.children[2]
Exemplo n.º 24
0
    def test_get_block(self) -> None:
        single_block = Block((0, 0), 16, (0, 0, 0), 0, 0)
        one_level = Block((0, 0), 16, None, 0, 1)
        one_level_upper_left = Block((0, 0), 8, None, 1, 1)
        one_level_upper_right = Block((8, 0), 8, PACIFIC_POINT, 1, 1)
        one_level_lower_left = Block((0, 8), 8, DAFFODIL_DELIGHT, 1, 1)
        one_level_lower_right = Block((8, 8), 8, BLACK, 1, 1)
        lul = Block((0, 0), 4, BLACK, 1, 1)
        lur = Block((4, 0), 4, PACIFIC_POINT, 1, 1)
        lll = Block((0, 4), 4, DAFFODIL_DELIGHT, 1, 1)
        llr = Block((4, 4), 4, WHITE, 1, 1)
        one_level.children = [
            one_level_upper_right, one_level_upper_left, one_level_lower_left,
            one_level_lower_right
        ]
        one_level_upper_left.children = [lur, lul, lll, llr]

        assert None == _get_block(single_block, (16, 5), 0)
        assert None == _get_block(single_block, (5, 16), 0)
        assert single_block == _get_block(single_block, (0, 5), 0)
        assert single_block == _get_block(single_block, (5, 0), 0)
        assert single_block == _get_block(single_block, (5, 5), 0)
        assert single_block == _get_block(single_block, (5, 5), 0)
        assert one_level == _get_block(one_level, (0, 0), 0)
        assert one_level_upper_left == _get_block(one_level, (0, 0), 1)
        assert one_level_upper_right == _get_block(one_level, (8, 0), 1)
        assert one_level_lower_left == _get_block(one_level, (0, 8), 1)
        assert one_level_lower_right == _get_block(one_level, (8, 8), 1)
        assert one_level_upper_left == _get_block(one_level, (1, 5), 1)
        assert one_level_upper_right == _get_block(one_level, (9, 5), 1)
        assert one_level_lower_left == _get_block(one_level, (4, 14), 1)
        assert one_level_lower_right == _get_block(one_level, (13, 9), 1)

        assert lul == _get_block(one_level, (0, 0), 2)
        assert lur == _get_block(one_level, (4, 0), 2)
        assert lll == _get_block(one_level, (0, 4), 2)
        assert llr == _get_block(one_level, (4, 4), 2)
        assert lul == _get_block(one_level, (3, 2), 2)
        assert lur == _get_block(one_level, (5, 3), 2)
        assert lll == _get_block(one_level, (3, 6), 2)
        assert llr == _get_block(one_level, (5, 7), 2)
Exemplo n.º 25
0
 def test_get_block_board(self, board_32x32) -> None:
     get_block = _get_block(board_32x32, (35, 127), 0)
     assert get_block == board_32x32
Exemplo n.º 26
0
def test_get_block() -> None:
    """ Test the _get_block function. """
    b1 = Block((0, 0), 500, (255, 0, 0), 0, 3)

    assert _get_block(b1, (55, 75), 0) is b1

    assert _get_block(b1, (0, 0), 0) is b1

    assert _get_block(b1, (500, 425), 0) is None

    assert _get_block(b1, (55, 75), 5) is b1

    b2 = Block((0, 0), 1000, None, 0, 2)
    b2.children = [Block((500, 0), 500, (255, 0, 0), 1, 2),
                   Block((0, 0), 500, (255, 255, 0), 1, 2),
                   Block((0, 500), 500, (255, 0, 255), 1, 2),
                   Block((500, 500), 500, (0, 0, 255), 1, 2)]

    b2.children[1].colour = None

    b2.children[1].children = [Block((250, 0), 250, (0, 0, 0), 2, 2),
                               Block((0, 0), 250, (0, 255, 0), 2, 2),
                               Block((0, 250), 250, (255, 255, 255), 2, 2),
                               Block((250, 250), 250, (0, 255, 255), 2, 2)]

    assert _get_block(b2, (288, 22), 0) is b2

    assert _get_block(b2, (51, 155), 2) is b2.children[1].children[1]

    assert _get_block(b2, (51, 243), 1) is b2.children[1]

    assert _get_block(b2, (1, 1000), 1) is None

    assert _get_block(b2, (250, 1000), 1) is None

    assert _get_block(b2, (250, 16), 2) is b2.children[1].children[0]

    assert _get_block(b2, (550, 670), 2) is b2.children[3]
Exemplo n.º 27
0
 def test_get_block_corner(self, board_32x32) -> None:
     get_block = _get_block(board_32x32, (376, 376), 1)
     the_block = Block((375, 375), 375, COLOUR_LIST[3], 1, 3)
     assert get_block == the_block