Page 1 of 1

Masyu - it's like pathfinding?

Posted: 14 Jan 2008, 21:15
by pktm
Hello!

I'm trying to write a Masyu solver, but it's really hard. It reminds me of pathfinding, so i thought, i could ask someone here :)

Does anyone has any suggestion how to solve a Masyu puzzle?

My approaches always have some bugs, they don't work out.

regards, pktm

Re: Masyu - it's like pathfinding?

Posted: 14 Jan 2008, 23:04
by AF
First, what's masyu?

Re: Masyu - it's like pathfinding?

Posted: 14 Jan 2008, 23:29
by pktm
It's a puzzle: http://en.wikipedia.org/wiki/Masyu

You have to connect all pearls by watching certain rules.

But, how do you compute a solution?

Re: Masyu - it's like pathfinding?

Posted: 14 Jan 2008, 23:55
by SinbadEV
Looks like "Maze" solver Algorithm would probably work... just with the added rules. Another idea would be to calculate all the possible paths and see if any of them don't break any of the rules.

edit:
Okay, standard maze solver algorithm says you move to a new square you have 3 options, (any direction but where you came from) in this case if a square is blank you have all three options, if it's black you only have 1 (strait) and if it's white you have 2 (not strait)...

Re: Masyu - it's like pathfinding?

Posted: 15 Jan 2008, 14:11
by pktm
[quote="SinbadEV"]Looks like "Maze" solver Algorithm would probably work... just with the added rules. Another idea would be to calculate all the possible paths and see if any of them don't break any of the rules.

edit:
Okay, standard maze solver algorithm says you move to a new square you have 3 options, (any direction but where you came from) in this case if a square is blank you have all three options, if it's black you only have 1 (strait) and if it's white you have 2 (not strait)...[/quote]

But how to add the option, that you have to turn at least oncew if you cross a white pearl?

Re: Masyu - it's like pathfinding?

Posted: 15 Jan 2008, 17:00
by SinbadEV
Ok, so, then with a standard maze solver you remove the option of Up Down, Left or Right based on where walls are, in this you remove them as you enter the square for the particular path...

so if you enter a n empty grid from the top you need to try left right and down, if you enter a black perl from the top you only need to check down, and if you enter a white perl from the top you only need to test left or right.

you continue the path until you reach an already entered suqare... then you check to see if the path has entered all the perls and abandon it if it hasn't.

Re: Masyu - it's like pathfinding?

Posted: 26 Jan 2008, 17:47
by kiki
oop + backtracking

Re: Masyu - it's like pathfinding?

Posted: 14 Feb 2008, 00:21
by imbaczek
this one is NP-complete (wikipedia even provides link to a proof.) IOW, no easy way to find a solution, maze path finding algorithms are useless here. smart backtracking is the only option.

Re: Masyu - it's like pathfinding?

Posted: 27 Feb 2008, 10:18
by Error323
Yes it's NP-Complete, that basically means that you have to make it compute all the possibilities, and check each for correctness, using perhaps Genetic Algorithms or something. This means only relatively small boards can be solved in a reasonable amount of time.