Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

World smallest chess program

546 views
Skip to first unread message

biy...@gmail.com

unread,
Nov 22, 2006, 3:23:58 PM11/22/06
to
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 computergameplay.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/

biy...@gmail.com

unread,
Nov 22, 2006, 3:59:00 PM11/22/06
to
Hi, a year ago I won the 2005 Best Game category
of the International Obfuscated C Code Contest
with a chess program.

http://www.ioccc.org/whowon2005.html
http://www.mailcom.com/ioccc/toledo/hint.htm

But this post is because I have discovered (a
surprise for me) that it is also the world

smallest chess program written in C language.

It has a size of 3004 bytes, or 2261 bytes simply
deleting all the spacing that makes the knight

figure, cutting down the evaluation function would


make it smaller but that deteriorates the computer
gameplay.

By the way, if someone doesn't play chess, here is
a simple modification to make the computer play

versus itself, change 1<L&e to 1

jacob navia

unread,
Nov 22, 2006, 6:20:41 PM11/22/06
to

And it works!

Incredible!

Mis sinceras felicitaciones. Eso es una obra de arte.

jacob

keith_emerson

unread,
Nov 22, 2006, 7:19:32 PM11/22/06
to
But where is the setjmp.h???

dco...@connx.com

unread,
Nov 22, 2006, 8:32:05 PM11/22/06
to

It's not the smallest C chess program in the world.
http://home.hccnet.nl/h.g.muller/max1.html

Old Wolf

unread,
Nov 22, 2006, 10:03:16 PM11/22/06
to
dco...@connx.com wrote:

> biy...@gmail.com wrote:
> > 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
>
> It's not the smallest C chess program in the world.
> http://home.hccnet.nl/h.g.muller/max1.html

That page says that its software doesn't even implement
the rules of chess properly .. I don't think that counts

Jack Klein

unread,
Nov 22, 2006, 10:19:39 PM11/22/06
to
On 22 Nov 2006 16:19:32 -0800, "keith_emerson" <nicol...@gmail.com>
wrote in comp.lang.c:

> But where is the setjmp.h???

It's a standard header supplied with every standard C compiler. If
your compiler does not have it available, it is either a very strange
non-conforming compiler, or perhaps it is installed incorrectly.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

Old Wolf

unread,
Nov 22, 2006, 10:29:19 PM11/22/06
to
biy...@gmail.com wrote:
> Hi, a year ago I won the 2005 Best Game categoryof the International
> Obfuscated C Code Contestwith a chess program.
>
> cutting down the evaluation function would make it smaller but that
> deteriorates the computer gameplay.

Well, in the 5-ply mode I won in 8 moves the first game, and it
allows repetition of the same game each time. You might like
to mix it up a bit by randomizing amonst the top few candidate
moves, if they all have similar evaluations.

The game was: 1. e4 Nc6; 2. d4 Nf6; 3. Bd3 d5; 4. e5 Nd7;
5. c3 f6; 6. Qh5+ g6; 7. Qxg6+ hg; 8. Bxg6#

William Hughes

unread,
Nov 22, 2006, 10:31:34 PM11/22/06
to

However this version does.

http://home.hccnet.nl/h.g.muller/max-src2.html

and at 2000 bytes is still smaller.

-William Hughes

biy...@gmail.com

unread,
Nov 22, 2006, 10:56:32 PM11/22/06
to

William Hughes ha escrito:

My program is still the world smallest chess
program, as it does all legal chess moves (the
other program cannot promote to knight, bishop
or rook).

As a bonus it includes messages for the current
score, stalemate and checkmate and a good board
display for the user's benefit.

Is very possible to cut all those "extras" and
leave a bare chess engine, getting it far below
the actual size of 2044 IOCCC characters (characters
minus spaces, and } { ; followed by space).

But I leave that as an exercise for the readers. ;)

About the random generator, is easy to add a
*NIX only srand(getpid()); at the program start.

David Richerby

unread,
Nov 23, 2006, 4:03:44 AM11/23/06
to
Old Wolf <old...@inspire.net.nz> wrote:
> biy...@gmail.com wrote:
>> Hi, a year ago I won the 2005 Best Game categoryof the International
>> Obfuscated C Code Contestwith a chess program.
>>
>> cutting down the evaluation function would make it smaller but that
>> deteriorates the computer gameplay.
>
> Well, in the 5-ply mode I won in 8 moves the first game, and it
> allows repetition of the same game each time.

Something tells me that playing high quality chess wasn't one of the
project's design goals...


Dave.

--
David Richerby Sadistic Cheese Watch (TM): it's like
www.chiark.greenend.org.uk/~davidr/ a precision chronometer that's made
of cheese but it wants to hurt you!

dco...@connx.com

unread,
Nov 25, 2006, 3:20:53 PM11/25/06
to

While I will admit that writing a working chess program is impressive
and your program is no exception, his program does recognize
underpromotion, it just does not play it. So the only consequence will
be suboptimal play on those rare occasions where underpromotion is
beneficial. BTW, his chess program will positively destroy yours in a
course of games.

P.S.
This is the world's smallest chess program. It plays legal chess, but
it will not fare very well in contests:
#include <stdio.h>
int main(void)
{puts("I resign.");return 0;}

Kenneth Sloan

unread,
Nov 25, 2006, 7:02:00 PM11/25/06
to
This program can be made MUCH shorter.

--
Kenneth Sloan Kennet...@gmail.com
Computer and Information Sciences +1-205-932-2213
University of Alabama at Birmingham FAX +1-205-934-5473
Birmingham, AL 35294-1170 http://www.cis.uab.edu/sloan/

Keith Thompson

unread,
Nov 27, 2006, 8:03:18 PM11/27/06
to
dco...@connx.com writes:
[...]

> P.S.
> This is the world's smallest chess program. It plays legal chess, but
> it will not fare very well in contests:
> #include <stdio.h>
> int main(void)
> {puts("I resign.");return 0;}

<OT>
Reminds me of one of the first programs I wrote (not in C). It would
ask you whether you want to go first. If not, its first move was
always pawn to king 4. After your first move, it would randomly print

Checkmate in [N] moves, (I resign)|(You lose).
</OT>

--
Keith Thompson (The_Other_Keith) 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.

Christopher Benson-Manica

unread,
Nov 30, 2006, 8:55:06 AM11/30/06
to
In comp.lang.c dco...@connx.com wrote:

> #include <stdio.h>
> int main(void)
> {puts("I resign.");return 0;}

There's a tic-tac-toe variation that I rather prefer:

#include <stdio.h>
int main(void) {
puts("If we both play optimally it's a draw. Good game.");
return 0;
}

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.

Random832

unread,
Nov 30, 2006, 10:37:36 AM11/30/06
to
2006-11-30 <ekmnrq$dfc$1...@chessie.cirr.com>,

Christopher Benson-Manica wrote:
> In comp.lang.c dco...@connx.com wrote:
>
>> #include <stdio.h>
>> int main(void)
>> {puts("I resign.");return 0;}
>
> There's a tic-tac-toe variation that I rather prefer:
>
> #include <stdio.h>
> int main(void) {
> puts("If we both play optimally it's a draw. Good game.");
> return 0;
>}

Surely one could add a lookup table that says how many [minimum number]
moves to a draw if the player places his first mark in a center, side,
or corner.

h.g.m...@hccnet.nl

unread,
Dec 11, 2006, 10:11:35 AM12/11/06
to
> P.S.
> This is the world's smallest chess program. It plays legal chess, but
> it will not fare very well in contests:
> #include <stdio.h>
> int main(void)
> {puts("I resign.");return 0;}

Let me clarify something here.

This discussion is obviously only meaningfull is there is an
unambiguous definition of the concept 'Chess Program'. Like always,
when exploring a boundary, this is not completely obvious what this
should be.

I always have found the following definition to work satisfactory:

A chess program is a program that, according to unambiguous
input/output rules defined by the programmer, is able to score
significantly (in the statistical sense) better than 50% against an
opponent that plays random legal moves.

This would exclude quirks like the one above. (Which I consider a good
thing.) Also note that the random move generator does not yet qualify
as a chess program. (In topological terms, it is on the edge, but not
in the set itself.) To be a chess program you have to do something
more, but it can be an infinitesimal amount.

According to my definition, it is not a requirement that the program
plays legal moves in every situation. Requiring so, would be tantamount
to requiring that the program contains no bugs. Since in general this
cannot be proven for a language as powerful as C, requiring such a
thing would render the definition useless. Giving off an illegal move
should simply be counted as a resignation. If a program that has a
habit of doing this does not do it so often that it no longer clearly
beats the random mover, it still is a chess program.

According to this definition, both micro-Max and Toledo are chess
programs by a large margin. Micro-Max is smaller. And stronger :D,
despite the fact that (unlike what was stated above) it does neither
do, nor accept minor promotions. If the opponent does a minor promotion
that makes a difference (i.e. the piece is not immediately captured)
the response of micro-Max should be considered a resignation. This has
negligible impact on its performance.

I don't know if micro-Max is actually the world's smallest chess
program, but I am not aware of any program that is smaller.

max

unread,
Dec 11, 2006, 4:04:07 PM12/11/06
to
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.

<h.g.m...@hccnet.nl> wrote in message
news:1165849895.9...@l12g2000cwl.googlegroups.com...

David Richerby

unread,
Dec 11, 2006, 5:50:59 PM12/11/06
to
max <no...@none.com> wrote:
> 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.

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'.


Dave.

--
David Richerby Mentholated Chair (TM): it's like a
www.chiark.greenend.org.uk/~davidr/ chair but it's invigorating!

james of tucson

unread,
Dec 11, 2006, 7:33:37 PM12/11/06
to
max wrote:
> 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.

Was that a derivative of Sargon? There were versions of Sargon as early
as 1978. Sargon is actually not that difficult to digest. I read the
book in 1980, and actually considered implementing a version.
Everything you needed to know about Z-80 programming could have been
learned from this program. Add to that perhaps the basic approach to
CP/M syscalls and you were golden, in those days.

http://madscientistroom.org/chm/Sargon.html

james of tucson

unread,
Dec 11, 2006, 7:56:39 PM12/11/06
to
David Richerby wrote:
> max <no...@none.com> wrote:
>> 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.
>
> 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'.

The 1978 Sargon I that, I believe, the ZX-81 chess was based on,
supported E-P and castling. You could implement Sargon I in 8K RAM.
It was not *that* bad. You could beat it easily in the opening of
course, and alpha-beta pruning doesn't really work for endgames, but its
tactics are not all that bad. I believe that in 1980, a Sargon-I on a
Z-80 microcomputer had a rating in the 1600's. I suspect it was the
basis for some of the purpose-built chess computers of the day.

Sargon does a pretty good job of pruning loss-lines, provided they are
evaluated as losses early enough. It is a very good example of
Alpha-Beta pruning, and does what I would call a magnificent job of
pushing the limits of a small memory space for evaluating board
positions. I mean, GNUChess does essentially the same thing (I know PVS
is more than just an optimization of Alpha-Beta, but it's still
essentially the same approach to evaluation).

I've seen smarter guys than myself be beaten time and time again by
GNUChess. Also, I suspect that there are problem setups you could feed
to Sargon that would allow its tactics to play quite strongly, even on a
16K machine.

I'm not seriously trying to compare Sargon I to a computer chess program
that can be configured with hundreds of megabytes of opening book,
complete solutions for 5-piece endgames, and that can exploit
multi-gigahertz processors and gigabytes of ram for tactical evaluation.
But I still say that Sargon and its variants might surprise you. Yeah,
you can beat it every time -- but if you refrain from confusing it in
the opening, you may find it quite surprisingly "strong" in midgame
tactics.

I'm no chess champion, by any means (I play in the 1400's), and I only
dabble in game programming, so don't contribute to the conversation by
tearing my analysis to shreds. I'd actually like to read on this topic
from people who have implement a-b on a board game, for instance.

dco...@connx.com

unread,
Dec 11, 2006, 8:37:05 PM12/11/06
to

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?

Similarly, the chess program Junior won the world championship without
performing underpromotions -- even when an underpromotion is the best
move.
Is Junior therefore not a chess program?

Both of these programs are sold commercially and even used by chess
experts to analyze games.

My two line chess program obeys the FIDE rules of chess and is
therefore a complete and working chess program.
It loses every game, but that is beside the point.

dco...@connx.com

unread,
Dec 11, 2006, 8:41:14 PM12/11/06
to
From:
http://www.chessvariants.com/fidelaws.html
We have this:
"Article 10: The Completed Game
10.1
The game is won by the player who has checkmated his opponent's king.
This immediately ends the game.
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.

Guy Macon

unread,
Dec 12, 2006, 3:37:47 AM12/12/06
to


dco...@connx.com 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*.


Richard Heathfield

unread,
Dec 12, 2006, 4:04:32 AM12/12/06
to

puts(const char *);main(){puts("I resign");return 0;}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.

Guy Macon

unread,
Dec 12, 2006, 4:11:09 AM12/12/06
to


Richard Heathfield wrote:
>
>Guy Macon <http://www.guymacon.com/> said:
>
>> dco...@connx.com 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*.
>
>puts(const char *);main(){puts("I resign");return 0;}

Now *that's* what I call a small chess-playing program! <grin>

And, as an added bonus, it wins against my computer as often
as I do...


Richard Bos

unread,
Dec 12, 2006, 5:31:15 AM12/12/06
to
dco...@connx.com wrote:

> David Richerby wrote:
> > max <no...@none.com> wrote:
> > > 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.
> >
> > 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.

Richard

jaapsch

unread,
Dec 12, 2006, 5:49:43 AM12/12/06
to
james of tucson wrote:
> max wrote:
> > 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.
>
> Was that a derivative of Sargon?

No it wasn't actually. The 1K zx81 chess program used no look ahead (or
rather just 1-ply). Iit just evaluated a score for each of its
available moves.

Since the screen contents also were stored in that 1k memory, this
program cleverly didn't have any code to draw the board. You had to
reload the program from tape to play another game. It also used that
screen memory directly for its board representation, i.e. it did not
have any other copy of the board contents in memory.

It was fun to completely disassemble it to see how it worked.

> There were versions of Sargon as early
> as 1978. Sargon is actually not that difficult to digest. I read the
> book in 1980, and actually considered implementing a version.

I still have that book, full of pencil annotations. I also wanted to
implement it, but as an 11-year-old that was a daunting task that I
never got around to. It taught me a lot though.


--
Jaap's Puzzle Page:
http://www.geocities.com/jaapsch/puzzles/

David Richerby

unread,
Dec 12, 2006, 7:01:37 AM12/12/06
to

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


Dave.

--
David Richerby Natural Newspaper (TM): it's like a
www.chiark.greenend.org.uk/~davidr/ daily broadsheet but it's completely
natural!

David Richerby

unread,
Dec 12, 2006, 6:59:45 AM12/12/06
to
David Richerby <dav...@chiark.greenend.org.uk> wrote:
> max <no...@none.com> wrote:
>> 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.
>
> 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'.

I see now that there was more than one commercially available chess
program for the ZX81. At least one of these implemented all legal
moves but it is implied in

http://www.sincuser.f9.co.uk/016/mindgms.htm

that this required 16KB RAM. I infer this because the article then
goes on to say,

``Artic also produces a technically-excellent game which fits into
the 1K ZX-81. It may not play brilliantly but it is fascinating to
watch the computer scan the moves available to it graphically on
the screen. The computer makes moves very quickly, although it
will not allow the usual en passant and castling which are
available on the bigger games. The game loads very quickly and at
GBP2.95 it is worth the money.''

I suspect that this is the program I was thinking of.


Dave.

--
David Richerby Old-Fashioned Mexi-Pants (TM):
www.chiark.greenend.org.uk/~davidr/ it's like a well-tailored pair of
trousers that comes from Mexico but
it's perfect for your grandparents!

CBFalconer

unread,
Dec 12, 2006, 7:02:07 AM12/12/06
to
Guy Macon wrote:
> dco...@connx.com 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>


h.g.m...@hccnet.nl

unread,
Dec 12, 2006, 8:04:10 AM12/12/06
to

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.

dco...@connx.com

unread,
Dec 12, 2006, 9:28:35 AM12/12/06
to

David Richerby wrote:
> Richard Bos <r...@hoekstra-uitgeverij.nl> wrote:
> > dco...@connx.com 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);return 0;}

This program always loses the game on time.

David Richerby

unread,
Dec 12, 2006, 10:00:52 AM12/12/06
to
<h.g.m...@hccnet.nl> wrote:
> 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!

David Richerby

unread,
Dec 12, 2006, 10:50:36 AM12/12/06
to
<dco...@connx.com> wrote:
> David Richerby wrote:
>> Richard Bos <r...@hoekstra-uitgeverij.nl> wrote:
>>> dco...@connx.com 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.

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);return 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!

h.g.m...@hccnet.nl

unread,
Dec 12, 2006, 11:52:21 AM12/12/06
to
> 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.

CBFalconer

unread,
Dec 12, 2006, 11:25:41 AM12/12/06
to
CBFalconer wrote:
> Guy Macon wrote:
>> dco...@connx.com 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.

james of tucson

unread,
Dec 12, 2006, 12:14:10 PM12/12/06
to
dco...@connx.com 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.

Ben Pfaff

unread,
Dec 12, 2006, 12:19:43 PM12/12/06
to
CBFalconer <cbfal...@yahoo.com> writes:

> 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.
--
"Programmers have the right to be ignorant of many details of your code
and still make reasonable changes."
--Kernighan and Plauger, _Software Tools_

Keith Thompson

unread,
Dec 12, 2006, 5:34:24 PM12/12/06
to
dco...@connx.com writes:
[...]

> Another even shorter alternative is:
>
> int main(void) (while(1);return 0;}
>
> This program always loses the game on time.

The "return 0;" is not necessary. In C99, reaching the '}' that
terminates the main function is equivalent to "return 0;". In C90, it
merely causes an unspecified status to be returned to the environment,
but that doesn't matter since it can't ever be executed anyway.

And you can save a single character by using "for" rather than "while":

int main(void){for(;;);}

In C90, you can drop the "int "; it's required in C99.

<OT>Running this program on a multi-user system is likely to anger
your fellow users.</OT>

--
Keith Thompson (The_Other_Keith) 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.

Keith Thompson

unread,
Dec 12, 2006, 5:38:33 PM12/12/06
to
David Richerby <dav...@chiark.greenend.org.uk> writes:
> <h.g.m...@hccnet.nl> wrote:
>> 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.

james of tucson

unread,
Dec 12, 2006, 6:08:18 PM12/12/06
to
h.g.m...@hccnet.nl wrote:

> 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, it was common practice to code in assembler while making
maximum use of routines that could be found in ROM -- you could use it
for constants, use routines as they were meant to be used, and very
clever people figured out ways to use ROM in really bizarre ways, with
arbitrary entry points, setting registers a certain way, etc.
I knew some of this stuff for Model-I TRS-80. I realized it was an
insane practice then, but it was how you pushed the envelope and squoze
every last byte out of the machine.

CBFalconer

unread,
Dec 12, 2006, 4:33:38 PM12/12/06
to

Allright. Using the principal of successive refinement:

#include <stdio.h>

int turn;

int main(void)
{
do {
if (!turn++) puts("1: P-K4");
else {
puts("I resign");
return 0;
}
} while (1);
} /* main, fully tested */

Note that it works when playing either white or black. :-) The
next refinement is to get the players move, which will upset the
above universality. Algebraic notation will also upset that.

Ignore any compiler warnings about failure to return a value. The
compiler is confused.

In seriousness, is there an available system for playing postal
chess, which avoids the temptation of letting the program analyze?

dco...@connx.com

unread,
Dec 12, 2006, 8:41:50 PM12/12/06
to
CBFalconer wrote:
[snip]

> In seriousness, is there an available system for playing postal
> chess, which avoids the temptation of letting the program analyze?

Sure. Those that do not contain analyzing programs like:
http://deepfrozen.tripod.com/index.html
http://www.ectool.nu/
http://jhess.sourceforge.net/
http://astrodogpress.com/chess/
There are some others.

Barry Schwarz

unread,
Dec 12, 2006, 9:20:41 PM12/12/06
to

Perhaps but it's a header file and does not appear in your executable
program.


Remove del for email

Richard Heathfield

unread,
Dec 13, 2006, 2:08:55 AM12/13/06
to
CBFalconer said:

<snip>

> In seriousness, is there an available system for playing postal
> chess, which avoids the temptation of letting the program analyze?

http://www.auspost.com.au
http://www.canadapost.ca
http://www.indiapost.gov.in
http://www.post.japanpost.jp/english/
http://www.newzealandmail.co.nz
http://www.royalmail.com
http://www.usps.com

are the Web sites of just some of the several specialist agencies dedicated
to providing a postal chess service (and other, somewhat related,
services). Alas, they won't normally provide you with an opponent, paper,
pencil, envelopes, pieces, or chess-board. But once you have solved those
problems, they can generally take up the strain from there.

ais523

unread,
Dec 13, 2006, 7:07:11 AM12/13/06
to
Keith Thompson wrote:

> And you can save a single character by using "for" rather than "while":
>
> int main(void){for(;;);}

You can save one more character by using a recursive call to main:

int main(void){main();}

This is likely to break an implementation limit on many
implementations, but I can imagine an implementation that recognizes
the tail-recursion and goes into an infinite loop here (which is the
behaviour the Standard would suggest).
--
ais523

Guy Macon

unread,
Dec 13, 2006, 7:49:26 AM12/13/06
to


dco...@connx.com wrote:

>Another even shorter alternative is:
>
>int main(void) (while(1);return 0;}
>
>This program always loses the game on time.

You, sir, are brilliant! You program does indeed play
perfectly legal chess according to both FIDE and USCF
rules, runs on a wide variety of hardware, and is self
documenting as well.

The same program ported to FORTH runs much faster though... :)

William Hughes

unread,
Dec 13, 2006, 7:52:33 AM12/13/06
to

On a Cray it executes in 15 seconds.

- William Hughes

Guy Macon

unread,
Dec 13, 2006, 7:54:24 AM12/13/06
to


David Richerby wrote:
>
><dco...@connx.com> wrote:

>> [...] a program that resigns (plays fully under the FIDE rules
>> of chess) [...] 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 t
>> 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.

Exactly so. The ZX-81 was palying something a lot like chess,
but it wasn't playing chess.

Guy Macon
<http://www.guymacon.com/>

Richard Tobin

unread,
Dec 13, 2006, 7:57:00 AM12/13/06
to
In article <1166011631.4...@j44g2000cwa.googlegroups.com>,
ais523 <ais...@bham.ac.uk> wrote:

>int main(void){main();}

>This is likely to break an implementation limit on many
>implementations, but I can imagine an implementation that recognizes
>the tail-recursion and goes into an infinite loop here

gcc appears to be such an implementation, when -O is used.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.

Richard Bos

unread,
Dec 13, 2006, 9:08:36 AM12/13/06
to
"William Hughes" <wpih...@hotmail.com> wrote:

Then it's not a valid chess program on a Cray. This may be one of the
few examples of a purpose for which a Cray is less powerful than a
Sinclair ZX-81.

Richard

Dr A. N. Walker

unread,
Dec 13, 2006, 12:13:37 PM12/13/06
to
In article <lnodq8e...@nuthaus.mib.org>,
Keith Thompson <ks...@mib.org> wrote:
>int main(void){for(;;);}

Pah. These wimpy, verbose languages. In Algol, the "same"
program is only 21% of the size, and for good measure is palindromic,
almost symmetric, and almost a word:

DO~OD

><OT>Running this program on a multi-user system is likely to anger
>your fellow users.</OT>

Surely, only if it's a *bad* multi-user system? Or does the
idle loop equally annoy the users?

--
Andy Walker, School of MathSci., Univ. of Nott'm, UK.
a...@maths.nott.ac.uk

Richard Tobin

unread,
Dec 13, 2006, 7:23:41 PM12/13/06
to
In article <elpcc1$c7q$1...@oyez.ccc.nottingham.ac.uk>,

Dr A. N. Walker <a...@maths.nott.ac.uk> wrote:

>><OT>Running this program on a multi-user system is likely to anger
>>your fellow users.</OT>

> Surely, only if it's a *bad* multi-user system? Or does the
>idle loop equally annoy the users?

[Still off-topic]

Unfortunately, there seem to be some bad multi-user systems around
these days. Running a single CPU-intensive process on our Linux
systems drastically slows down interactive response and network file
access. Perhaps it's related to Linux's Minix heritage...

David Richerby

unread,
Dec 15, 2006, 8:11:16 AM12/15/06
to
ais523 <ais...@bham.ac.uk> wrote:
> You can save one more character by using a recursive call to main:
>
> int main(void){main();}
>
> This is likely to break an implementation limit on many
> implementations

So it still fails to output a legal move within the time limit so
still loses on time. Mission accomplished, either way.


Dave.

--
David Richerby Accelerated Swiss Painting (TM): it's
www.chiark.greenend.org.uk/~davidr/ like a Renaissance masterpiece but
it's made in Switzerland and twice
as fast!

David Richerby

unread,
Dec 15, 2006, 8:18:48 AM12/15/06
to
Keith Thompson <ks...@mib.org> wrote:
> <OT>Running this program on a multi-user system is likely to anger
> your fellow users.

#include <sys/select.h>
int main () { select (1,0,0,0,0); }

Is much friendlier and only a little longer.</OT>


Dave.

--
David Richerby Aquatic Cyber-Laser (TM): it's like
www.chiark.greenend.org.uk/~davidr/ an intense beam of light that exists
only in your computer but it lives in
the sea!

Keith Thompson

unread,
Dec 15, 2006, 4:01:56 PM12/15/06
to
David Richerby <dav...@chiark.greenend.org.uk> writes:
> Keith Thompson <ks...@mib.org> wrote:
>> <OT>Running this program on a multi-user system is likely to anger
>> your fellow users.
>
> #include <sys/select.h>
> int main () { select (1,0,0,0,0); }
>
> Is much friendlier and only a little longer.

But it's not portable; the <sys/select.h> header and the select()
function are not part of standard C.

William Hughes

unread,
Dec 15, 2006, 4:12:41 PM12/15/06
to

David Richerby wrote:
> ais523 <ais...@bham.ac.uk> wrote:
> > You can save one more character by using a recursive call to main:
> >
> > int main(void){main();}
> >
> > This is likely to break an implementation limit on many
> > implementations
>
> So it still fails to output a legal move within the time limit so
> still loses on time. Mission accomplished, either way.

Yes, but if you allow anything that "fails to output a legal
move within the time limit" , isn't the empty program
a solution?

- William Hughes

MikeC

unread,
Jan 6, 2007, 12:48:37 PM1/6/07
to
I remember that somebody wrote a demonstration chess program about 25 years
ago on the Sinclair ZX81, which only had a 1K memory. The program could
take the first three moves.


<dco...@connx.com> wrote in message
news:1164245524.9...@h54g2000cwb.googlegroups.com...

biy...@gmail.com wrote:
> 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 computergameplay.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/

It's not the smallest C chess program in the world.
http://home.hccnet.nl/h.g.muller/max1.html


Hans

unread,
Feb 12, 2007, 5:51:29 PM2/12/07
to

Je hebt gelijk. You are right on this, I second that.

Vincent Diepeveen

unread,
Feb 13, 2007, 11:42:59 AM2/13/07
to
Nice to see Harm-Geert active here too :)

Vincent

p.s. smallest chessprogram on planet in C:

#include <stdio.h>
main() {
printf("i resign\n");
return 0;
}

"Hans" <m...@mac.mac> wrote in message
news:45d0ef5b$0$437$c3e...@news.astraweb.com...

Christopher Benson-Manica

unread,
Feb 13, 2007, 11:53:01 AM2/13/07
to
In comp.lang.c Vincent Diepeveen <di...@xs4all.nl> wrote:

> Nice to see Harm-Geert active here too :)

Currently "Here" includes comp.lang.c, and IMHO the discussion has
become sufficiently un-C-like that it would be best to remove
comp.lang.c from the followup list. Thanks. (f'ups set)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.

Guy Macon

unread,
Feb 14, 2007, 11:39:08 AM2/14/07
to


h.g.m...@hccnet.nl said:

> 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.

So the worlds smallest/simplest chess program would make a move,
wait until the other side moves, *then* resign.

Richard Bos

unread,
Feb 15, 2007, 3:36:55 AM2/15/07
to
Guy Macon <http://www.guymacon.com/> wrote:

Just as the world's smallest OS would give you a file, trash it, and
then crash. So why is MS Windows so bleedin' large?

Richard

0 new messages