World smallest chess program

K

Keith Thompson

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

Keith Thompson

David Richerby said:
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.
 
J

james of tucson

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

Barry Schwarz

(e-mail address removed) wrote:



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

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


Remove del for email
 
R

Richard Heathfield

CBFalconer said:

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

ais523

Keith said:
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).
 
G

Guy Macon

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... :)
 
W

William Hughes

Guy said:
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... :)

On a Cray it executes in 15 seconds.

- William Hughes
 
G

Guy Macon

David said:
[...] 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/>
 
R

Richard Tobin

ais523 said:
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
 
R

Richard Bos

William Hughes said:
On a Cray it executes in 15 seconds.

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
 
D

Dr A. N. Walker

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?
 
R

Richard Tobin

<OT>Running this program on a multi-user system is likely to anger
your fellow users.</OT>
[/QUOTE]
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...

-- Richard
 
D

David Richerby

ais523 said:
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.
 
D

David Richerby

Keith Thompson said:
<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.
 
W

William Hughes

David said:
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
 
M

MikeC

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.



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
 
H

Hans

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.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top