As part of a homework assignment, I have to program a simple chess game in Java. I was thinking of taking the opportunity to experiment with recursion, and I was wondering if there's an obvious candidate in chess for recursive code?
The most obvious candidate to me would be a recursive minimax routine for searching for the best moves. This also gets into a lot of the theory behind search algorithms and would be pretty cool to implement.
Example:
http://www.devshed.com/c/a/Practices/Solving-Problems-with-Recursion/6/
Yes there is. If you have some function that evaluate "force" of some position for say player white. You can move a piece and call it recursively to evaluate the value of a move and choose the best move.
You should call the same function for player black, exchanging roles for blacks and whites, thus evaluating "danger" of an opponent move.
Then again for the whites, etc.
Just be aware you should not go too deep in recursion levels or it will take forever.
Depth-first search is a prime candidate for recursion. so if you're programming an AI for the homework assignment, then the AI's lookhead algorithm to try to figure out a best next move would be a good candidate.
Be careful though - you can run out of memory quick. You probably want to limit the number of moves deep the AI can look.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With