School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 306,831 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,743 people online right now. Registration is fast and FREE... Join Now!




Tetravex Solver

 

Tetravex Solver, Tetravex puzzle solver algorithm

mostyfriedman

20 Mar, 2009 - 09:36 AM
Post #1

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,211



Thanked: 357 times
Dream Kudos: 600
Expert In: Learning

My Contributions
hello geeks,

I'm in my 2nd year in computer science major right now and i have implemented a game of Tetravex..anyway i was thinking of writing a program that will solve any tetravex puzzle and i just wanted to know your thoughts about this, is it doable in an efficient way?? or would it be a waste of time to try to implement such a program??.. thanks for reading

User is online!Profile CardPM
+Quote Post


mostyfriedman

RE: Tetravex Solver

20 Mar, 2009 - 04:26 PM
Post #2

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,211



Thanked: 357 times
Dream Kudos: 600
Expert In: Learning

My Contributions
i think i should have posted this in the game programming forum, can a mod/admin move this please
User is online!Profile CardPM
+Quote Post

Gloin

RE: Tetravex Solver

21 Mar, 2009 - 02:55 AM
Post #3

Expert Schmexpert...
Group Icon

Joined: 4 Aug, 2008
Posts: 3,607



Thanked: 143 times
Dream Kudos: 75
My Contributions
I don't know any short-cut polynomial algorithm for this problem and the immediate thought is that you would have to try an exponential number of combinations to find the solution.
However, considering there are likely more than one solution to many of these puzzles and that you can branch quite heavily, there's likely a pretty good chance of finding a solution fast anyways.
What's the largest puzzle that you allow? Is there a limit or do you intend to have a solver for the n by n case?
User is offlineProfile CardPM
+Quote Post

baavgai

RE: Tetravex Solver

21 Mar, 2009 - 03:32 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,347



Thanked: 410 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
QUOTE(mostyfriedman @ 20 Mar, 2009 - 11:36 AM) *
is it doable in an efficient way?


Depends on how you judge efficient. tongue.gif

Every piece matches to a minimum of two other pieces. Doing an initial compare pass to find the piece that has the least matches would be a good place to start. It would also be a simple validation, since a having piece that can't even match two in a corner means your puzzle can't be done. If you're lucky enough to find a piece that must be a corner, then your search became significantly more efficient.

Sounds like fun. Good luck.

User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Tetravex Solver

21 Mar, 2009 - 08:48 AM
Post #5

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,211



Thanked: 357 times
Dream Kudos: 600
Expert In: Learning

My Contributions
QUOTE(Gloin @ 21 Mar, 2009 - 02:55 AM) *

I don't know any short-cut polynomial algorithm for this problem and the immediate thought is that you would have to try an exponential number of combinations to find the solution.
However, considering there are likely more than one solution to many of these puzzles and that you can branch quite heavily, there's likely a pretty good chance of finding a solution fast anyways.
What's the largest puzzle that you allow? Is there a limit or do you intend to have a solver for the n by n case?



the largest puzzle that i allow is 6*6 and the smallest is 2*2, i actually i thought of it and i drew a diagram for all the possibilities on paper, i thought of using recursion for it, i don't know if this is a good idea though...

btw i already have the solution, because what my program does, is that it generates the solution first and then it shuffles the puzzle(to ensure that the puzzle is solvable) so if the user gives up and wants to see the solution the solution will be displayed, what i was thinking of doing is to write a generic algorithm to solve any puzzle...
User is online!Profile CardPM
+Quote Post

Gloin

RE: Tetravex Solver

24 Mar, 2009 - 02:48 PM
Post #6

Expert Schmexpert...
Group Icon

Joined: 4 Aug, 2008
Posts: 3,607



Thanked: 143 times
Dream Kudos: 75
My Contributions
That was my first thought actually, taking a solution and shuffle it but I figured you wanted a solver.
For a maximum of 6x6 I would go with brute force with some simple branching rule. Doesn't matter that the number of possible combinations grow exponentially since it will never grow too big to handle for a standard computer.
Recursion is good for this problem.
User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Tetravex Solver

24 Mar, 2009 - 05:30 PM
Post #7

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,211



Thanked: 357 times
Dream Kudos: 600
Expert In: Learning

My Contributions
QUOTE(Gloin @ 24 Mar, 2009 - 02:48 PM) *

That was my first thought actually, taking a solution and shuffle it but I figured you wanted a solver.
For a maximum of 6x6 I would go with brute force with some simple branching rule. Doesn't matter that the number of possible combinations grow exponentially since it will never grow too big to handle for a standard computer.
Recursion is good for this problem.


thanks for the reply, i was actually thinking of a brute force approach, since there is no other straight forward way to do this.. i thought of either generating all the possible permutations of the puzzle, or doing like some kinda search and bound algorithm where each time i eliminate solutions that won't work..
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/20/09 10:46PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month