Computer Chess Created In 487 Bytes, Breaks 32-Year-Old Record
An anonymous reader writes: The record for smallest computer implementation of chess on any platform was held by 1K ZX Chess, which saw a release back in 1983 for the Sinclair ZX81. It uses just 672 bytes of memory, and includes most chess rules as well as a computer component to play against. The 32-year-old record has been beaten this week by the demoscene group Red Sector Inc. They have implemented a fully-playable version of chess called BootChess in just 487 bytes (readme file including source code).
Next you'll be telling me you can create operating systems in less than 15GB!
or "play-worthy" ?
There's a difference.
0 GOSUB 10000
1 INPUT "DO YOU WANT INSTRUCTIONS (Y OR N)?",A$: IF A$#"Y" AND A$#"N" THEN 1: IF A$="Y" THEN GOSUB 30000
2 REF=5: CALL -936
3 INPUT "COMPUTER TO PLAY WHITE(0) OR BLACK(1)",WHO
4 IST=0
5 DIM WC(99),BC(99)
6 DIM V(6),P(26),C(3)
7 DIM KING(16)
8 DIM A(70)
10 DIM M(120),W(120),B(120),I(6)
11 DIM G(100)
12 FOR X=1 TO 120:M(X)=0: NEXT X
14 FOR X=1 TO 99:W(X)=0:B(X)=0: NEXT X
15 FOR X=2 TO 9:X1=10*X:X2=X1+1:M(X1)=7:M(X2)=7: NEXT X
16 DIM STR$(10),FILE$(8),RANK$(8)
17 FILE$(1)="A":FILE$(2)="B":FILE$(3)="C":FILE$(4)="D":FILE$(5)="E":FILE$(6)="F":FILE$(7)="G":FILE$(8)="H"
18 RANK$="12345678"
20 FOR K=1 TO 21:K2=K+99:M(K)=7:M(K2)=7: NEXT K
22 FOR K=32 TO 39:K2=K+50:M(K)=1:M(K2)=-1: NEXT K
23 M(22)=4:M(23)=2:M(24)=3:M(25)=5:M(26)=6:M(27)=3:M(28)=2:M(29)=4
25 FOR K=22 TO 29:K2=K+70:M(K2)=-M(K): NEXT K
30 I(1)=12:I(2)=15:I(3)=10:I(4)=1:I(5)=6:I(6)=6
35 V(1)=1:V(2)=3:V(3)=3:V(4)=5:V(5)=9:V(6)=10
40 P(1)=-1:P(2)=1:P(3)=10:P(4)=-10:P(5)=0:P(6)=1:P(7)=-1
45 P(8)=10:P(9)=-10:P(10)=-9:P(11)=-11:P(12)=9:P(13)=11:P(14)=0
50 P(15)=8:P(16)=-8:P(17)=12:P(18)=-12:P(19)=19:P(20)=-19
55 P(21)=21:P(22)=-21:P(23)=0:P(24)=10:P(25)=20:P(26)=0
60 C(1)=8:C(2)=0:C(3)=3
80 IF WHO=1 THEN 90
85 M(25)=6:M(26)=5:M(95)=-6:M(96)=-5
90 GOSUB 5000
93 FOR II=1 TO 120:W(II)=0:B(II)=0: NEXT II
95 IF WHO=1 THEN 100:T2=0: GOTO 1000
100 REM MAKE MOVE
101 GOSUB 4000
105 Z9=0
110 GOSUB 4200
115 GOSUB 5000: IF WHO=0 THEN 1000
116 M9=M9+1: IF M9>REF THEN 120
117 IF T2>4 THEN 120: IF IST=1 THEN GOTO 120
118 F2=9-F2:T2=9-T2: GOSUB 4200: GOSUB 5000: GOTO 100
120 REM FILL CONTROL ARRAYS
122 N8=0:IST=1
125 FOR X1=22 TO 99:WC(X1)=0:BC(X1)=0: IF M(X1)=6 THEN BKING=X1: IF M(X1)=-6 THEN WKING=X1: NEXT X1
130 FOR X=22 TO 99: IF M(X)<1 THEN 170: IF M(X)=7 THEN 170: GOSUB 8000: IF N9=0 THEN 170
150 FOR X1=1 TO N9:TO=G(X1)-G(X1)/100*100: IF M(TO)>0 THEN 168
164 N8=N8+1:A(N8)=G(X1)
168 BC(TO)=BC(TO)+1
169 NEXT X1
170 NEXT X
172 FOR X=22 TO 99: IF M(X)>-1 THEN 180: GOSUB 8000
173 IF N9=0 THEN 180
174 FOR X1=1 TO N9:TO=G(X1)-G(X1)/100*100:WC(TO)=WC(TO)+1
176 NEXT X1
180 NEXT X
181 GOTO 3000: REM CASTLE LOGIC
182 REM FILL KING CONTROL ARRAY
184 KING(1)=BKING+1:KING(2)=BKING-1:KING(3)=BKING+10:KING(4)=BKING-10
185 KING(5)=BKING+11:KING(6)=BKING-11:KING(7)=BKING+9:KING(8)=BKING-9
186 KING(9)=WKING+1:KING(10)=WKING-1:KING(11)=WKING+10:KING(12)=WKING-10
187 KING(13)=WKING+11:KING(14)=WKING-11:KING(15)=WKING+9:KING(16)=WKING-9
190 V9=-10000:I9=0: FOR X4=1 TO N8:N4=0:F4=A(X4)/100
210 T4=A(X4)-F4*100:F5=M(F4):T5=M(T4)
212 REM FIND MOVES OFPIECE IN PRESENT POSTION.
214 X=F4: GOSUB 8000
225 M(T4)=M(F4):M(F4)=0
235 GOSUB 9000: IF N4<=V9 THEN 255
245 V9=N4:F9=F4:T9=T4
255 M(F4)=F5:M(T4)=T5:
256 Z9=Z9+1: IF Z9>20 THEN Z9=1: TAB 26: VTAB Z9: PRINT F4;" : ";T4;" V= ";N4
259 NEXT X4
270 F1=F9:T1=T9:M(T1)=M(F1):M(F1)=0:F6=F1-F1/10*10-1:F7=10-F1/10:T6=T1-T1/10*10-1:T7=10-T1/10
280 IF WHO=1 AND F1=22 THEN QROOK=1
281 IF WHO=1 AND F1=29 THEN KROOK=1
282 IF M(T1)=6 THEN MKING=1
283 IF WHO=0 AND F1=22 THEN QROOK=1
284 IF WHO=0 AND F1=29 THEN KROOK=1
310 PRINT "FROM ";F6;F7
Toldja, 640 bytes otta be enough for anyone. -Gill Bates
Table-ized A.I.
They have altered the rules. Pray they do not alter it further.
It would be cool to see which programming languages could have the best short chess programs.
I'd nominate Haskell, scheme and prolog to try it in.
From the readme:
Underpromotion may be understandable, maybe en-passant since it doesn't come up that oftean, but castling makes a ton of games unplayable.
Also, purists consider anything that implements these three rules to be a better record than something that omits three rules.
BootChess vs1K ZX Chess
Probably a bit like watching snails race, but snail-races can get interesting.
I’m old enough to remember 16K of memory being described as “whopping”
the fifty-move rule which states that the game may end in a draw if you play 50 moves without any pawns moved or any captures made
FTFY. It doesn't end automagically, a player has to invoke that rule explicitly.
(or 100 moves in certain special board states).
I've never heard about that, but the wikipedia article you linked says that this rule was in effect from 1952-1992. It's not anymore
I'm willing to call this proof of concept as chess even if it doesn't fully implement that.
We don't need no proof of concept for chess, it's kind of an old thing. The point here is to fit the stuff in <512 bytes, which they say they couldn't do without leaving away en passant, castling, etc. So I don't really see how this is proving any concept.
That being said, It's pretty impressive to implement what they did in this little amount of storage. It's just not chess. Now get off my lawn.
CLI paste? paste.pr0.tips!
Buggy? Incomplete?
Perhaps they intend to work in the games industry.
Priest: "Universe from nothing, no laws of physics, sped up time"+ huge discrepancies. Creationism? No. Big Bang Theory
... when you consider the ZX81 chess was written in Z80 assembler whereas this is in x86 asm and although both have variable sized instructions the x86 will on average be larger.
It would be a lot more impressive if they went to 2k and had it actually working. I can understand the motivation to play code golf, but every code golf I've played requires a fully correct answer to earn the right to count the bytes.
Why can't people like you just appreciate the technical accomplishment instead of nit picking.
Tell you what - why not go away and try and write any type of chess program then get back to us?
As someone who has written a chess program which even after some code optimisation still came out at ~3000 lines of C, I can tell you this is damn impressive.
You're right if by 100+ you mean 100+(600). Castling was introduced in the 1300s. En Passant in the 1400s.
Support the First Amendment. Read at -1
Actually, it does end automatically. I've seen it happen playing chess online. In an OTB (over-the-board) game, I am convinced a draw would be agreed upon well beforehand unless one player was going for a time win.
Regardless, your selective quote left out the end: "In the 20th century it was discovered that some positions of certain endgames can only be won in more than fifty moves (without a capture or a pawn move). The rule was changed to include certain exceptions in which one hundred moves were allowed with particular material combinations. However, more and more exceptions were discovered and in 1992 FIDE abolished all such exceptions and reinstated the strict fifty-move rule."
Some people die at 25 and aren't buried until 75. -Benjamin Franklin
My source states that a checkerboard has 64 squares, like a chessboard.
Well, the real question is if this program was replicating the same rules as the one that was previously accepted and supposedly beat?
Like the previous record holder, this program implements neither en passant nor castling.
Unlike the previous record holder, this program implements queening, so it is both smaller and has an additional feature.