• 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
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Breadth-First Search  RSS feed

 
Greenhorn
Posts: 3
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
 
Master Rancher
Posts: 3189
119
  • 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.

 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!