473,811 Members | 3,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

World smallest chess program

Hi, a year ago I won the 2005 Best Game categoryof the International
Obfuscated C Code Contestwith a chess program.
http://www.ioccc.org/whowon2005.html
http://www.mailcom.com/ioccc/toledo/hint.htmBut this post is because I
have discovered (asurprise for me) that it is also the worldsmallest
chess program written in C language.It has a size of 3004 bytes, or
2261 bytes simplydeleting all the spacing that makes the knightfigure,
cutting down the evaluation function wouldmake it smaller but that
deteriorates the computergamepla y.By the way, if someone doesn't play
chess, here isa simple modification to make the computer playversus
itself, change 1<L&e to 1Regards,Óscar Toledo G.http://www.biyubi.com/

Nov 22 '06
63 15286
Guy Macon wrote:
dc*****@connx.c om wrote:
>10.2
The game is won by the player whose opponent declares he resigns.
This immediately ends the game.
..."+
>>From article 10.2, it is very clear that:
#include <stdio.h>
int main(void){puts ("I resign");return 0}
is a legal chess program. It also works fine for thematic
tournaments.

Legal, but far from small. stdio.h is *huge*.
But puts is not. The remainder is a linking problem, and OT. :-)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Dec 12 '06 #31

max schreef:
No idea how small micro-Max is, but back in the 1980s there was a chess
program that fitted within the 1K ZX-81 memory - Z80 machine code, but
making use of the 16K ZX-81 ROM, for IO. Apparently it played legal but bad
chess.
One should distingush the sizes of the source code, the executable and
the memory size used including data. The 1KB ZX81 program was a real
achievement, since the 1KB had to hold both the program code and the
data. I am not sure if it was written (entirely) in assembler, though,
because I seem to recall that the ZX-81 had a BASIC interpreter in ROM,
so the program could also have been encoded BASIC instructions (which
could do more per byte than Z80 machine instructions).

In those days I had written a 2KB chess program (code + data) for the
6800 micro-processor, called Usurpator I. The micro-Max project was
actually inspired by the question if I could rival such code density in
a high-level language. The source of such assembly programs was much
larger, of course, since a single-byte assembly instruction typically
took 5 characters to write down. On the other hand, micro-Max is very
memory-hungry for data: in just a few characters you can declare an
array of hundreds of megabytes (int A[1<<26];), and this is exactly
what micro-Max does. So in that sense the comparison is not fair.

Dan and I simply disagree about whether resigning should count as
playing Chess. In my opinion playing Chess is what you do *before* you
resign. That the FIDE rules stipulate that you are allowed to stop
playing Chess any time you like during a game (by resigning) does not
convince me that the stopping itself is part of the game. I would
reserve the term Chess program for a program that can play a game of
Chess to the very end without resigning.

Dec 12 '06 #32

David Richerby wrote:
Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
dc*****@connx.c om wrote:
David Richerby wrote:
IIRC, the ZX-81 chess program didn't allow en passant and/or
castling and/or underpromotion, so can't really be called `legal
chess'.

Rybka, the strongest chess engine in the world, ignores some
underpromotions (at one point it ignored all of them).
Is it therefore not a chess program?
If it allows you to under-promote, but does not choose to do so
itself, that's legal.

Exactly. (Sorry for the `me too' but the question was kind of
directed at me.)
How is it differnt than a program that resigns (plays fully under the
FIDE rules of chess)?
It also is simply not exercising every possible rule of the game. In
both cases the programs are simply choosing not to perform some of the
alternatives that are available to them.

If you fail to see the full correspondence between these two
situations, then I am at a loss as to how to make it clear.

Another even shorter alternative is:

int main(void) (while(1);retur n 0;}

This program always loses the game on time.

Dec 12 '06 #33
<h.********@hcc net.nlwrote:
Dan and I simply disagree about whether resigning should count as
playing Chess. In my opinion playing Chess is what you do *before*
you resign. That the FIDE rules stipulate that you are allowed to
stop playing Chess any time you like during a game (by resigning)
does not convince me that the stopping itself is part of the game. I
would reserve the term Chess program for a program that can play a
game of Chess to the very end without resigning.
In that case,

int main() {while (1);}

is a chess program: it will lose every game on time. I think the best
way to proceed is to use the term `non-trivial chess program'.
Dave.

--
David Richerby Aluminium Bulb (TM): it's like a light
www.chiark.greenend.org.uk/~davidr/ bulb that's really light!
Dec 12 '06 #34
<dc*****@connx. comwrote:
David Richerby wrote:
>Richard Bos <rl*@hoekstra-uitgeverij.nlwr ote:
>>dc*****@connx.c om wrote:
David Richerby wrote:
IIRC, the ZX-81 chess program didn't allow en passant and/or
castling and/or underpromotion, so can't really be called `legal
chess'.

Rybka, the strongest chess engine in the world, ignores some
underpromoti ons (at one point it ignored all of them).
Is it therefore not a chess program?

If it allows you to under-promote, but does not choose to do so
itself, that's legal.

Exactly. (Sorry for the `me too' but the question was kind of
directed at me.)

How is it differnt than a program that resigns (plays fully under the
FIDE rules of chess)?
It also is simply not exercising every possible rule of the game. In
both cases the programs are simply choosing not to perform some of the
alternatives that are available to them.
As far as I can see, we're in complete agreement! My objection to the
ZX-81 program was that not allow its opponent to castle, capture en
passant or underpromote. If a program wishes to avoid making certain
types of moves itself or to resign without even considering the
position, that's perfectly within its prerogative.

If you fail to see the full correspondence between these two
situations, then I am at a loss as to how to make it clear.

Another even shorter alternative is:

int main(void) (while(1);retur n 0;}

This program always loses the game on time.
Indeed -- as I posted myself earlier. (This is not a criticism of you
for posting the same program; just an observation that I was already
aware of this idea.)
Dave.

--
David Richerby Pickled Priest (TM): it's like a
www.chiark.greenend.org.uk/~davidr/ man of the cloth but it's preserved
in vinegar!
Dec 12 '06 #35
If you fail to see the full correspondence between these two
situations, then I am at a loss as to how to make it clear.
There is nothing to make clear. We just don't agree on the definition
of Chess.

In my view the rules of Chess are a subset of the FIDE rules. There are
other FIDE rules that prescribe how participants in events organized by
FIDE should behave. These FIDE rules have nothing to do with Chess. The
Dutch Bridge Society has rules for when Bridge players can smoke during
a Bridge game. That dosn't mean that smoking a cigarete is playing
Bridge.

FIDE rules about offering draws, resigning, and other player
interactions that can determine the entry that goes in the score table
of a tournament by negociation without playing, have nothing to do with
Chess. FIDE rules allow you to participate in a FIDE tournament without
playing Chess.

Resigning is *not* a Chess move, it is merely exercising your right to
stop playing Chess. At any turn someone playing a Chess game has the
choice to play (a move) or to resign or forfeit on time (= not play).
Not playing does not violate FIDE rules. But that does not make not
playing playing Chess.

Dec 12 '06 #36
CBFalconer wrote:
Guy Macon wrote:
>dc*****@connx.c om wrote:
>>10.2
The game is won by the player whose opponent declares he resigns.
This immediately ends the game.
..."+

From article 10.2, it is very clear that:
#include <stdio.h>
int main(void){puts ("I resign");return 0}
is a legal chess program. It also works fine for thematic
tournaments .

Legal, but far from small. stdio.h is *huge*.

But puts is not. The remainder is a linking problem, and OT. :-)
In fact, to elaborate, the following is a satisfactory puts:

int puts(char *s) {
int err;

while (*s && (EOF != (err = putchar(*s++))) ) continue;
if (err 0) err = putchar('\n');
return err;
}

For many non-hosted systems, it suffices to code putchar(), which
will usually reduce to a half-dozen lines of assembly at worst.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Dec 12 '06 #37
dc*****@connx.c om wrote:
How is it differnt than a program that resigns (plays fully under the
FIDE rules of chess)?
It also is simply not exercising every possible rule of the game.
The difference is, a reasonable person will call you an idiot for making
that program, whereas a program that makes some attempt at actually
playing, might garner some respect.

If you honestly do not see the difference between, say, a one-statement
program that "just resigns", versus say, a one-liner that actually
*plays chess*, 100% completely or otherwise, you have a perception
problem, or you are merely being a clown.
Dec 12 '06 #38
CBFalconer <cb********@yah oo.comwrites:
For many non-hosted systems, it suffices to code putchar(), which
will usually reduce to a half-dozen lines of assembly at worst.
However: the putchar and puts functions are in the hosted
library, which freestanding implementations don't have to support
at all.
--
"Programmer s have the right to be ignorant of many details of your code
and still make reasonable changes."
--Kernighan and Plauger, _Software Tools_
Dec 12 '06 #39
David Richerby <da****@chiark. greenend.org.uk writes:
<h.********@hcc net.nlwrote:
>Dan and I simply disagree about whether resigning should count as
playing Chess. In my opinion playing Chess is what you do *before*
you resign. That the FIDE rules stipulate that you are allowed to
stop playing Chess any time you like during a game (by resigning)
does not convince me that the stopping itself is part of the game. I
would reserve the term Chess program for a program that can play a
game of Chess to the very end without resigning.

In that case,

int main() {while (1);}

is a chess program: it will lose every game on time. I think the best
way to proceed is to use the term `non-trivial chess program'.
I also suggest considering carefully whether further followups should
go to comp.lang.c, rec.games.chess .computer, or both. If you're not
discussing the C programming language, please consider limiting your
followup to rec.games.chess .computer.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 12 '06 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.