Questions tagged [sliding-tile-puzzle]

For algorithm or programming questions about sliding puzzles (such as the 8-puzzle or 15-puzzle), where the player is challenged to slide randomized, numbered tiles along certain routes on a board in order to arrive at a certain end configuration. There is one tile missing, in order to facilitate movement.

For algorithm or programming questions about sliding puzzles, such as the 8-puzzle or 15-puzzle, which challenge the player to slide randomized, numbered tiles along the playing surface in order to arrive at a certain end configuration. There is one tile missing, in order to facilitate movement of other tiles across the board.

Commonly, such puzzles are solved with an A* algorithm.

166 questions
2
votes
2 answers

Fast / efficient identification of two 2D arrays for sameness in C

I'm working on a search algorithm project, finding the solution for the 16 puzzle. I have two lists of structs that contain a 2D array board[N][N] The numbers in the list are unique in a range of 0-15, the difference is their order. BoardA = 0 1 …
MKUltra
  • 349
  • 2
  • 14
2
votes
2 answers

Precalculate Result of A*

Currently learning about the A* search algorithm and using it to find the quickest solution to the N-Puzzle. For some random seed of the initial starting state, the puzzle may be unsolvable which would result in extremely long wait times until the…
m_callens
  • 6,100
  • 8
  • 32
  • 54
2
votes
0 answers

Prolog: Using A* to solve 8 puzzle

I'm trying to implement a solver of an 8-puzzle. The puzzle board is represented as a list. For example, the goal state: 1 | 2 | 3 --------- 4 | 5 | 6 --------- 7 | 8 | 0 is represented as [1,2,3,4,5,6,7,8,0], where 0 represents the empty…
bli00
  • 2,215
  • 2
  • 19
  • 46
2
votes
1 answer

What is a more efficient way to choose/sort the best node in an A* search?

I am using an A* search and a Breadth First search to find a winning game state in an 8 puzzle. The winning state looks like this 123 456 780 and stored as a list like such [1,2,3,4,5,6,7,8,9,0] I used a heuristic function to score each node…
2
votes
1 answer

Why "ERROR: Out of global stack"

%(SWI-Prolog)You can run the program by: ?- bestfs([8,1,3,7,0,2,6,5,4],P). initial([8,1,3,7,0,2,6,5,4]). goal([1,2,3,8,0,4,7,6,5]). operators([left, right, up, down]). % 8-puzzle solution % initial([8,1,3,7,0,2,6,5,4]). %…
Korn Smith
  • 21
  • 3
2
votes
1 answer

Improve 8-Puzzle using BFS

I've tried to implement Breadth First Search algorithm into my attempt to solve the 8 Puzzle Game. But in some cases, I ran out of memory, but on simpler cases it solves without problem. How can I improve my algorithm to fix it? main.c /* Standard…
Bruno Alano
  • 643
  • 1
  • 11
  • 21
2
votes
1 answer

I am trying to solve '15 puzzle', but I get 'OutOfMemoryError'

Is there a 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 class TilePuzzle { private final…
gaijinco
  • 95
  • 1
  • 3
2
votes
1 answer

Manhattan distance in 8 puzzle

Can anybody explain me how to calculate manhattan distance in 8 puzzle problem on this example http://ai.ia.agh.edu.pl/wiki/pl:prolog:pllib:sliding_puzzle ? How it's calculate this: a(0,0). a(1,0). a(2,1). a(3,2). a(4,3). a(5,4). a(6,3). a(7,2). …
Chris
  • 652
  • 1
  • 7
  • 22
2
votes
1 answer

Updating WPF GUI Every 2 Seconds (C#)

I'm doing an 8 Puzzle solver that ultimately stores each node (int[] of elements 0-8) in the path to put the blocks in order in a stack. I have a WPF GUI that displays an int[,] foreach (var node in stack) { int[,] unstrung =…
2
votes
1 answer

Non-optimal solutions for 15-puzzle game

I am applying A* (and IDA*) search with manhattan heuristic for finding solution to 15-puzzle problem. Using the fact that i dont want an optimal solution for the problem how can i can speed up the search as the current routine is too slow.
gabber12
  • 1,114
  • 2
  • 11
  • 18
1
vote
2 answers

Search algorithms (DFS,BFS,A star etc.). How to update the GUI (with updated state) without "freezing"?

My question is rather simple. Let's suppose I'm executing the algorithm "A star" (search algorithm using a heuristic function to calculate next state to visit). I want to show in a grid the updates (I will apply it to 8-puzzle problem). How should I…
dragonmnl
  • 14,578
  • 33
  • 84
  • 129
1
vote
2 answers

Queues in Java - What's wrong with my implementation, and what's one I can use?

I am trying to make a breadth-first search to solve a square-shifting puzzle (the one where you move squares into an empty space until it's solved). My breadth-first algorithm uses a queue. Unfortunately, it only seems to be working for the UP and…
Andrew Latham
  • 5,982
  • 14
  • 47
  • 87
1
vote
1 answer

Give a part of chessboard of 15-puzzle, how to get all of the state of the the part chessboard using BFS?

the board is like this: 1 2 3 4 5 6 7 0 0 0 0 0 0 0 0 0 the '0' represents that is empty, we can move the non-zero number to the '0'. so how to get all of the state of the board using BFS? for example, there are two state of the board: 1 2 3 4 0 0…
1
vote
0 answers

Sliding Puzzle with Standard Python Modules and without Class

I am new to programming and trying to create a sliding puzzle program without class and only standard python module. I have found a code from internet about the sliding puzzle game and tried to modify the board dimension and the input to move the…
i'm-anon
  • 11
  • 3
1
vote
1 answer

How can I implement IDA* algorithm in Python for 15-Puzzle problem?

I'm trying to solve the 15-Puzzle problem using IDA* algorithm and Manhattan heuristic. I already implemented the algorithm from the pseudocode in this Wikipedia page (link). Here's my code so far : def IDA(initial_state, goal_state): …
1 2
3
11 12