Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good use of recursion in chess programming? [closed]

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?

like image 604
JDelage Avatar asked May 27 '10 12:05

JDelage


3 Answers

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/

like image 182
Laplace Avatar answered Sep 18 '22 10:09

Laplace


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.

like image 42
kriss Avatar answered Sep 21 '22 10:09

kriss


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.

like image 21
sechastain Avatar answered Sep 22 '22 10:09

sechastain