-
October 13th, 2007, 02:09 PM
#1
How to have a program "think ahead"
Hi all.
I'm making a chess program (c++). The output of the program is simple: "Your move:" on the player's turn ... "thinking..." (and, of course, a move) on the program's turn.
My problem is that, while the chess program works pretty well, the player still has to wait about 20 seconds for the program to calculate an answer. However, I figure that, because the player may take a while to choose a move, why not have the program think ahead to its next move so that the player may not have to wait as long. Of course, this would mean that the program would have to account for any move that the player might make, but it might be worth it if it ends up saving time.
So, is there a way for the program to accept input from the player while simultaneously calculating its own moves?
Alternatively, is there a way for the program to calculate moves UNTIL the player provides input?
Anyway...
Thank you!
Andy
-
October 13th, 2007, 02:39 PM
#2
Re: How to have a program "think ahead"
You should use threads for this. Run the calculation in a separate thread from the user input and then they will not block each other.
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|