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

    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)
            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 10:28 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    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, 02:30 AM
  2. N-Puzzle Help!
    By evan42781 in forum New To Java
    Replies: 12
    Last Post: 04-29-2009, 11:34 PM
  3. Need help with Trees...(8-puzzle)
    By ventrue in forum New To Java
    Replies: 2
    Last Post: 03-23-2009, 11:04 PM
  4. 8-Square puzzle loop
    By SapphireSpark in forum New To Java
    Replies: 7
    Last Post: 12-04-2008, 07:21 PM
  5. Java Drawing PUZZLE
    By Cyorxamp in forum AWT / Swing
    Replies: 3
    Last Post: 06-09-2008, 10: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