Tuesday, January 13, 2009

Why Do I Waste My Time Like This?

A week ago, my best "friend" Brian suggested I install Tetris Friends to my Facebook (I refer to it as FB Tetris). Why did I let him talk me into such a cataclysmic waste of time?

I've concentrated on the Sprint variant. FB Tetris Sprint requires the player to optimize clearing 40 lines with respect to time. In other words, clear 40 lines fast.

To get better at Tetris Sprint, it is a matter of math, really:

1 line = 10 blocks
1 piece = 4 blocks
1 game = 40 lines

40 lines = 40 * 10 blocks = 400 blocks
400 blocks / 4 blocks / piece = 100 pieces

To finish this game, you need at least 100 pieces to fall. That represents a perfect, waste-free game, which never happens. There are no line "bonuses" that get you to 40 lines any faster than 100 pieces. Since we are optimizing for time and there is always going to be waste, the questions is:

How much time does each block cost?

My computer isn't sufficiently precise or powerful enough to record the games and replay them, frame by frame, to see the latency cost incurred while doing certain tetris game actions such as:
  • dropping a piece straight down ("Hard Drop")
  • swapping a piece in/out of the single-piece buffer
  • clearing a line/lines (it should be noted that the time it takes to clear 4 lines is the same amount of time it takes to clear 1 line)
  • moving a piece right/left
  • latency between pressing "Hard Drop" and getting the next piece in play
The only other actions involved with tetris are:
  • thinking
  • reacting to misplaced pieces
Additionally, I haven't recorded myself playing to measure the latency of my eyes skipping around the screen.
  • your eyes will move back and forth between the piece and the playing area
  • your eyes will move around between the 2nd, 3rd, etc pieces and the playing area
  • your eyes will move right and left as you consider where to drop the piece.
I do not consider using the "Soft Drop" reasonable. You are wasting my time and yours if you think you can compete using that button.

Turns out that of all the time-consuming things above, time lost to thinking dominates all the others. In trying to optimize for time, you want to improve the areas that promise the greatest rewards first. It also turns out that latency related to eye movement is usually associated with thinking.

My FB Tetris Fundamental Assertion (FTFA): If you want to compete in FB Tetris Sprint, stop thinking.

Each of these thinking activities turns out to be counter-productive (for most players):
  • Planning to clear multiple lines at a time. Don't do it. If you lose 1/2 second to game planning, you have already wasted more time than the game takes up clearing 3 singles. Defeated.
  • Planning multiple pieces ahead. Don't fall victim to this. Eye movement back and forth and the pause needed to mentally place them erase the rewards for multiple lines.
  • Moving your eyes up to see the next piece. Your eyes must stay put. Memorize the colors and use your periphery. If your eyes are moving, your fingers are not. Generally, you'll put your eyes where you want the piece to go and use the "Hard Drop" once the shadow is there, correctly oriented.
  • Changing your mind. Go with your gut and never look back. When you've identified the next piece to come into play and identified it's resting place, never alter that plan. Moving pieces costs finger movement and time to move across board "space."
  • Using the one-piece buffer. This is about the worst thing most people can do. If it isn't enough that you've moved your eyes around to identify the piece in play and moved them back and forth across the board to locate a place for it only to determine not to use it, you then move your eyes up to the buffer piece and repeat the same series of actions. The one piece ends up costing you between 3-5 pieces, or 12-20 blocks. At the end of the day, that one buffer piece cost you two lines. If you are using the suggestion below to lay pieces flat, the worst that will happen is you have a hole which will open up in 3-5 pieces anyway. No time/lines lost.
  • Caring about where a piece lands. Sure, you meant for it to be somewhere else. It isn't. Don't ever think about it again, just play the next piece.
On the other hand, try to do the following:
  • Lay pieces flat. Laying them flat means a smaller likelihood of blocks being left behind vertically at the end. It also means less likelihood of multi-line clears, which reduces the need to think.
  • Use peripheral vision. Discussed above, this shaves worlds of time off.
  • Minimize movement and rotation. After you get good at memorizing the next piece coming into play, you'll recognize its initial orientation. In this implementation of Tetris, it is always starts out the same (which is merciful). You've identified the piece, your eyes see it's location, you know the destination location and orientation, so your fingers can get right to work, all the way to the Hard Drop before the shadow gets there. You should never rotate a piece more than two (2) times, and worse case you shouldn't move it right/left more than 5 key presses.
  • Press right/left at the same time you press rotate. Instead of losing the amount of time it takes to press 5 keys, you lose the amount of time it takes to press 3.
  • Intentionally rotate the proper/intended direction. Teach both fingers to rotate. Don't just always rotate clockwise. You'll rotate much less, and find that you don't get lost with the expected vs. real orientation only to rotate a time or two more, which also consumes tons of time. You have to wait for the game to catch up with you. For advanced Tetris players, your mind is already trained to do this. Think like Neo. "Know you're faster."
  • Keep your eyes glued to the middle of the board. Especially as you lay things flat, it will be easy and obvious where pieces should go, so your eyes will need to move less. This shaves tons of time.
