Recalculating the time in every recursive call, get's quite expensive. Perhaps depth mod 8 == 0 would be enough?
Also, you re-draw the board for every move. You only need to redraw two squares after any move - the from square, and the to square. It also gets rid of any possible screen flicker.
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
That's not entirely correct I'm afraid.
I only display the board when it is solved, that's also when I calculate the difference in time.
Notice the #ifdef DEBUG in front of the "print the board after every move" line. That line only gets compiled when DEBUG is defined, which it isn't. It was there for, naturally, debugging purposes.
Then you need to start bringing the facts forward, and start including data: How long does your program take to run, and on what hardware?
Have you profiled it yet, and what were the results?
What compiler are you using, and with what flags?
I'm sure you could google around and find other versions of this program. How does your program compare to them, when run on the same hardware and compiler?
That will give you real insight into the performance of your program.
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
before i go any further, i want to know what kind of speeds you're currently getting. time per solution.
also, do you require closed solutions, or are open solutions acceptable?
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
Why does it matter what speeds I'm getting?
why so hostile?
i want to know if its worth my time to post my solution. if you're getting speeds as fast as mine, i wont bother.
anyhow, the Warnsdorff algorithm, as ive coded it, solves each of the 64 positions on the board in 15 milliseconds or less. This is a 1.8 GHz machine.
mind you, this is just "solving" any given position. I could keep running it at that rate indefinitely, but if i had to keep track of unique solutions, it would add some overhead.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
i dont have my code available to me here at work, its on my laptop at home.
all i did was write code to implement the Warnsdorff Algorithm. its a couple hundred years old, and it's no secret.
you could implement it yourself and get the same results i did.
http://web.telia.com/~u85905224/knight/eWarnsd.htm
the pros of this method is that it's accurate (~98%) and its FAST. when i said 15 milliseconds or less, that was the maximum total time to find one solution per square, for ALL of the 64 squares in succession. so, approximately 250 microseconds per solution, or less. (and actually that was on my laptop, an AMD Athelon X2 (2.something GHz per core)
the real flaw with it is that it won't find all possible solutions, which may be unacceptable depending on your requirements. it can find multiple solutions per square, some closed and some open, but it wont find them all.
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
I wanted to create an algorithm that finds every possible Knight's Tour from any given position in a reasonable amount of time. I'd like it to be in a minute, but I'm not sure if that's possible.
um, yeah, good luck with that.
there are 26,534,728,821,064 possible CLOSED solutions to the Knight's Tour on an 8x8 board, plus an as-yet uncounted number of undoubtedly many orders of magnitude greater than that for the OPEN solutions.
check these guys out for help: http://www.cray.com/products/xt5/index.html , and meanwhile, Ill keep an eye out for your results when you're published in the journals.
:P
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179