Hello.
Doing anything in just 20 lines is already in itself a challenge.
But if the intention is to make something as complex as a game of chess mission moves from difficult to nearly impossible.
And unfortunately for me, that sort of thing I like light attracts moths.
He made two codes.
They are identical except that one creates its own "media" and the other needs of the images that I have put into the download.
Anyone who creates their own images is a 20+6 lines.
I am afraid I have not been able to put in all 20 lines.
The second code if it is 20 lines, but needs images.
It has not been easy to codify the rules of the game of chess, making the party so that the human player moves and above all, make a rudimentary AI to play the computer.
Already warning that anyone expect something as simple and basic as having a level playing like Kasparov.
Rather plays as they would a child.
But until that is something tremendamnte compound.
Anyone who has ever tried to make a chess comprising what I mean.
Code 1:
set display mode 1024,768,32:sync on:sync rate 60:backdrop on:color backdrop 0:autocam off:set ambient light 0:point light 0,-.6,-1.7,5.8:dim g(12,12):dim j(3,3000,5):dim e(12000):q=10:make object sphere 1,1,24,24:f(9,2,1,0,7):make object cylinder 4,1
f(9,5,4,0,7):make object cone 6,1:set text opaque:f(9,7,6,0,7):set normalization on:f(9,0,2,-4,4):f(1,100,40,100,1):f(2,40,40,40,1):f(2,0,1.1,0,2):f(4,94,q,94,1):f(4,0,-.1,0,2):f(5,20,100,20,1):f(5,0,.5,0,2):dim s$(4):set text size 40:f(6,60,60,60,1)
f(6,0,.5,0,2):f(7,40,8,40,1):f(7,0,.93,0,2):f(0,0,0,0,1):f(9,3,1,0,7):f(2,35,54,35,1):f(2,0,.3,0,2):f(3,15,15,15,1):f(3,0,1.71,0,2):f(5,0,.4,0,2):f(7,40,20,40,1):f(7,0,.26,0,2):f(0,0,0,0,2):make object cube 8,1:color object 8,0:f(2,58,25,58,1)
f(2,0,-.08,0,2):f(3,45,25,45,1):f(3,0,-.7,0,2):f(5,55,35,55,1):f(5,0,.62,0,2):f(6,95,160,95,1):f(6,0,.39,0,2):f(7,50,140,50,1):f(7,180,15,0,3):f(7,0,.6,0,2):f(8,q,20,90,1):f(8,0,1.6,0,2):f(0,0,0,0,3):delete object 8:f(2,55,20,55,1):f(2,0,.4,0,2)
f(3,50,q,50,1):f(3,0,.2,0,2):f(5,30,130,30,1):f(5,0,-.4,0,2):f(6,80,60,80,1):f(6,0,-.45,0,2):f(7,55,30,55,1):f(7,0,-.95,0,2):f(0,0,0,0,5):make object cube 8,1:f(9,9,8,0,7):f(8,4,24,4,1):f(8,0,1.9,0,2):f(8,0,45,0,3):f(9,20,4,4,1):f(9,0,1.93,0,2)
f(9,45,0,0,3):f(0,0,0,0,6):f(2,150,50,1,1):f(2,0,-1,0,2):f(2,149,-103,-18,3):f(3,q,q,q,1):f(3,145,0,-q,3):f(3,0,-.22,0,2):f(5,15,50,15,1):f(5,0,-.1,0,2):f(5,0,0,-30,3):f(7,75,70,75,1):f(7,0,0,0,3):f(7,0,-.7,0,2):f(7,0,0,-30,3):f(8,45,30,25,1)
f(8,0,0,0,3):f(8,0,-.6,0,2):f(9,100,50,50,1):f(9,0,0,0,3):f(9,0,-.19,0,2):f(9,0,0,35,3):perform csg difference 8,9:f(8,-19,0,0,3):f(9,q,q,q,1):f(9,0,0,27,3):f(9,0,-.33,0,2):f(9,-82,387,127,3):f(0,0,0,0,4):for t=1 to 168:if t<7:sprite t,0,900,t
scale sprite t,25:endif:if t<17:read null:else if t<21:read s$(t-16):endif:endif:g(t)=-1:next t:for l=3 to q:for c=3 to q:read g(l,c):next c:next l:offset sprite 1,0,30:delete objects 1,9:cls 0x302050:f(9,0,0,0,8):f(9,0,0,-8.4,4):tr=1:do:f(1,fx,fy,0,9)
if jm:f(jm,0,0,0,6):endif:mc=mouseclick():if tr=1:if jq:text 30,timer()/q mod 700,"CHECK":endif:mx=mousex():my=mousey():ck=(ck+mc)*mc:px=2+(mx-37)/95:py=2+(my+91)/95:On=pick object(mx,my,1,1):if ck=1 and On:k=g(py,px):if k>0 and k<7:fx=px:fy=py:v=k:ox=mx
oy=my:endif:endif:if mc=0:if v>0 and On:b=g(py,px):if b=0 or b>q:gosub MOV:if er=0:g(fy,fx)=0:g(py,px)=v:tr=0:if b=16:jm=3:endif:endif:endif:endif:fx=0:v=0:else:if v>0:line ox,oy,mx,my:endif:endif:else:tr=0:y=0:gosub POS:if i=0:jm=4:else:i1=i:i6=0:jr=jq
vf=-999:pc=1:for t1=1 to i1:dy=j(0,t1,0):dx=j(0,t1,1):hy=j(0,t1,2):hx=j(0,t1,3):g(dy,dx)=0:bc=j(0,t1,4):g(hy,hx)=bc+q:tr=0:y=2:gosub POS:jb=jq:v3=j(0,t1,5):if v3=6:vt=999:jr=0:else:tr=1:y=1:gosub POS:if i=0:vt=v3*5:else:jr=0:i2=i:v2=0:v4=0:pp=0
for t2=1 to i2:ay=j(1,t2,0):ax=j(1,t2,1):by=j(1,t2,2):bx=j(1,t2,3):if by=hy and bx=hx:pp=1:endif:g(ay,ax)=0:nc=j(1,t2,4):fa=j(1,t2,5):g(by,bx)=nc:g=fa-q:if g=6:jr=1:endif:sw=0:tr=0:y=2:gosub POS:if jq=0:jb=0:endif:for t=1 to i:uy=j(2,t,2):ux=j(2,t,3)
lo=j(2,t,5):if uy=by and ux=bx and g<v3:sw=1:endif:if lo>v4:lk=0:for t3=1 to i2:if uy=j(1,t3,2) and ux=j(1,t3,3) and lo>j(2,t,4):lk=1:endif:next t3:if lk=0:v4=lo:endif:endif:next t:g=g-(nc*sw):if g>v2:v2=g:endif:g(ay,ax)=nc:g(by,bx)=fa:next t2
vt=((v3*5)-(bc*5*pp))-(v2*5)+(v4/3)-(99*jr):if jb=1:vt=999:endif:endif:endif:if jr=0:if vt>=vf:if vt>vf:vf=vt:i6=1:else:i6=i6+1:endif:e(i6)=t1:endif:endif:g(dy,dx)=bc+q:g(hy,hx)=v3:next t1:if vf=-999:tr=1:y=0:gosub POS:if jq=1:jm=1:else jm=4:endif:endif
if vf=999:jm=2:endif:if jm=2 or jm=0:i=e(1+rnd(i6-1)):d1=j(0,i,0):d2=j(0,i,1):d3=j(0,i,2):d4=j(0,i,3):f(d1,d2,d3,d4,10):g(d3,d4)=j(0,i,4)+q:if j(0,i,5)=6:jm=3:endif:endif:tr=0:y=0:gosub POS:tr=1:fx=0:v=0:endif:endif:sync:loop
POS:i=0:jq=0:for fy=3 to q:for fx=3 to q:v=g(fy,fx):if (tr=0 and v>q) or (tr=1 and v>0 and v<7):if v>q:v=v-q:endif:for py=3 to q:for px=3 to q:b=g(py,px):if (tr=0 and b<7) or (tr=1 and (b=0 or b>q)):gosub MOV:if er=0:inc i:j(y,i,0)=fy:j(y,i,1)=fx
j(y,i,2)=py:j(y,i,3)=px:j(y,i,4)=v:j(y,i,5)=b:if b=6 or b=16:jq=1:endif:endif:endif:next px:next py:endif:next fx:next fy:return
MOV:er=0:a=abs(px-fx):d=abs(py-fy):e=fy-py:if v=2 or v=5:if a*e=0 or a<>d:er=1:else:gosub CHK:endif:endif:if v=3 or (v=5 and er=1):er=0:if a*e<>0:er=1:else:gosub CHK:endif:endif:if v=1:if (tr=1 and a=0 and e=2 and fy=9) or (tr=0 and a=0 and e=-2 and fy=4)
if a*e<>0:er=1:else:gosub CHK:endif:else:sw=0:if a=0 and b<>0:sw=1:endif:if (tr=1 and (a>1 or e<>1 or (a=1 and b<7) or sw=1)) or (tr=0 and (a>1 or e<>-1 or (a=1 and (b=0 or b>6)) or sw=1)):er=1:endif:endif:endif:if v=4:restore DAT:er=1:for t=1 to 8
read sy,sx:tx=fx+sx:ty=fy+sy:c=g(ty,tx):if tx=px and ty=py and ((tr=1 and (c=0 or c>6)) or (tr=0 and c>=0 and c<7)):er=0:endif:next t:endif:if v=6:if a>1 or d>1 or (b>0 and b<7 and tr=1) or (b>6 and tr=0):er=1:endif:endif:return
CHK:sx=0:sy=0:if py<fy:sy=-1:else if py>fy:sy=1:endif:endif:if px<fx:sx=-1:else if px>fx:sx=1:endif:endif:ix=fx:iy=fy:tx=px-sx:ty=py-sy:if v=1:ty=ty+sy:endif:while ix<>tx or iy<>ty:ix=ix+sx:iy=iy+sy:if g(iy,ix)<>0:er=1:exit:endif:endwhile:return
function f(o,x#,y#,z#,a):q=512:if o=0:sync:get image a,432,58,592,444,1:else:if a=9:for l=3 to 10:for c=3 to 10:t=g(l,c):if (t=1 and l=3) or (t=11 and l=10):t=t+4:g(l,c)=t:endif:if t>0:if t<7:f(t,255,255,0,5):if l=y# and c=x#:f(t,255,0,0,5):endif:else
t=t-10:f(t,120,120,0,5):endif:f(t,c,l,0,11):endif:next c:next l:endif:if a=10:n=x#:d=g(o,n)-10:g(o,n)=0:y1#=o:x1#=x#:sty#=(y#-o)/90.0:stx#=(z#-x#)/90.0:for t=1 to 90:y1#=y1#+sty#:x1#=x1#+stx#:f(1,0,0,0,9):f(d,120,120,0,5):f(d,x1#,y1#,0,11):sync:next:endif
if a=1:scale object o,x#,y#,z#:endif:if a=8:box 257,1,q,257:box 1,257,255,q:ink 0xFFA000,0:get image 7,1,1,q,q:make object plain 1,10,10:scale object texture 1,4,4:texture object 1,7:endif:if a=4:position camera 0,y#,z#:point camera 0,0,0:endif:if a=11
paste sprite o,x#*95-125,y#*95-287:endif:if a=2:move object up o,y#:endif:if a=3:rotate object o,x#,y#,z#:endif:if a=5:set sprite diffuse o,x#,y#,y#:endif:if a=6:center text q,334,s$(o):sync:wait key:end:endif:if a=7:clone object x#,y#:endif:endif:endfunction
DAT:data -2,-1,-2,1,-1,2,1,2,2,1,2,-1,1,-2,-1,-2,"Checkmate, you win","Checkmate, you lost","King died","Tied",13,14,12,16,15,12,14,13,11,11,11,11,11,11,11,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,3,4,2,6,5,2,4,3
Code 2:
set display mode 1024,768,32:sync on:sync rate 60:backdrop on:color backdrop 0:autocam off:set ambient light 50:point light 0,-.6,-1.7,5.8:dim g(12,12):dim j(3,3000,5):dim e(12000):q=10:dim s$(4):for t=1 to 168:if t<7:load image "F"+str$(t)+".png",t,1
sprite t,0,900,t:scale sprite t,25:endif:if t<17:read null:else if t<21:read s$(t-16):endif:endif:g(t)=-1:next t:for l=3 to q:for c=3 to q:read g(l,c):next c:next l:offset sprite 1,0,30:set text size 40:cls 0x302050:f(9,0,0,0,8):f(9,0,0,-8.4,4):tr=1:do
f(1,fx,fy,0,9):if jm:f(jm,0,0,0,6):endif:mc=mouseclick():if tr=1:if jq:text 30,timer()/q mod 700,"CHECK":endif:mx=mousex():my=mousey():ck=(ck+mc)*mc:px=2+(mx-37)/95:py=2+(my+91)/95:On=pick object(mx,my,1,1):if ck=1 and On:k=g(py,px):if k>0 and k<7:fx=px
fy=py:v=k:ox=mx:oy=my:endif:endif:if mc=0:if v>0 and On:b=g(py,px):if b=0 or b>q:gosub MOV:if er=0:g(fy,fx)=0:g(py,px)=v:tr=0:if b=16:jm=3:endif:endif:endif:endif:fx=0:v=0:else:if v>0:line ox,oy,mx,my:endif:endif:else:tr=0:y=0:gosub POS:if i=0:jm=4:else
i1=i:i6=0:jr=jq:vf=-999:pc=1:for t1=1 to i1:dy=j(0,t1,0):dx=j(0,t1,1):hy=j(0,t1,2):hx=j(0,t1,3):g(dy,dx)=0:bc=j(0,t1,4):g(hy,hx)=bc+q:tr=0:y=2:gosub POS:jb=jq:v3=j(0,t1,5):if v3=6:vt=999:jr=0:else:tr=1:y=1:gosub POS:if i=0:vt=v3*5:else:jr=0:i2=i:v2=0
v4=0:pp=0:for t2=1 to i2:ay=j(1,t2,0):ax=j(1,t2,1):by=j(1,t2,2):bx=j(1,t2,3):if by=hy and bx=hx:pp=1:endif:g(ay,ax)=0:nc=j(1,t2,4):fa=j(1,t2,5):g(by,bx)=nc:g=fa-q:if g=6:jr=1:endif:sw=0:tr=0:y=2:gosub POS:if jq=0:jb=0:endif:for t=1 to i:uy=j(2,t,2)
ux=j(2,t,3):lo=j(2,t,5):if uy=by and ux=bx and g<v3:sw=1:endif:if lo>v4:lk=0:for t3=1 to i2:if uy=j(1,t3,2) and ux=j(1,t3,3) and lo>j(2,t,4):lk=1:endif:next t3:if lk=0:v4=lo:endif:endif:next t:g=g-(nc*sw):if g>v2:v2=g:endif:g(ay,ax)=nc:g(by,bx)=fa:next t2
vt=((v3*5)-(bc*5*pp))-(v2*5)+(v4/3)-(99*jr):if jb=1:vt=999:endif:endif:endif:if jr=0:if vt>=vf:if vt>vf:vf=vt:i6=1:else:i6=i6+1:endif:e(i6)=t1:endif:endif:g(dy,dx)=bc+q:g(hy,hx)=v3:next t1:if vf=-999:tr=1:y=0:gosub POS:if jq=1:jm=1:else jm=4:endif:endif
if vf=999:jm=2:endif:if jm=2 or jm=0:i=e(1+rnd(i6-1)):d1=j(0,i,0):d2=j(0,i,1):d3=j(0,i,2):d4=j(0,i,3):f(d1,d2,d3,d4,10):g(d3,d4)=j(0,i,4)+q:if j(0,i,5)=6:jm=3:endif:endif:tr=0:y=0:gosub POS:tr=1:fx=0:v=0:endif:endif:sync:loop
POS:i=0:jq=0:for fy=3 to q:for fx=3 to q:v=g(fy,fx):if (tr=0 and v>q) or (tr=1 and v>0 and v<7):if v>q:v=v-q:endif:for py=3 to q:for px=3 to q:b=g(py,px):if (tr=0 and b<7) or (tr=1 and (b=0 or b>q)):gosub MOV:if er=0:inc i:j(y,i,0)=fy:j(y,i,1)=fx
j(y,i,2)=py:j(y,i,3)=px:j(y,i,4)=v:j(y,i,5)=b:if b=6 or b=16:jq=1:endif:endif:endif:next px:next py:endif:next fx:next fy:return
MOV:er=0:a=abs(px-fx):d=abs(py-fy):e=fy-py:if v=2 or v=5:if a*e=0 or a<>d:er=1:else:gosub CHK:endif:endif:if v=3 or (v=5 and er=1):er=0:if a*e<>0:er=1:else:gosub CHK:endif:endif:if v=1:if (tr=1 and a=0 and e=2 and fy=9) or (tr=0 and a=0 and e=-2 and fy=4)
if a*e<>0:er=1:else:gosub CHK:endif:else:sw=0:if a=0 and b<>0:sw=1:endif:if (tr=1 and (a>1 or e<>1 or (a=1 and b<7) or sw=1)) or (tr=0 and (a>1 or e<>-1 or (a=1 and (b=0 or b>6)) or sw=1)):er=1:endif:endif:endif:if v=4:restore DAT:er=1:for t=1 to 8
read sy,sx:tx=fx+sx:ty=fy+sy:c=g(ty,tx):if tx=px and ty=py and ((tr=1 and (c=0 or c>6)) or (tr=0 and c>=0 and c<7)):er=0:endif:next t:endif:if v=6:if a>1 or d>1 or (b>0 and b<7 and tr=1) or (b>6 and tr=0):er=1:endif:endif:return
CHK:sx=0:sy=0:if py<fy:sy=-1:else if py>fy:sy=1:endif:endif:if px<fx:sx=-1:else if px>fx:sx=1:endif:endif:ix=fx:iy=fy:tx=px-sx:ty=py-sy:if v=1:ty=ty+sy:endif:while ix<>tx or iy<>ty:ix=ix+sx:iy=iy+sy:if g(iy,ix)<>0:er=1:exit:endif:endwhile:return
function f(o,x#,y#,z#,a):q=512:if a=9:for l=3 to 10:for c=3 to 10:t=g(l,c):if (t=1 and l=3) or (t=11 and l=10):t=t+4:g(l,c)=t:endif:if t>0:if t<7:f(t,255,255,0,5):if l=y# and c=x#:f(t,255,0,0,5):endif:else:t=t-10:f(t,120,120,0,5):endif:f(t,c,l,0,11):endif
next c:next l:endif:if a=10:n=x#:d=g(o,n)-10:g(o,n)=0:y1#=o:x1#=x#:sty#=(y#-o)/90.0:stx#=(z#-x#)/90.0:for t=1 to 90:y1#=y1#+sty#:x1#=x1#+stx#:f(1,0,0,0,9):f(d,120,120,0,5):f(d,x1#,y1#,0,11):sync:next:endif:if a=8:box 257,1,q,257:box 1,257,255,q
ink 0xFFA000,0:get image 7,1,1,q,q:make object plain 1,10,10:scale object texture 1,4,4:texture object 1,7:endif:if a=4:position camera 0,y#,z#:point camera 0,0,0:set text opaque:endif:if a=11:paste sprite o,x#*95-125,y#*95-287:endif:if a=5
set sprite diffuse o,x#,y#,y#:endif:if a=6:center text q,334,s$(o):sync:wait key:end:endif:endfunction
DAT:data -2,-1,-2,1,-1,2,1,2,2,1,2,-1,1,-2,-1,-2,"Checkmate, you win","Checkmate, you lost","King died","Tied",13,14,12,16,15,12,14,13,11,11,11,11,11,11,11,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,3,4,2,6,5,2,4,3
I hope you like.
A greeting.