Ejemplo n.º 1
0
def test_move_right__ok_4plus():
    """
		test if move right work proprely with size 4 or plus
	"""
    old_puzzle = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 14, 15, 16]
    obj_puzzle = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 0, 15, 16]
    new_puzzle = moves.move_right(4, old_puzzle)
    assert new_puzzle == obj_puzzle
    old_puzzle = [1, 2, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    obj_puzzle = [1, 2, 4, 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    new_puzzle = moves.move_right(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, 27, 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, 0, 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, 17, 18, 19, 20,
        21, 22, 23, 24, 25, 26, 27, 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, 66, 0, 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_right(10, old_puzzle)
    assert new_puzzle == obj_puzzle
Ejemplo n.º 2
0
def test_move_right__ko_3():
    """
		test if move right work proprely when 0 is on the top border with size 3
	"""
    old_puzzle = [1, 2, 0, 4, 5, 6, 7, 8, 9]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle is None
    old_puzzle = [1, 2, 3, 4, 5, 0, 7, 8, 9]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle is None
    old_puzzle = [1, 2, 3, 4, 5, 6, 7, 8, 0]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle is None
Ejemplo n.º 3
0
	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)
Ejemplo n.º 4
0
def test_move_right__ok_3():
    """
		test if move right work proprely with size 3
	"""
    old_puzzle = [0, 2, 3, 4, 5, 6, 7, 8, 9]
    obj_puzzle = [2, 0, 3, 4, 5, 6, 7, 8, 9]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle == obj_puzzle
    old_puzzle = [1, 0, 3, 4, 5, 6, 7, 8, 9]
    obj_puzzle = [1, 3, 0, 4, 5, 6, 7, 8, 9]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle == obj_puzzle
    old_puzzle = [1, 2, 3, 0, 5, 6, 7, 8, 9]
    obj_puzzle = [1, 2, 3, 5, 0, 6, 7, 8, 9]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle == obj_puzzle
    old_puzzle = [1, 2, 3, 4, 0, 6, 7, 8, 9]
    obj_puzzle = [1, 2, 3, 4, 6, 0, 7, 8, 9]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle == obj_puzzle
    old_puzzle = [1, 2, 3, 4, 5, 6, 0, 8, 9]
    obj_puzzle = [1, 2, 3, 4, 5, 6, 8, 0, 9]
    new_puzzle = moves.move_right(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, 5, 6, 7, 9, 0]
    new_puzzle = moves.move_right(3, old_puzzle)
    assert new_puzzle == obj_puzzle