--- hatetris.html 2010-04-10 03:37:17.491337444 +0100
+++ Downloads/hatetris.html 2010-04-10 03:32:08.264902582 +0100
@@ -65,6 +65,8 @@
var replayOut;
var replayIn;
var replayTimeoutId;
+ var gravityTimeoutId;
+ var gravityInterval = 500;
// draw the current scenery
function drawWell(thisWell) {
@@ -415,6 +417,8 @@
// take user input
document.onkeydown = keyhandler;
+
+ gravityTimeoutId = setTimeout("gravityHandler();", gravityInterval);
}
function showReplay() {
@@ -554,6 +558,14 @@
}
}
+ function gravityHandler() {
+ var down = 2;
+ var gameContinues = transformHandler(down);
+ if(gameContinues) {
+ gravityTimeoutId = setTimeout("gravityHandler();", gravityInterval);
+ }
+ }
+
function keyhandler(event) {
// only handle one key at a time.
@@ -626,4 +638,4 @@
/></p>
</noscript>
</body>
-</html>
\ No newline at end of file
+</html>
I particularly like the fact that the author's top score was five lines and he has absolutely no idea whether it's possible to come up with a strategy to beat the machine (it's completely deterministic).
edit: I've been thinking about it some more, and what's interesting is that you ought to be able to analyze it using regular game theory and prove interesting things about it. There must be an optimal strategy for both players, and there ought to be some highest possible score on the assumption that both players play with optimal strategy. Even if this game is too complicated to fully analyze, perhaps thinner games can be analyzed completely? For instance, is it possible for the computer to prevent the player from getting any lines in a 4x4 game? I _think_ two S shapes, a square and an L would do the trick, but I could be wrong. What if it were four wide by eight high?
If his algorithm is correct, it is known that it is possible to guarantee a loss in truly random Tetris with the right sequence of Ss and then Zs; you can force a hole, and this means that the player must eventually use.
Now, he may not be implementing his "worst possible piece" algorithm correctly, and it is certainly the case that the requisite sequence of Ss and Zs will take its sweet time about killing you.
It looks like he's choosing the worst piece by looking one step ahead. In general, choosing strategies this way can back you into corners. I'd be interested to know whether in this case, looking ahead 1 move is enough to get a global win as well (for the AI).
The paper "How to Lose at Tetris" (http://www.geom.uiuc.edu/java/tetris/tetris.ps) says that you don't even need to know what the player is doing. And that even almost all [1] random tetris games are bound to be lost, even with perfect play.
[1] "Almost all" is a technical term in probability theory and means "with probability 1" (which is not the same as "all games".)
I wonder whether that is equivalent the same technical term from set theory which mean "all except for a finite number of exceptions", and thus with a finite underlying set, it's correct to say that "almost all" elements have a property when in fact none of them have it...
It's similar, but with a finite set it wouldn't show up unless you had some outcomes have probability 0 (in which case, why not just delete them from the outcome space?).
Where you need the idea is in continuous spaces - like a uniform [0,1] random variable. With probability 1 it's not a rational number, etc.
This game would be much more punishing if it did not keep repeating the same piece over and over again. The way that a piece would repeat itself until just before a line is cleared makes the game's AI way too obvious.
He warns that the preferred piece is an S in the docs. But I was able to force the game to generate squares and lines with "good" play. (I could predict by the end which piece it would pick with reasonable accuracy.) To do better (at least based on my watching the high score replays), you have to intentionally "play badly" and make gaps that open up if you clear a middle row of the gap. The 17-replay I saw generated tons of lines, which I honestly wouldn't expect this app to generate.
"56AA AAAA AAA6 AAAA AAAA 8AAA AAAA AB55 AAAA AAAB 00AA AAAA AA9A AAAA AAA6 0AAA AAAA A96A AAA8 AAA9 A808 AAAA AA9A AAAA AAAB 55AA AAAA A82A AAAA AA97 5AAA AA9A AAAA A6AB 5AA6 AAAA 6AAA AAAA C02A AAAA AABF BEAA AAA9 E9AA AAA9 AAAA AAFE AAAA AD5A AAAA F0AA AAA9 BF00 AAAA AA9B AD56 AAAA FC02 AAAA AABA C02A AAAA AB5A AAAA BAAA AAB6 AAAA AB55 6AAA A02A AAAA A82A AAAA ACAA AAAC 02AA AAAA FE9A AAAF EAAA 9D5A AAA9 6AAA AD57 AAAB C2AA A9BF 00AA AAA6 BBF0 0AAA AABA D56A AAC0 2AAA AAD6 AAAB AAAA DAAA A80A AAAA 82AA AAB5 5AAA B2AA A0C0 AAAA AFDA AABF AA9D 5AAA 5AAA 57DA A6AB C2AA 6FC0 2AAA 6BBF 00AA AAEB 00AA AA03 5556 AA02 AAA8 282A AB0A AAB2 AAB6 AA9D AAB5 02AB 55AA 80C2 AAB0 22AB AAD6 AB55 AA00 AA40 AA79 A"
http://speeddemosarchive.com/forum/index.php?topic=11523.msg...