• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Breadth-First Search

 
Greenhorn
Posts: 6
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm doing an assignment for class where we're given the following code in order to solve the 8-piece sliding puzzle problem. We are to complete the method boolean isSolvable(Configuration configuration). I've been able to set up the bfs algorithm but I'm having trouble getting the method to actually figure out if the configuration is solvable. Right now I'm getting false, false, false when the output should be true true false. Can someone see where I'm going wrong?

Here is the given code:


This is the suggestion from my professor:

This is my attempt:


My Output: false, false, false
 
Saloon Keeper
Posts: 3462
149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Max,

well, it need not be that there is something wrong with your code. Maybe the three configurations that you check, might be unsolvable?

I added this to your Configuration class:

And I changed the beginning of your isSolvable method slightly, to print the configuration that was just pulled from the queue:

And lastly, in your main, I went for only this configuration:

Well, it seems perfectly oke to me! But do check some other easy initial configurations, to see if your code is oke.

Finally, while being off the street anyway, you might also implement a DFS, that would make following the process a little easier.

 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!