Results 1 to 2 of 2
  1. #1
    GPB
    GPB is offline Member
    Join Date
    Feb 2010
    Posts
    20
    Rep Power
    0

    Default 15 puzzle using 2d arrays

    I made a basic (not very efficient) algorithm to solve a 15-puzzle using bfs.
    Each node is a puzzle-state.

    I assume I'm doing something wrong, because the puzzles.size() runs over 30000+
    I'd really appreciate it if someone could take a look.

    It should basically go:
    Java Code:
    new queue, add rootNode
    while (queue != empty){
        Node n = firstFromQueue
        if ( n matches goalState)
            succes
        else
            add n.successors to queue
    but also keep track of the nodes visited, because you don't need to visit them again.
    Last edited by GPB; 05-25-2010 at 11:28 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default

    Add some debugging statements to show execution flow and how variable values change.

    If you see how the code is executing, you should be able to see your problem.

Similar Threads

  1. trying to create a soduku puzzle
    By Jaguar1998 in forum New To Java
    Replies: 13
    Last Post: 04-13-2010, 03:30 AM
  2. N-Puzzle Help!
    By evan42781 in forum New To Java
    Replies: 12
    Last Post: 04-30-2009, 12:34 AM
  3. Need help with Trees...(8-puzzle)
    By ventrue in forum New To Java
    Replies: 2
    Last Post: 03-24-2009, 12:04 AM
  4. 8-Square puzzle loop
    By SapphireSpark in forum New To Java
    Replies: 7
    Last Post: 12-04-2008, 08:21 PM
  5. Java Drawing PUZZLE
    By Cyorxamp in forum AWT / Swing
    Replies: 3
    Last Post: 06-09-2008, 11:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •