8-puzzle

8 puzzle problem using brute force search

吃可爱长大的小学妹 提交于 2020-02-20 06:21:46
问题 def exploring_nodes(node): print("Exploring Nodes") actions = ["down", "up", "left", "right"] goal_node = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 0]]) node_q = [node] final_nodes = [] visited = [] final_nodes.append(node_q[0].data.tolist()) # Only writing data of nodes in seen node_counter = 0 # To define a unique ID to all the nodes formed while node_q: current_root = node_q.pop(0) # Pop the element 0 from the list if current_root.data.tolist() == goal_node.tolist(): print("Goal reached")

8 puzzle problem using brute force search

☆樱花仙子☆ 提交于 2020-02-20 06:21:26
问题 def exploring_nodes(node): print("Exploring Nodes") actions = ["down", "up", "left", "right"] goal_node = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 0]]) node_q = [node] final_nodes = [] visited = [] final_nodes.append(node_q[0].data.tolist()) # Only writing data of nodes in seen node_counter = 0 # To define a unique ID to all the nodes formed while node_q: current_root = node_q.pop(0) # Pop the element 0 from the list if current_root.data.tolist() == goal_node.tolist(): print("Goal reached")

Manhattan distance in A*

拈花ヽ惹草 提交于 2020-01-11 02:21:07
问题 I am implementing a NxN puzzle solver using A* search algorithm and using Manhattan distance as a heuristic and I've run into a curious bug (?) which I can't wrap my head around. Consider these puzzles (0 element being blank space): (initial) 1 0 2 7 5 4 8 6 3 (goal) 1 2 3 4 5 6 7 8 0 The minumum number of moves to reach solution from initial state is 11. However, my solver, reaches goal in 17 moves. And therein lies the problem - my puzzle solver mostly solves the solvable puzzles in a

Using A* algorithm to solve 8-puzzle boards (Board data type works fine)

眉间皱痕 提交于 2020-01-04 03:16:30
问题 Hi I'm using java to create a Solver program that uses the assistance of HeapMinPQ and nodes in order to solve any board based on the "8 puzzle" format. I've already created by "Board" data type which uses a two-dimensional array to account for the tiles (and "0" is the blank space). Within my SearchNodes, I have a priority Integer that accounts for the "Manhattan" values (and I'm sure that method works fine). The problem is that I've been trying to make progress, and although my program

Ideas for an efficient way of hashing a 15-puzzle state

不想你离开。 提交于 2019-12-22 08:52:19
问题 I am implementing a 15-puzzle solver by Ant Colony Optimization, and I am thinking a way of efficiently hashing each state into a number, so I waste the least amount of bytes. A state is represented by a list of 16 numbers, from 0 to 15 (0 is the hole). Like: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0] So I want to create an unique number to identify that state. I could convert all the digits to a base 16 number, but I don't think that's very efficient Any ideas?. Thanks 回答1: Your state is

How many possible states does the 8-puzzle have?

倖福魔咒の 提交于 2019-12-20 17:32:38
问题 The classical 8-puzzle belongs to the family of sliding blocks. My book (Artificial intelligence A modern approach by Stuart Russell and peter Norwig) says that the 8-puzzle has 9!/2 possible states. But WHY the /2 ? How do you get this? 回答1: 9! is the total number of possible configurations of the puzzle, whereas 9!/2 is the total number of solvable configurations. For example, this configuration doesn't have a solution: 1 2 3 4 5 6 8 7 Read more about the solvability of certain

How many possible states does the 8-puzzle have?

痴心易碎 提交于 2019-12-20 17:31:54
问题 The classical 8-puzzle belongs to the family of sliding blocks. My book (Artificial intelligence A modern approach by Stuart Russell and peter Norwig) says that the 8-puzzle has 9!/2 possible states. But WHY the /2 ? How do you get this? 回答1: 9! is the total number of possible configurations of the puzzle, whereas 9!/2 is the total number of solvable configurations. For example, this configuration doesn't have a solution: 1 2 3 4 5 6 8 7 Read more about the solvability of certain

Trying to solve 15 Puzzle, OutOfMemoryError [closed]

痴心易碎 提交于 2019-12-12 10:12:51
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago . Is there any way that I can optimize this code as to not run out of memory? import java.util.HashMap; import java.util.Map; import java.util.PriorityQueue; import java.util.Random; import java.util.Stack; public

Ideas for an efficient way of hashing a 15-puzzle state

与世无争的帅哥 提交于 2019-12-05 17:05:01
I am implementing a 15-puzzle solver by Ant Colony Optimization, and I am thinking a way of efficiently hashing each state into a number, so I waste the least amount of bytes. A state is represented by a list of 16 numbers, from 0 to 15 (0 is the hole). Like: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0] So I want to create an unique number to identify that state. I could convert all the digits to a base 16 number, but I don't think that's very efficient Any ideas?. Thanks Your state is isomorphic to the permutations of 16 elements. A 45 bit number is enough to enumerate those (log2 16!), but we

How many possible states does the 8-puzzle have?

这一生的挚爱 提交于 2019-12-03 04:59:51
The classical 8-puzzle belongs to the family of sliding blocks. My book (Artificial intelligence A modern approach by Stuart Russell and peter Norwig) says that the 8-puzzle has 9!/2 possible states. But WHY the /2 ? How do you get this? 9! is the total number of possible configurations of the puzzle, whereas 9!/2 is the total number of solvable configurations. For example, this configuration doesn't have a solution: 1 2 3 4 5 6 8 7 Read more about the solvability of certain configurations of the n-puzzle in this Wikipedia article , or as pointed out by @dasblinkenlight in this MathWorld