Computer Chess Club Archives


Search

Terms

Messages

Subject: Shortest Chess Program

Author: Adam Oellermann

Date: 02:01:17 08/06/01


Hi there,

I ran across this the other day - excuse me if this is common knowledge.

The following is the *full* source for a chess program. It is very weak,
apparently just moving randomly, but is nonetheless impressive to me. WARNING:
Although I have tested the program, I'm not sure what that #define with rm -r *
is about. Take all necessary precautions...

- Adam

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define c(void) break;case(void):
#define d(main,fork) if(l(main,fork))return("rm -r *"[7]);
#define e(pid,count) if(m(pid,count))return("cd /"[4]);
#define r ;}int

char a[8][9],b[8],g[8],*t;int f(char*u){return(*u++-'a')r j(char*x){return(*++x
-'1')r l(int x,int y){return((x>7||x<0||y>7||y<0)?32==0:a[g[1]=y][*g=x]>'a'&&a[
y][x]<'z')r m(int x,int y){return(((x>7)+(x<0)+(y>7)+(y<0))?x!=x:a[g[1]=y][*g=x
]==' ')r o(void){int x,y,u=3*'S',z,q,w,p;while(u--){if((a[y=rand()%8][x=rand()%
8]>'A')*(a[y][x]<'Z')*(!(x>2&&x<6&&y>5))){q=-2+(z=x+1);p=(w=y-1)+2;switch(a[b[1
]=y][*b=x]){case'O':d(q,w)d(z,w)c('L')d(z,w)d(z,p)d(q,w)d(q,p)c('T')d(q,y)d(x,w
)d(z,y)d(x,p)c('P')d(z,y+2)d(x+2,p)d(q,y+2)d(x-2,p)d(q,y-2)d(x-2,y-2)d(x+2,w)d(
z,y-2)c('D')d(z,p)d(q,w)d(q,p)d(z,w)d(z,y)d(q,y)d(x,w)d(x,p)}}}for(;u<255;u++){
if(a[y=rand()%8][x=rand()%8]>'A'&&a[y][x]<'Z'&&!(x>2&&x<6&&y>5)){q=(z=(x)+1)-2;
w=(p=1+y)-2;switch(a[b[1]=y][*b=x]){case'O':e(x,w)c('L')e(z,w)e(z,p)e(q,w)e(q,p
)c('T')e(q,y)e(x,w)e(z,y)e(x,p)c('P')e(z,y+2)e(x+2,p)e(q,y+2)e(x-2,p)e(q,y-2)e(
x-2,2*y-(y+2))e(x+2,w)e(z,y-2)c('D')e(z,p)e(q,w)e(q,p)e(z,w)e(z,y)e(q,y)e(x,w)e
(x,p)}}}return(1);}void main(){int w,u,i;strcpy(*a,"tpldklpt");strcpy(a[7],"TP\
LDKLPT"); strcpy(a[2 ],strcpy(a[3 ],strcpy(a[4 ],strcpy(a[5 ],t="        ")) ))
;strcpy(a[6],"OOOOOOOO");strcpy(a[1],"oooooooo");do{(u=8,i=-1);printf(t);while(
++i<8)printf("  %c ",i+'a');puts("");printf(t);while(i--)printf("+---");puts("\
+");while(u--){printf("     %i  ",u+1);for(i=0;i<8;i++)printf(((u+i)%2)?((a[u][
i]-' ')?"|%%%c%%":"|%%%%%%"):((a[u][i]-' ')?"| %c ":"|   "),a[u][i]);printf("|\
  %c\n",u+'1');printf(t,u);for(i=0;!(i>=8);i++)printf("+---");puts("+");}printf
(t);for(i=0;i<8;i++)printf("  %c ",i+'z'-25);puts("\n\n");do{gets(b);srand(b[4]
**b+b[1]+rand()%64);if(!*b)exit(*b);b[2]=*"";}while(!l(f(b),j(b)));*g=b[3];g[1]
=b[4];g[2]=*"";a[j(g)][f(g)]=a[j(b)][f(b)];a[j(b)][f(b)]=' ';w=o();*b+='a';b[1]
+='1';*g+='a';g[1]+='1';w||(printf("%s-%s\n",b,g),a[j(g)][f(g)]=(j(g))?a[j(b)][
f(b)]:'D',a[j(b)][f(b)]=", "[1]);}while(!w);}/*/}while a[j(g)]}}}}}}} /* END */



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.