Smallest Tetris Clone? Antoni Gual Posting Freak Posts: 1,407 Threads: 117 Joined: Dec 2002 08-03-2007, 06:48 PM Program a tetris clone in the smallest possible source size. The only condition is it must be playable, no fancy graphics required ASCII or graphics, QB or FB. Only built-in keywords allowed, no libraries! Some people says it can be done in 100 lines or less.. Antoni Deleter Posting Freak Posts: 1,025 Threads: 44 Joined: May 2005 08-06-2007, 11:36 PM (This post was last modified: 08-06-2007, 11:49 PM by Deleter.) pshhhhh 100, 79 is all you need: (fb code) Code:```screen 12 dim myblock(-1 to 16,31) as integer, score as integer ,px as integer=7 ,py as integer=3 , gameover as integer ,myblockdata(6,2,2) as integer={{{0,1,0},{0,1,0},{0,1,0}},{{0,0,0},{0,1,0},{1,1,1}},{{1,1,0},{1,0,0},{1,0,0}},{{0,1,1},{0,0,1},{0,0,1}},{{0,0,0},{1,1,0},{0,1,1}},{{0,0,0},{0,1,1},{1,1,0}},{{0,0,0},{1,1,0},{1,1,0}}},tm as double=timer,godown as integer,newblock as integer for tmpy as integerÂ  = 15 to 0 step -1 Â  Â  for tmpx as integer =0 to 4 Â  Â  Â  Â  if tmpx<3 and tmpy < 3 then if myblockdata(2,tmpy,tmpx) then myblock(px+tmpx,py+tmpy)=-1 Â  Â  Â  Â  myblock(iif(tmpx<2,-1,iif(tmpx<4,16,tmpy)),iif(tmpx=1 or tmpx=3,tmpy+16,iif(tmpx=4,30,tmpy)))=1 next tmpx,tmpy do Â  Â  locate 1,1 Â  Â  ? "Level:"+str((int(score/2500)+1))+chr(13)+chr(10)+"Score:"+str(score) Â  Â  for tmpx as integer = 0 to 30*16-1 Â  Â  Â  Â  if myblock((tmpx mod 16),int(tmpx/16))<>0 then line((tmpx mod 16)*20+160,(int(tmpx/16)-6)*20)-((tmpx mod 16)*20+20+158,(int(tmpx/16)-6)*20+20-2),7,bf else line((tmpx mod 16)*20+160,(int(tmpx/16)-6)*20)-((tmpx mod 16)*20+20+159,(int(tmpx/16)-6)*20+20-1),8,bf Â  Â  next tmpx Â  Â  sleep 50,1 Â  Â  sleep 500-(int(score/2500)+1)*50 Â  Â  newblock=int(rnd*5) Â  Â  if timer-tm>(.5-(int(score/2500)+1)*.05) or multikey(80) then godown=-1 else godown=0 Â  Â  dim canrotate as integer =-1, donttouch as integer =0,canmove as integer =-1, rotdata(2,2,1) as integer=>{{{2,0},{1,0},{0,0}},{{2,1},{1,1},{0,1}},{{2,2},{1,2},{0,2}}},tmpblock(-1 to 3,2) as integer=>{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},myxdir as integer=multikey(75)*2+1 Â  Â  if multikey(72) then Â  Â  Â  Â  for tmpx as integer=0 to 9-1 Â  Â  Â  Â  Â  Â  if myblock(px+(tmpx mod 3),py+int(tmpx/3))<> 0 then Â  Â  Â  Â  Â  Â  Â  Â  if myblock(px+(tmpx mod 3),py+int(tmpx/3))=-1 thenÂ  Â  tmpblock((tmpx mod 3),int(tmpx/3))=myblock(px+(tmpx mod 3),py+int(tmpx/3)) Â  Â  Â  Â  Â  Â  Â  Â  if myblock(px+(tmpx mod 3),py+int(tmpx/3))=-1 thenÂ  Â  if myblock(px+rotdata((tmpx mod 3),int(tmpx/3),0) , py+rotdata((tmpx mod 3),int(tmpx/3),1)Â  )<>0 then if myblock(px+rotdata((tmpx mod 3),int(tmpx/3),0),py+rotdata((tmpx mod 3),int(tmpx/3),1))=1 then canrotate=0 Â  Â  Â  Â  Â  Â  end if Â  Â  Â  Â  next tmpx Â  Â  Â  Â  if canrotate=-1 then Â  Â  Â  Â  Â  Â  for tmpx as integer=0 to 9-1 Â  Â  Â  Â  Â  Â  Â  Â  if myblock(px+rotdata((tmpx mod 3),int(tmpx/3),0),py+rotdata((tmpx mod 3),int(tmpx/3),1))<> 0 then if myblock(px+rotdata((tmpx mod 3),int(tmpx/3),0),py+rotdata((tmpx mod 3),int(tmpx/3),1))=1 then donttouch=-1 Â  Â  Â  Â  Â  Â  Â  Â  if donttouch=0 then myblock(px+rotdata((tmpx mod 3),int(tmpx/3),0),py+rotdata((tmpx mod 3),int(tmpx/3),1))=tmpblock((tmpx mod 3),int(tmpx/3)) else donttouch=0 Â  Â  Â  Â  Â  Â  Â  Â  tmpblock((tmpx mod 3),int(tmpx/3))=0 Â  Â  Â  Â  Â  Â  next tmpx Â  Â  Â  Â  end if Â  Â  elseif (multikey(75) xor multikey(77)) and (px+multikey(75)*2+1 >-2 ) and (px + multikey(75)*2+1 < 15) then Â  Â  Â  Â  for tmpx as integer = 0 to 9-1 Â  Â  Â  Â  Â  Â  if myblock(px+(tmpx mod 3),py+int(tmpx/3))<>0 then if myblock(px+(tmpx mod 3),py+int(tmpx/3))=-1 then if myblock(px+(tmpx mod 3)+myxdir,py+int(tmpx/3))<>0 then if myblock(px+(tmpx mod 3)+myxdir,py+int(tmpx/3))=1 then canmove=0 Â  Â  Â  Â  Â  Â  if myblock(px+(tmpx mod 3),py+int(tmpx/3))<>0 then if myblock(px+(tmpx mod 3),py+int(tmpx/3))=-1 then tmpblock((tmpx mod 3),int(tmpx/3))=myblock(px+(tmpx mod 3),py+int(tmpx/3)) Â  Â  Â  Â  next tmpx Â  Â  Â  Â  if canmove then Â  Â  Â  Â  Â  Â  px+=myxdir Â  Â  Â  Â  Â  Â  for tmpx as integer = iif(myxdir=-1,0,-1) to iif(myxdir=-1,3,2) Â  Â  Â  Â  Â  Â  for tmpy as integer =0 to 2 Â  Â  Â  Â  Â  Â  Â  Â  if myblock(px+tmpx,py+tmpy)<>0 then if myblock(px+tmpx,py+tmpy)=1 then donttouch=-1 Â  Â  Â  Â  Â  Â  Â  Â  if donttouch=0 then myblock(px+tmpx,py+tmpy)=tmpblock(tmpx,tmpy) else donttouch=0 Â  Â  Â  Â  Â  Â  next tmpx,tmpy Â  Â  Â  Â  end if Â  Â  end if Â  Â  if godown=-1 then Â  Â  Â  Â  canmove=-1 Â  Â  Â  Â  for tmpx as integer=0 to 9-1 Â  Â  Â  Â  Â  Â  if myblock(px+(tmpx mod 3),py+int(tmpx/3))<>0 then if myblock(px+(tmpx mod 3),py+int(tmpx/3))=-1 then if myblock(px+(tmpx mod 3),py+int(tmpx/3)+1)<>0 then if myblock(px+(tmpx mod 3),py+int(tmpx/3)+1)=1 then canmove=0 Â  Â  Â  Â  next tmpx Â  Â  Â  Â  for tmpx as integer = 4*3-1 to 0 step -1 Â  Â  Â  Â  Â  Â  if canmove=0 thenÂ  Â  if int(tmpx/3)<3 then if myblock(px+(tmpx mod 3),py+int(tmpx/3))<>0 then myblock(px+(tmpx mod 3),py+int(tmpx/3))=1 Â  Â  Â  Â  Â  Â  if canmove=0 thenÂ  Â  if int(tmpx/3)<3 then if myblockdata(newblock,int(tmpx/3),(tmpx mod 3)) then myblock(7+(tmpx mod 3),int(tmpx/3)+3)=-1 Â  Â  Â  Â  Â  Â  if canmove<>0 thenÂ  Â  if myblock((tmpx mod 3)+px,int(tmpx/3)+py)<>0 then if myblock((tmpx mod 3)+px,int(tmpx/3)+py)=1 then donttouch=-1 Â  Â  Â  Â  Â  Â  if canmove<>0 thenÂ  Â  if myblock((tmpx mod 3)+px,int(tmpx/3)+py-1)<> 0 then if myblock((tmpx mod 3)+px,int(tmpx/3)+py-1)=1 then donttouch=-1 Â  Â  Â  Â  Â  Â  if canmove<>0 thenÂ  Â  if myblock((tmpx mod 3)+px,int(tmpx/3)+py-1)<> 0 then if myblock((tmpx mod 3)+px,int(tmpx/3)+py-1)=1 then if myblock((tmpx mod 3)+px,int(tmpx/3)+py)<>0 then if myblock((tmpx mod 3)+px,int(tmpx/3)+py)=-1 then myblock((tmpx mod 3)+px,int(tmpx/3)+py)=0 Â  Â  Â  Â  Â  Â  if canmove<>0 thenÂ  Â  if donttouch=0 then myblock((tmpx mod 3)+px,int(tmpx/3)+py)=myblock((tmpx mod 3)+px,int(tmpx/3)+py-1) else donttouch=0 Â  Â  Â  Â  next tmpx Â  Â  Â  Â  if canmove=0 then py=3 else py+=1 Â  Â  Â  Â  if canmove=0 then px=7 Â  Â  end if Â  Â  if timer-tm>(.5-(int(score/2500)+1)*.05) then tm=timer Â  Â  dim exists as integer , shiftdown as integer =0 Â  Â  for tmpx as integer= 30*16-1 to 0 step -1 Â  Â  Â  Â  if (tmpx mod 16)=15 then exists=-1 Â  Â  Â  Â  if (myblock((tmpx mod 16),int(tmpx/16))<>0) thenÂ  Â  if myblock((tmpx mod 16),int(tmpx/16))=-1 then exists=0 else if int(tmpx/16)=6 then gameover=-1 Â  Â  Â  Â  if (myblock((tmpx mod 16),int(tmpx/16))<>0) thenÂ  Â  if int(tmpx/16)<30-shiftdown then if myblock((tmpx mod 16),int(tmpx/16))=1 and shiftdown>0 then myblock((tmpx mod 16),int(tmpx/16)+shiftdown)=myblock((tmpx mod 16),int(tmpx/16)) Â  Â  Â  Â  if (myblock((tmpx mod 16),int(tmpx/16))<>0) thenÂ  Â  if int(tmpx/16)<30-shiftdown then if myblock((tmpx mod 16),int(tmpx/16))=1 and shiftdown>0 then myblock((tmpx mod 16),int(tmpx/16))=0 Â  Â  Â  Â  if (myblock((tmpx mod 16),int(tmpx/16))=0) thenÂ  Â  exists=0 Â  Â  Â  Â  if (tmpx mod 16)=0 and exists=-1 then Â  Â  Â  Â  Â  Â  for tmpx2 as integer =0 to 15 Â  Â  Â  Â  Â  Â  Â  Â  myblock(tmpx2,int(tmpx/16)+shiftdown)=0 Â  Â  Â  Â  Â  Â  Â  Â  score+=10 Â  Â  Â  Â  Â  Â  next Â  Â  Â  Â  Â  Â  shiftdown+=1 Â  Â  Â  Â  end if Â  Â  next loop until multikey(1) or gameover``` not a single #define or colon.... edit: modified, now only 79 lines... Antoni Gual Posting Freak Posts: 1,407 Threads: 117 Joined: Dec 2002 08-10-2007, 02:25 AM Great work, Deleter! Tetris is a game that I always was afraid of coding, it looked too complicated to me. If it can be reduced to 79 lines I will grasp it one of these days. BTW: I must change that avatar of mine, I guess It'sÂ  scaring young people.. Antoni Dav Administrator Posts: 440 Threads: 65 Joined: Sep 2001 08-12-2007, 06:34 AM Nice one, Deleter. Small & complete! Visit Dav's Qbasic Site « Next Oldest | Next Newest »