def test_blob_goal_score() -> None: """ Test the BlobGoal class' score method. """ goal = BlobGoal((255, 255, 255)) assert goal.score(Block((0, 0), 250, (255, 255, 255), 0, 0)) == 1 board = Block((0, 0), 1000, None, 0, 2) board.children = [Block((500, 0), 500, (0, 255, 0), 1, 2), Block((0, 0), 500, (0, 0, 0), 1, 2), Block((0, 500), 500, (255, 255, 255), 1, 2), Block((500, 500), 500, (0, 255, 0), 1, 2)] assert goal.score(board) == 4 board.children[3].children = [Block((750, 500), 250, (0, 0, 0), 2, 2), Block((500, 500), 250, (0, 0, 0), 2, 2), Block((500, 750), 250, (55, 0, 0), 2, 2), Block((750, 750), 250, (0, 0, 0), 2, 2)] board.children[3].colour = None assert goal.score(board) == 4 goal2 = BlobGoal((0, 0, 0)) assert goal2.score(board) == 4 board.children[0].colour = (0, 0, 0) assert goal2.score(board) == 11
def test_JEN_smart_player(board_16x16) -> None: goal = BlobGoal((138, 151, 71)) player = SmartPlayer(2, goal, 2) player._proceed = True score1 = goal.score(board_16x16) move = player.generate_move(board_16x16) while move is SMASH: move.generate_move() score2 = goal.score(board_16x16) assert move is not None assert score2 >= score1
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
def test_blob_goal_2(self, board_4x4_3) -> None: correct_scores = [(COLOUR_LIST[0], 12), (COLOUR_LIST[1], 12), (COLOUR_LIST[2], 4), (COLOUR_LIST[3], 24)] for colour, expected in correct_scores: goal = BlobGoal(colour) assert goal.score(board_4x4_3) == expected
def test_blob_goal_4(self, board_2x2_2) -> None: correct_scores = [(COLOUR_LIST[0], 0), (COLOUR_LIST[1], 8), (COLOUR_LIST[2], 8), (COLOUR_LIST[3], 0)] for colour, expected in correct_scores: goal = BlobGoal(colour) assert goal.score(board_2x2_2) == expected
def test_blob_goal_unit(self, child_block) -> None: correct_scores = [(COLOUR_LIST[0], 1), (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 = BlobGoal(colour) assert goal.score(child_block) == expected
def test_BG_many_blob_not_connected(self) -> None: gol = BlobGoal(PACIFIC_POINT) borde = standard_borde() # print(borde) borde.children[2].children[0] = Block((100, 200), 100, OLD_OLIVE, 2, 3) # print(borde) assert gol.score(borde) == 20 assert borde.children[2].children[0].smash() is True
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)))
def test_blob_goal(self, board_16x16) -> None: correct_scores = [(COLOUR_LIST[0], 1), (COLOUR_LIST[1], 4), (COLOUR_LIST[2], 4), (COLOUR_LIST[3], 5)] # Set up a goal for each colour and check the results for colour, expected in correct_scores: goal = BlobGoal(colour) assert goal.score(board_16x16) == expected
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
def test_score_blob_goal_02() -> 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 = BlobGoal(COLOUR_LIST[3]) assert P.score(b) == 5 b.children[0].children[2].paint(COLOUR_LIST[3]) assert P.score(b) == 6 b.children[1].colour = COLOUR_LIST[3] assert P.score(b) == 10
def test_blob_goal_single_board(single_board) -> None: correct_scores = [ (COLOUR_LIST[0], 1), (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 = BlobGoal(colour) assert goal.score(single_board) == expected
def test_blob_depth_3() -> None: board = Block((0, 0), 100, None, 0, 3) # Level 1 colours = [COLOUR_LIST[0], None, None, None] set_children(board, colours) # Level 2 colours = [None, None, None, None] set_children(board.children[1], colours) colours = [COLOUR_LIST[2], COLOUR_LIST[1], COLOUR_LIST[3], COLOUR_LIST[0]] set_children(board.children[2], colours) colours = [None, None, None, None] set_children(board.children[3], colours) # Level 3 colours = [COLOUR_LIST[3], COLOUR_LIST[0], COLOUR_LIST[2], COLOUR_LIST[2]] set_children(board.children[1].children[0], colours) colours = [COLOUR_LIST[1], COLOUR_LIST[0], COLOUR_LIST[2], COLOUR_LIST[3]] set_children(board.children[1].children[1], colours) colours = [COLOUR_LIST[2], COLOUR_LIST[2], COLOUR_LIST[3], COLOUR_LIST[0]] set_children(board.children[1].children[2], colours) colours = [COLOUR_LIST[1], COLOUR_LIST[2], COLOUR_LIST[3], COLOUR_LIST[2]] set_children(board.children[1].children[3], colours) colours = [COLOUR_LIST[1], COLOUR_LIST[2], COLOUR_LIST[3], COLOUR_LIST[1]] set_children(board.children[3].children[0], colours) colours = [COLOUR_LIST[2], COLOUR_LIST[1], COLOUR_LIST[2], COLOUR_LIST[3]] set_children(board.children[3].children[1], colours) colours = [COLOUR_LIST[3], COLOUR_LIST[1], COLOUR_LIST[1], COLOUR_LIST[0]] set_children(board.children[3].children[2], colours) colours = [COLOUR_LIST[2], COLOUR_LIST[3], COLOUR_LIST[2], COLOUR_LIST[2]] set_children(board.children[3].children[3], colours) goal = BlobGoal(COLOUR_LIST[0]) assert goal.score(board) == 16 goal = BlobGoal(COLOUR_LIST[1]) assert goal.score(board) == 4 goal = BlobGoal(COLOUR_LIST[2]) assert goal.score(board) == 6 goal = BlobGoal(COLOUR_LIST[3]) assert goal.score(board) == 4
def test_blob_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], 1), (COLOUR_LIST[1], 4), (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 = BlobGoal(colour) assert goal.score(board) == score
def test_smart_player_generate_move() -> None: """ Test the SmartPlayer class' generate_move method. """ goal = BlobGoal((0, 0, 0)) player1 = SmartPlayer(1, goal, 4) player1._proceed = True b1 = Block((0, 0), 1000, (0, 0, 0), 0, 2) b1_score = goal.score(b1) move1 = player1.generate_move(b1) assert isinstance(move1, tuple) and isinstance(move1[0], str) and \ (isinstance(move1[1], int) or move1[1] is None) and \ isinstance(move1[2], Block) if move1[0:2] == ('rotate', 1): assert move1[2].rotate(1) assert goal.score(b1) > b1_score elif move1[0:2] == ('rotate', 3): assert move1[2].rotate(3) assert goal.score(b1) > b1_score elif move1[0:2] == ('swap', 0): assert move1[2].swap(0) assert goal.score(b1) > b1_score elif move1[0:2] == ('swap', 1): assert move1[2].swap(1) assert goal.score(b1) > b1_score elif move1[0:2] == ('paint', None): assert move1[2].paint(self.goal.colour) assert goal.score(b1) > b1_score elif move1[0:2] == ('combine', None): assert move1[2].combine() assert goal.score(b1) > b1_score else: assert move1[0:2] == ('pass', None) assert goal.score(b1) == b1_score
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)
def test_blob_goal1(self, board_32x32_rotate1) -> None: goal = BlobGoal(COLOUR_LIST[1]) assert goal.score(board_32x32_rotate1) == 16
def test_blob_goal_other(self, board_32x32) -> None: board_32x32.children[0].children[2].colour = COLOUR_LIST[0] goal = BlobGoal(COLOUR_LIST[0]) assert goal.score(board_32x32) == 5
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
def test_blob_goal_16(self, board_16x16) -> None: board_16x16.children[1].colour = COLOUR_LIST[1] goal = BlobGoal(COLOUR_LIST[1]) assert goal.score(board_16x16) == 10
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
def test_BG_2_blobs(self) -> None: gol = BlobGoal(PACIFIC_POINT) borde = standard_borde() assert gol.score(borde) == 24
class TestBlobGoal(A2TestStep7): def setUp(self) -> None: super().setUp() self.goal_colour = None self.goal = BlobGoal(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 = BlobGoal(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(1, res, "Since there is only 1 block in the board you should return 1") def test_goal_3(self): """ ____________ | | | | |___________| colour:(10, 10, 10) """ self.set_colour((10, 10, 10)) exps = [4, 16, 64, 256] res = [] for i in range(1, 5): 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 = 1 self.assertEqual(exp, res, "Every block only connect to itself, so you should always return 1") 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 = 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 = 4 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 = 1 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "The block only connects to itself") 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, "You have one fully connected blob of size 7") 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 = 4 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "You have a connected blob of size 4") 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 = 1 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "Diagonal connections do not count") 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 = 2 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "Two diagonal connections each counts as one so the longest connected blob is I N which is 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 = 1 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "Diagonal connections do not count") 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 = 1 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "Diagonal connections do not count") 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:(40, 40, 40) E:(10, 10, 10) F:(40, 40, 40) G:(40, 40, 40) H:(40, 40, 40) I:(60, 60, 60) J:(50, 50, 50) K:(40, 40, 40) L:(30, 30, 30) M:(40, 40, 40) N:(40, 40, 40) O:(20, 20, 20) P:(40, 40, 40) """ self.set_colour((40, 40, 40)) self.one_internal.children[0].children[3].colour = (40, 40, 40) self.set_children(self.one_internal.children[1], [(40, 40, 40) for i in range(4)]) self.one_internal.children[1].children[0].colour = (10, 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], [(40, 40, 40) for i in range(4)]) self.one_internal.children[3].children[2].colour = (20, 20, 20) exp = 5 res = self.goal.score(self.one_internal) self.assertEqual(exp, res, "The largest connected blob is ADMNP")
def test_score_blob_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 = BlobGoal((199, 44, 58)) goal2 = BlobGoal((255, 211, 92)) goal3 = BlobGoal((0, 0, 0)) block4 = 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) block4.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, (199, 44, 58), 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, (199, 44, 58), 2, 2) b44 = Block((12, 12), 4, (199, 44, 58), 2, 2) c4.children = [b41, b42, b43, b44] assert goal1.score(block1) == 5 assert goal1.score(block4) == 10 assert goal2.score(block1) == 1 assert goal2.score(block2) == 4 assert goal3.score(block3) == 2 assert goal3.score(block1) == 0
def test_score_blob_goal_no_children() -> None: b = Block((0, 0), 500, COLOUR_LIST[1], 0, 0) P = BlobGoal(COLOUR_LIST[1]) assert P.score(b) == 1 b = Block((0, 0), 500, COLOUR_LIST[1], 0, 1) assert P.score(b) == 4
def test_blob_goal0(self, board_32x32) -> None: goal = BlobGoal(COLOUR_LIST[0]) assert goal.score(board_32x32) == 4