def test_move_up__ok_4plus(): """ test if move up work proprely with size 4 or plus """ old_puzzle = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 15, 16] obj_puzzle = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 10, 15, 16] new_puzzle = moves.move_up(4, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [1, 2, 3, 4, 0, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] obj_puzzle = [0, 2, 3, 4, 1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] new_puzzle = moves.move_up(4, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 ] obj_puzzle = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 17, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 ] new_puzzle = moves.move_up(10, old_puzzle) assert new_puzzle == obj_puzzle
def test_move_up__ko_3(): """ test if move up work proprely when 0 is on the top border with size 3 """ old_puzzle = [0, 2, 3, 4, 5, 6, 7, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle is None old_puzzle = [1, 0, 3, 4, 5, 6, 7, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle is None old_puzzle = [1, 2, 0, 4, 5, 6, 7, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle is None
def _create_children(self, noodle: node.Node) -> None: """ creates new children from a node """ direc = [direction.UP, direction.DOWN, direction.RIGHT, direction.LEFT] children = [0, 0, 0, 0] children[0] = moves.move_up(self.size, noodle.puzzle[1]) children[1] = moves.move_down(self.size, noodle.puzzle[1]) children[2] = moves.move_right(self.size, noodle.puzzle[1]) children[3] = moves.move_left(self.size, noodle.puzzle[1]) i = -1 for child in children: i += 1 if child is not None: new_node = node.Node( [self.size, child], noodle, direc[i], self.greedy_algo ) lists, index, oldnode = self.find_puzzle_in_list(new_node) if lists is None: self.insert_node_in_open(new_node) else: if new_node.f_score < oldnode.f_score: if lists == self.open: del lists[index] self.insert_node_in_open(new_node)
def test_move_up__ok_3(): """ test if move up work proprely with size 3 """ old_puzzle = [1, 2, 3, 0, 5, 6, 7, 8, 9] obj_puzzle = [0, 2, 3, 1, 5, 6, 7, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [1, 2, 3, 4, 0, 6, 7, 8, 9] obj_puzzle = [1, 0, 3, 4, 2, 6, 7, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [1, 2, 3, 4, 5, 0, 7, 8, 9] obj_puzzle = [1, 2, 0, 4, 5, 3, 7, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [1, 2, 3, 4, 5, 6, 0, 8, 9] obj_puzzle = [1, 2, 3, 0, 5, 6, 4, 8, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [1, 2, 3, 4, 5, 6, 7, 0, 9] obj_puzzle = [1, 2, 3, 4, 0, 6, 7, 5, 9] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle == obj_puzzle old_puzzle = [1, 2, 3, 4, 5, 6, 7, 8, 0] obj_puzzle = [1, 2, 3, 4, 5, 0, 7, 8, 6] new_puzzle = moves.move_up(3, old_puzzle) assert new_puzzle == obj_puzzle