Puzzle Quest Solver

I figure it’s not cheating when I use this program to solve Puzzle Quest capture puzzles. But if you use it, you’re totally cheating. I wrote the code, that means I solved the puzzle. You, you’re scum.
pqsolver.exe (Get this if you just want to run it)

pqsolver.cpp (Source code, if you want to see how it works or don’t trust random executables off the internet. Builds on Mac, Linux, Windows, probably anything else with a C++ compiler)

Sample input files:

test2.pq (not a real puzzle, just an early test)

OrcLord.pq (Real)

Sandworm.pq (Real)

To run it:

pqsolver < file.pq

The magic values, straight from the code:
case red: c = 'r'; break;
case yellow: c = 'y'; break;
case green: c = 'g'; break;
case blue: c = 'b'; break;
case skull: c = 's'; break;
case skullx5: c = '5'; break;
case xp: c = 'x'; break;
case money: c = 'm'; break;
case empty: c = '.'; break;

The output has the first step at the bottom, last step at the top. Backwards, in other words. Harder to do it the right way around the way the algorithm works. The bottommost board displayed is the initial input, the topmost is the next to last state before winning. Above each board are the coordinates to move to get to the next step.

Updated 11/09/2007 : Thanks to Nige in the comments, the bug with skulls is fixed.  You Rock, Nige!

Tags: , ,

Wednesday, April 4th, 2007 Uncategorized

24 Comments to Puzzle Quest Solver

  • AarnaK says:

    good program, but you can make a window interface. I’m also a programmer and like you understand the importance of a good interface! 😉

  • Ogre says:

    The code is right there, feel free to make your own interface! A web interface would be great.

    Alternately, let’s say for the sake of argument that I’m willing to do contract work for a mere $75/hr. How much is that interface worth to you? 🙂

  • Bob says:

    Ha! And I got yelled at by someone for commenting “the puzzles aren’t that hard” in a forum thread you made on this, cuz you are so nice and altruistic to provide this.

    Now we see your TRUE motives!

    On a serious note: I finally got stuck on one of these damn things, the Warg-rider. I’m resorting to your app shortly. 🙂

  • someguy says:

    Okay I’ve tried a depth first search now (obviously stopping when I run out of moves that do anything) and that takes more than the 5 minutes I’ve left it to run too. I guess I just suck 😉

  • someguy says:

    hm, I wish I knew how to edit posts. Well, it turns out that DOES complete in a few minutes, maybe Java really IS slow 😉 I think it’s more likely my code is just pretty suboptimal, copying grids is probably a good deal more expensive in Java, unless I do it with some kind of buffer.

  • someguy says:

    Ok the solution for orc lord is (with y counting up from the bottom, sorry that way made more sense to me, but the step order is still reversed as in your code):

    5, 0 to 6, 0
    2, 0 to 2, 1
    1, 1 to 2, 1
    1, 1 to 2, 1
    5, 2 to 6, 2
    5, 4 to 6, 4
    6, 2 to 7, 2
    1, 3 to 2, 3
    1, 2 to 2, 2
    0, 2 to 1, 2

  • someguy says:

    Sorry for all the posts… just to confirm, my Java implementation is much slower, so I’ll have to spruce it up a bit 😉

  • Ogre says:

    Thanks for the note about the Ogre Lord. I’ll check it out when I get a chance.

    The number of copies my code does is indeed horrifying, I try not to think about it 🙂

  • someguy says:

    Actually I typed Ogre Lord, but I meant Orc Lord, sorry 😉

  • someguy says:

    Just in case anyone is following this, wolf rider solution is:

    6, 1 to 7, 1
    2, 0 to 3, 0
    1, 0 to 1, 1
    4, 0 to 5, 0
    4, 1 to 5, 1
    2, 2 to 3, 2
    2, 1 to 3, 1

    I’m so ashamed that I’m too stupid to work out the puzzles myself 🙁

  • Risby says:

    What do I need to run it? I downloaded the exe-file and opened it, had the OrcLord.pq in the same map and just wrote OrcLord.pq – the window closed and nothing happend.

    You need an FAQ to run shit like this.

  • Hunny says:

    Running this tool is simple – just pipe the data file (like OrcLord.pq) into the command.
    And if, by some occasion, you don’t know what “pipe… into” means – you need a book to learn shit like “computer”.

  • Baz says:

    Fun little tool, compiles and runs fine for me. Only problem is there seems to be a bug in the way it explodes the +5 skulls. Step 3 (from the bottom) of its solution to the given Sandworm file has it explode a +5 skull. The following board has some extra greens and yellows that should have been destroyed in the blast (double checked in game that this is so).

    The Explode() routine seems to be correct from a cursory glance, but there’s probably a bug given some combination of row matching, exploding, and gem falling.

  • Nige says:

    The comparison for the y loop in the Explode() function is wrong; there is a missing equals.
    It should read :

    for(y = yc -1; y

  • Nige says:

    I’ll try that again

    for(y = yc -1; y <= yc + 1; y++)

  • Ogre says:

    Thanks, Nige! Source and executable have been updated.

  • Arnar Æ says:


    I am trying to use the pqsolver with limited success.

    i use command prompt on Win XP and type
    “pqsolver sandworm.pq >>test.txt”

    but it stalls no error and does not stop until I break it.
    Any suggestions?

    Arnar Æ

  • whoozle says:



    consumes 100% cpu and hang for a long time 🙁 I’ve successfully solved orclord,orcmage with pqsolver, thanks 🙂

  • Morkatron says:

    I too am attempting to use the solver with no luck. I have typed “pqsolver sandworm.pq >>test.txt” at the cmd prompt and I receive the msg “the system cannot execute the specified program” Any suggestions?


  • Morkatron says:

    Oh and I am using a XP pro OS corporate if that matters…

  • Sumrnot says:

    Well, it’s nice to see someone else interested in writing a solver. I’m getting close to releasing a beta (exe only) myself.

    Featuring: (drum roll)
    – GUI (win 2000,nt,xp) uses MaskBlt Not sure about Vista.
    No Linux yet.
    – adaptive cache of about 140,000 positions
    – preemptive testing to cut down search space
    – animation (Dammit,Jim. I’m a programmer. not an artist)

    Give me about a week to track down some bugs and finish in-house, and if anyone’s interested I’ll post a link.

  • Dave says:

    Sumrnot, i’m really interested in your project, please post a link. Ogre’s code works perfectly, but it takes long time filling the text file.



  • Raspa says:

    Hey, I’m working on a solver aswell. I’m doing this on my freetime, so it might take a while. Currently I’m doing it in java, but maybe i’ll port it to processing to put it in a webpage.

    I’m still missing the handling of wildcards and 5xskuls, but if the problem doesn’t have neither, it finishes in about 1-2 seconds. (it doesn’t stop when the solution is found, so that’s the time to search all the solutions space)

    I’ll probaby finish the first version, this week or so, and i’ll share it to the world.

    Sumrnot, what do you mean by: adaptive cache of about 140,000 positions.

  • puzzled says:

    Well, googling OGRE LORD brings you here… and there are solutions to other things…

    Might there be a solution for maybe…

    The Ogre Lord puzzle?


  • Leave a Reply