make
./toledo [a ...]
./toledo a
./toledo a b
Two alternate versions of this entry, toledo2.c and toledo3.c are provided.
To compile the alternate versions:
make alt
Use Use toledo2
and toledo3
as you would toledo
above.
Challenge yourself with your ability to look 5, 6 or more moves ahead. Challenge your knowledge of C operator precedence. The following is the move analysis via recursion while it executes moves. All while playing by the rules of C and Chess within a single function!
When this entry was submitted the code was a recursive call to main()
- that
was it. In 2023 due to problems with clang
main()
calls another function,
pain()
, which calls itself. But it might be said that the Chess is still a
single function.
This is a chess program, it can work in two modes: two-players, and one player (always white) against the machine. To get the first mode, run the program without arguments:
./toledo
The other mode is accessible running the program with one argument (5-ply analysis):
./toledo a
Two arguments for 6-ply analysis:
./toledo a b
And each successive argument will analyze one ply more. There is no ply limit, but beyond 7 ply is very slow, try it at your own risk and computing time.
When it is your turn, you can enter your move, for example, as d2d4
and press the
enter key. This will move the pawn at D2
to D4
, assuming that a pawn is
there (as it would be in the beginning). The computer will check move legality
and will warn you of illegal moves. All legal chess moves are permitted.
One special case is when you are doing promotion, you must enter the move with an extra letter indicating the desired piece.
For example f7f8n
(supposing you have a pawn on F7
), will promote it to a
knight; substitute n
for the desired piece (N
/Q
/R
/B
).
Note that the program requires the piece letter; it will not select automatically a queen, so don’t be surprised if it doesn’t accept your move.
The computer will check for checkmate and stalemate. Also, after each machine move, it will show the score of the position: a higher number is better for the computer, i.e. worse for you.
None.
This is a good example of a chess program reduced to the essential. In order to get it into the contest limits, I used short but slow and unintelligible algorithms.
The interface accounts for only a fraction of the code, the core does multiples functions: it is called recursively to analyze and evaluate each ply, does alpha-beta pruning, move generation, machine playing, check detection, illegal move verification and does moves after they are verified.
It also sets a standard on ultra-mini-chess programs. The player and the computer can do all legal chess moves.
Other features are: