o9s
is a microblog
home archives search feed blogroll


Tiny Tetris

19 lines of BASIC code

In 2002, Curtis F. Kaylor programmed a Tetris game for Commodore VIC-20 in just 19 lines of code.

1 REM PETRIS (C)2002 CURTIS F KAYLOR
2 T$="{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT} {RIGHT}{RIGHT} {RIGHT}{RIGHT}{RIGHT}  {RIGHT} {RIGHT}{RIGHT}{RIGHT} {RIGHT} {RIGHT}  {RIGHT}{RIGHT}    {RIGHT}{RIGHT}{RIGHT} {RIGHT}{RIGHT}  {RIGHT} {RIGHT} {RIGHT}    {RIGHT}{RIGHT}  {RIGHT}    {RIGHT}    "
3 DIMT$(15):FORI=0TO15:T$(I)=MID$(T$,4*I+1,4):NEXT:DIMB%(6,3,3):DIMP(23)
4 B$="DDDD@O@@DDDD@O@@@FDD@GA@@AAC@DG@@FBB@AG@@DDF@GD@@BFB@BG@@BCB@GB@@ACB@FC@"
5 B$=B$+"@ACB@FC@@DFB@CF@@DFB@CF@@FF@@FF@@FF@@FF@":FORI=0TO6:FORJ=0TO3:FORK=0TO3
6 Z=Z+1:B%(I,J,K)=ASC(MID$(B$,Z))AND15:NEXT:NEXT:NEXT:FORI=0TO19:P(I)=4097:NEXT:P(I)=8191
7 PRINT"{CLR}":FORI=0TO20:P=P(I):PRINT"{RVS ON}"T$(P/4096)T$(P/256AND15)T$(P/16AND15)T$(PAND15):NEXT
8 PRINT "{UP}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RVS ON}PETRIS";S
9 X=5:Y=0:B=7*RND(0):C=0:D=2:PRINT"{HOME}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}{DOWN}";:R=1
10 IFRTHEND$="":FORI=0TO3:D$=D$+T$(B%(B,C,I))+"{DOWN}{LEFT}{LEFT}{LEFT}{LEFT}":NEXT:D$=D$+"{UP}{UP}{UP}{UP}"
11 PRINT CHR$(93*ABS(M)+64*M)"{RVS ON}";D$;:IF M+R THEN M=0:R=0:GOTO14
12 GET K$:M=(K$="{RIGHT}")-(K$="{DOWN}"):R=(K$=" "):IFMTHENX=X+M:GOSUB16:IFZTHENX=X-M:M=0
13 IFRTHENC=C-RAND3:GOSUB16:IFZTHENC=C+RAND3:R=0
14 IF M+R=0 THEN Y=Y+1:GOSUB16:IF Z THEN Y=Y-1:ONSGN(Y)GOTO17:END
15 PRINT"{RVS OFF}"D$;CHR$(-17*(M+R=0));:GOTO10
16 Z=0:T=2^X:FORI=0TO3:Z=Z+(P(Y+I)ANDB%(B,C,I)*T):NEXT:RETURN
17 A=0:FORI=0TO3:P(Y+I)=P(Y+I)ORB%(B,C,I)*T:IFP(Y+I)=8191ANDY+I<20THENGOSUB19
18 NEXT:ONDGOTO7,9
19 FORZ=Y+ITO1STEP-1:P(Z)=P(Z-1):NEXT:P(0)=4097:D=1:A=A+10:S=S+A:RETURN

Sleeping Elephant

Less than 512 bytes of JavaScript and HTML

This is by far the best entry of @MaximeEuziere's #golfctober combo: A full TETRIS game by @veubeke 🐌 in less than 512 bytes of HTML and JavaScript!

▶ Play: https://t.co/O1cT6PszSz
ℹ️ Source: https://t.co/SmpSv7g3kj

With help from @benjamin_js, @Fusselwurm and @aemkei (me). pic.twitter.com/01cl8vSHyR

— Martin Kleppe (@aemkei) October 12, 2017

1 line of BBC BASIC V code

Rheolism is a one-liner Tetris game. It was written after a programmer bet another programmer that it was impossible.

Rheolism

0MODE9:OFF:GCOL-9:CLG:REPEATs=s+VPOS:PRINTCHR$30s:REPEATSYS6,135TOi,p,d:PRINTTAB
(p=0)CHR$9;:IFPOS=22VDU3100;VPOS,21;6667;:UNTIL0ELSEUNTILVPOS=25:v=ABSRNDMOD7:VD
U31:COLOUR3:REPEATm=9-INKEY(INKEYTRUEOR6)MOD3:FORr=TRUETO1:t=rANDSGNt:IFt=rCOLOU
Rv-15:VDUrEORm:i+=m=7AND9-6*r:IF0ELSEFORn=0TO11:d=nDIV3OR2EORd:VDUd:IF1<<(n+i)MO
D12AND&amp;C2590ECDIV8^vAND975t+=POINT(p*POS,31-VPOS<<5):IFrVDUp,8:IF0ELSENEXT,:VDU2
0:UNTILt*LOGm:UNTILVPOS=3:Z

Rheolism

On a B&W camcorder viewfinder CRT

The screen size is 14x7x5 mm and the playing field is 7x5 mm.

Under a microscope

A real-life implementation of the evergreen arcade game Tetris was obtained by optically trapping 42 glass microspheres (1 μm or 0.001 mm diameter) in a 25 μm x 20 μm sized area under a microscope. Their positions are then steered with a computer.”

Posted on 2018-01-23   #tetris     #basic     #javascript  






← Next post    ·    Previous post →