Shortest Tetris Challenge
Author |
Message |
Tony
|
Posted: Sat Feb 02, 2008 4:47 pm Post subject: RE:Shortest Tetris Challenge |
|
|
If you take out the exact specifications of "standard tetris", zylum could make "a tetris" in 20 lines.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
ericfourfour
|
Posted: Sat Feb 02, 2008 5:31 pm Post subject: Re: Shortest Tetris Challenge |
|
|
The file is 2734 Bytes. Each character is 1 Byte. To find out how many lines Zylum used you need to guess the average number of characters per line.
code: | nBytes / nLines = chars / line
nLines = nBytes / (chars / line)
nLines = 2734 / (chars / line) |
Let's try 32 chars / line:
code: | nLines = 2734 / 32
nLines = approx. 85 lines |
Let's try 80 chars / line:
code: | nLines = 2734 / 80
nLines = approx. 34 lines |
My guess is 34 <= zylumLines <= 85.
|
|
|
|
|
|
Tony
|
Posted: Sat Feb 02, 2008 6:55 pm Post subject: RE:Shortest Tetris Challenge |
|
|
Keep in mind that there is a datafile in there as well.
Also, there's a lot of variance in "characters per line".
loop / end loop is 2 lines and only 11 characters.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
zylum
|
Posted: Sat Feb 02, 2008 9:48 pm Post subject: Re: Shortest Tetris Challenge |
|
|
Clayton @ Sat Feb 02, 2008 5:03 pm wrote: Zylum probably did his in 25 lines.
I was hoping to It's harder than it looks to apply the standard rules. Theres a lot more going on in tetris than in pong, and so far the record for that is 19 lines by Catalyst.. The user controls are more complex, there are more variables to keep track of, the collisions are much more complex, the drawing is more complex. You have to collapse the stack once a row is complete... You get the picture
You guys over estimate me a bit I would be lucky to make "a tetris" in 40 lines...
fishtastic> I'm glad you enjoyed the contest And yes, I also used "cheap" tricks, but thats what makes it so fun.. Trying to squeeze out every last line is fun and challenging and makes you look at the problem differently.
As for your program, it's a lot better! Couple of small details though.. The pieces don't generate at the proper place (ie [6, 20]) and some of the pieces don't rotate properly (the I piece for instance), but these problems should be trivial to fix at this point.
So far fishtastic is the only submission. Looking forward to seeing more
BTW here's a slightly shorter version of mine...
Description: |
|
Download |
Filename: |
tetris-short.rar |
Filesize: |
1.08 KB |
Downloaded: |
253 Time(s) |
|
|
|
|
|
|
Clayton
|
Posted: Sun Feb 03, 2008 11:03 am Post subject: RE:Shortest Tetris Challenge |
|
|
I was kind of being a bit sarcastic, but you get my point
|
|
|
|
|
|
fishtastic
|
Posted: Sun Feb 03, 2008 2:07 pm Post subject: Re: Shortest Tetris Challenge |
|
|
here. my newer version.
few lines shorter.
and i think i fixed the rotation.
I will post the code near the of this challenge. since i might change my code again.
Description: |
|
Download |
Filename: |
Fish Tetris (ver 2).zip |
Filesize: |
275.43 KB |
Downloaded: |
220 Time(s) |
|
|
|
|
|
|
ericfourfour
|
Posted: Sun Feb 03, 2008 7:28 pm Post subject: Re: Shortest Tetris Challenge |
|
|
If anyone wants to know a shortcut for doing rotations:
As long as you design your pieces the way the site Zylum linked to did, this should be no problem.
The formula for rotating a point around the origin is:
code: | newX = x * cos theta - y * sin theta
newY = x * sin theta + y * cos theta |
Since we are only rotating counter-clockwise, the angle is: 90 degress (or pi / 2 radians).
code: | newX = x * cos 90 - y * sin 90
newY = x * sin 90 + y * cos 90 |
Since: sin 90 = 1 and cos 90 = 0:
code: | newX = x * 0 - y * 1
newY = x * 1 + y * 0 |
or:
An example of this in Turing:
Turing: | type Point :
record
x, y : int
end record
fcn rotatePoint90 (point : Point) : Point
var newPoint : Point
newPoint.x := -point.y
newPoint.y := point.x
result newPoint
end rotatePoint90 |
If you want to rotate clockwise use theta = 270 (or 3 * pi / 2 radians).
You will also have to compensate for pieces that do not rotate or only rotate once.
|
|
|
|
|
|
fishtastic
|
Posted: Sat Feb 09, 2008 1:23 pm Post subject: Re: Shortest Tetris Challenge |
|
|
Here is my code.
It seems like no one else is doing this challenge, also i don't think i can make it shorter.
although I could use some really meaningless methods (such as putting all variables in one variable using div/mod).
But even if that makes the program having lesser lines, it wont really make the program smaller in size.
I think the contest would be better if it is marked based on the size(in bytes) instead of line number.
anyway. the program is 80 line (by that i mean after f2 and does not generate a not enough memory for indent message.)
I don't think i will have time to work on this since it ends on sunday and i have quite lot of things to do this week.
I would really like to see how zylum did it. zylum's is almost 1kb smaller
(still looks impossible )
Turing: | View.Set ("offscreenonly;graphics:200;300,position:bottom;left,nobuttonbar")
var m, bk, eb : array 1 .. 22, 1 .. 12 of boolean
var g, ol := false
var x, y, cb, dt, score := 0
var nx := Rand.Int (1, 7)
var data : array 1 .. 28 of string := init ("0000000011110000", "0000011001100000", "0000001101100000", "0000011000110000", "0000010001110000", "0000000101110000", "0000001001110000",
"0010001000100010", "0000011001100000", "0000001000110001", "0000000100110010", "0000001100100010", "0000001000100011", "0000001000110010",
"0000000011110000", "0000011001100000", "0000001101100000", "0000011000110000", "0000000001110001", "0000000001110100", "0000000001110010",
"0010001000100010", "0000011001100000", "0000001000110001", "0000000100110010", "0000001000100110", "0000011000100010", "0000001001100010")
var keys : array 1 .. 20 of string := init (KEY_LEFT_ARROW, "1", "0", "0", "1", KEY_RIGHT_ARROW, "-1", "0", "0", "1", KEY_DOWN_ARROW, "0", "1", "0", "20", KEY_UP_ARROW, "0", "0", "1", "1",)
for i : 0 .. 22 * 12 - 1
eb (i div 12 + 1, i mod 12 + 1) := false
m (i div 12 + 1, i mod 12 + 1) := i div 12 + 1 = 1 or i div 12 + 1 = 22 or i mod 12 + 1 = 1 or i mod 12 + 1 = 12
end for
proc newb (b, x, y, sx, sy : int, DM, DB : boolean)
ol := false
g := false
bk := eb
for i : 0 .. 22 * 12 - 1
if i > 0 and i <= 16 and y + (i - 1) div 4 > 0 and x + (i - 1) mod 4 > 0 and x + (i - 1) mod 4 <= 12 and data (b ) (i ) = '1' then
bk (y + (i - 1) div 4, x + (i - 1) mod 4) := true
ol := ol or ((m (y + (i - 1) div 4, x + (i - 1) mod 4)) and y + (i - 1) div 4 < 22)
g := g or ((y + (i - 1) div 4 - 1 > 0 and m (y + (i - 1) div 4 - 1, x + (i - 1) mod 4)) and bk (y + (i - 1) div 4, x + (i - 1) mod 4))
end if
if (m ((i div 12 + 1), (i mod 12 + 1)) and DM ) or (bk ((i div 12 + 1), (i mod 12 + 1)) and DB ) then
drawfillbox (sx + (i mod 12 + 1) * 10 - 8, sy + (i div 12 + 1) * 10 - 8, sx + (i mod 12 + 1) * 10, sy + (i div 12 + 1) * 10, 145)
end if
end for
end newb
loop
cb := nx
nx := Rand.Int (1, 7)
x := 5
y := 19
newb (cb, x, y, 5, 5, true, true)
exit when ol
loop
if hasch then
var key := getchar
for i : 0 .. 3
if key = keys (i * 5 + 1) then
for j : 1 .. strint (keys (i * 5 + 5))
x - = strint (keys (i * 5 + 2))
y - = strint (keys (i * 5 + 3))
cb := (cb + strint (keys (i * 5 + 4)) * 7 - 1) mod 28 + 1
newb (cb, x, y, 5, 5, false, false)
exit when ol
end for
if ol then
x + = strint (keys (i * 5 + 2))
y + = strint (keys (i * 5 + 3))
cb := (cb - strint (keys (i * 5 + 4)) * 7 - 1) mod 28 + 1
end if
end if
end for
end if
dt + = 1
newb (cb, x, y, 5, 5, true, true)
y + = ord (ol ) - ord (dt mod 5 = 0)
exit when g and not ol and dt mod 5 = 0
put "SCORE: ", score
newb (nx, 2, 2, 120, 220, false, true)
View.Update
Time.DelaySinceLast (100)
cls
end loop
for i : 0 .. 22 * 12 - 1
m (i div 12 + 1, i mod 12 + 1) := bk (i div 12 + 1, i mod 12 + 1) or m (i div 12 + 1, i mod 12 + 1)
end for
for decreasing i : 22 - 1 .. 2
if m (i, 11) = true and m (i, 2) = true and m (i, 3) = true and m (i, 4) = true and m (i, 5) = true
and m (i, 6) = true and m (i, 7) = true and m (i, 8) = true and m (i, 9) = true and m (i, 10) = true then
score + = 1
for k : i * 12 .. (22 - 2) * 12
m ((k div 12), k mod 12 + 1) := m ((k div 12) + 1, k mod 12 + 1)
end for
end if
end for
end loop
put "Game Over"
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
zylum
|
Posted: Mon Feb 11, 2008 4:25 am Post subject: RE:Shortest Tetris Challenge |
|
|
OK so the contest is closed with a total of one submissions Before I post my code, I just need to know which prize you would like fishtastic...
BTW I'm quite impressed you made it so short good job!
|
|
|
|
|
|
Tony
|
|
|
|
|
fishtastic
|
Posted: Mon Feb 11, 2008 3:30 pm Post subject: Re: RE:Shortest Tetris Challenge |
|
|
zylum @ Mon Feb 11, 2008 3:25 am wrote: OK so the contest is closed with a total of one submissions Before I post my code, I just need to know which prize you would like fishtastic...
I dont really think mine is short enough to compare with yours.
first one please : Bits = round (10000 / max (lines - 50, 1)) - 50
BTW I remember seeing 1kb tetris in flash before, just cant find the site anymore....
|
|
|
|
|
|
Clayton
|
Posted: Mon Feb 11, 2008 3:44 pm Post subject: RE:Shortest Tetris Challenge |
|
|
Turing: | if Sys.Exec ("tetris.exe") then
put "Tetris in 3 lines, go me."
end if |
I'll take option one, as that results in 9950 bits.
|
|
|
|
|
|
Tony
|
|
|
|
|
Clayton
|
Posted: Mon Feb 11, 2008 3:48 pm Post subject: RE:Shortest Tetris Challenge |
|
|
but that way you don't get my gloating-ness, also, what the hell does true/false mean to the end user?
|
|
|
|
|
|
StealthArcher
|
Posted: Mon Feb 11, 2008 5:34 pm Post subject: RE:Shortest Tetris Challenge |
|
|
Turing: | var owned: boolean:= Sys.Exec("tetris.exe") |
|
|
|
|
|
|
|
|