Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Funny project: Minimum legal chess

Author: Dann Corbit

Date: 12:16:41 04/05/00

Go up one level in this thread


On April 05, 2000 at 14:30:14, Pete Galati wrote:

>On April 05, 2000 at 14:08:01, Dann Corbit wrote:
>
>>It might be funny to write the smallest possible chess program that produces
>>legal moves for both sides.  If it plays against itself, it could have no I/O
>>except to display the chosen moves.  It could more or less choose legal moves at
>>random.  Basically, it could be nothing but a board representation, a move
>>generator, and calls to rand().
>>
>>Can it be done in (for instance) ten lines of C?
>
>How would you decide the random move to make?  Wait a minute, that didn't make
>sense.  Since you're not really talking about selecting a move based on a
>search, you'd have to generate a list of all the legal moves for each position,
>feed them to your random function as variables, and it would make it's random
>selection from those.
>
>It would play a bad game of Chess.  I doubt if you could get by on 10 lines.

Just take the list of legal moves.  Suppose that there are N of them, then your
choice is:
(int)((double)rand() / ((double)RAND_MAX + 1) * N)

The game is over when no legal moves exist (draw) or checkmate.

And the source lines...
A logical line of C can have over 500 characters in C89 and 4095 characters in a
logical source line for C9X.
;-)







This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.