In the worst game (academically speaking of course) your keypresses would be:

(5 (r/l) + 2 (rotation)) * 100 = 700

Although that is severly overstated because of (at least) the following:
  • That assumes every piece is a straight piece moved against the wall
  • You can press r/l and rotation buttons simultaneously
  • That assumes a perfect, wasteless game
So even a very exaggerated count would be:

5 (r/l/rot) * 100 = 500

Assuming that only one in four pieces will need to be moved to either edge as a worst case scenario and that the others can be positioned with at most 3 r/l movements:

25 * 5 (r/l/rot) + 75 * 3 (r/l/rot) = 75 + 225 = 300 key presses

Again, the 2 rotation key presses are done concurrently with the r/l movement key presses, so there is no need to count them explicitly. Even if you consider the possibility of having a relatively clean board, with say 10 wasted pieces (which is a ton), you just 10 * 3 = 30 more serialized key presses.

All this leads to the following:

330 key presses is sufficient to finish any game of FB Tetris Sprint.

In case you've missed how profound a realization that is, read it again. To win a game of FB tetris, you can count a very finite and relatively small number of actions you will be required to make. This means you can start eating the clock.

We could get a better approximation by using statistical methods, but I'm not good enough to do so, and the time won back won't be precise enough to make a difference. 330 is a very good approximation for the purposes of online, Flash-based Tetris.

Go ahead and try it. Press a key (or several different keys) 330 times in a row. This is your ideal game time - your time to beat. In reality, that isn't the case because NOW the other factors you have less control over come into play:
  • latency between next in-play piece
  • latency to clear line/lines
  • latency to move piece right/left after pressing the button
  • latency to rotate a peice after pressing a button
  • latency for a Hard Drop to fall
Although #1, #3 and #4 can be ignored because everybody has to do it, so it isn't time "lost" but rather time "required."

So assuming you have mastered all the above skills, the only things left are:
  • latency to clear line/lines
  • latency for a Hard Drop to fall
If you are at this point and you are optimizing even more, the way to resolve #1 above is to clear 10 perfect Tetris. es. (How do you pluralize Tetris?) That represents the time "required" to play the game. This requires being able to see not just the piece in play, but all 4 subsequent pieces in your periphery and mentally rotate/place them before you get them in play.

The only way to resolve the second one that I can think of is to make the board shorter. You would do that by sparsely dropping the first number of pieces such that you build a "platform" 1/3 to 2/3 the way up the board, and simply clear the 40 lines on a higher baseline plane. Shorter distance to fall, quicker piece turnaround time.

This, however, will likely violate the FTFA noted above (stop thinking). I suspect the time it would take to appropriately configure the pieces into a platform alone would eliminate the amount of time you gain back from drop-time latencies. Assuming it doesn't, you would likely lose time due to more strategic piece placement (to avoid death being closer to the top).

Having thought about all of this, I don't have a theoretical "best" game time, but I don't know that it matters. I also don't have a feel for how different computers may affect game time (better processor speeds, faster RAM, more RAM, springs in the keyboards, etc). At the end of the day, we aren't good enough to blame our game time on the responsiveness of the keys or handling times of the interrupts.

So, bringing it back to the original question, each block costs some sort of combination of turnaround time, rotation/relocation time, Hard Drop time and line clearing time - none of which are really measurable. However, the statistics the game provides helps us out quite a bit with the "Tetrominoes Per Minute" ("TPM") metric.

Think about it. My best time isn't that great: 1:38.45 or 1.64 minutes (98.45 seconds). My TPM? 67.03 (1.12 per second). That particular game, I played a total of 110 pieces, which represents an average amount of waste. This means that if you want your times to be fast, you just have to play more pieces per minute. I'll assume 110 pieces in a game. Consider your net time if you get your TPM very, very high:

69.4 TPM = 1:35
73.3 TPM = 1:30
77.6 TPM = 1:25
82.5 TMP = 1:20
88 TPM = 1:15

Of course, you'll likely have more waste at the end, but you didn't die which means that you're clearing lines. Tons faster. An interesting side note is that if you are wasting, you're slowly getting your baseline "platform" higher, which shaves little bits of time off the Hard Drop latency. The extra waste incurred isn't a substantial cost of time.

The net result? Keep your eyes down and count to 100. For each piece that falls, count. Play dirty. Play sloppy. Play quickly. If you concentrate on counting more than you concentrate on playing traditional "clean" Tetris, your times will drop. Quite a bit.

And maybe I'll see some competition. Say what you will about why I waste my time like this, but you just read it all, so poo on your face. Who's the bigger time waster?