1 of 11

Why we Build Algorithms w/Tetris

2 of 11

What do we mean by algorithms?

  • Really just a set of instructions for completing a given task
  • Often attributed to mathematics and coding
  • May be familiar with algorithm for Rubiks cube
  • Can be a lot of things, so why and how do we create them?
    • Solve problems, do things more efficiently, do things faster, anything else?

3 of 11

Tetris Rules:

Ok so obviously I’m not gonna spell out every rule but there is some general game strategy:

  1. A Tetris gets the greatest point value with 4 rows cleared
  2. Build low and dense
  3. The randomizer generally deals a uniform distribution of pieces in the short game
    1. in other words, play assuming no repeats
  4. Every block serves a different function within building but we’re more worried about general shape

Lines cleared

Points

1 line clear

100 points x level

2 line clear

300 points x level

3 line clear

500 points x level

Tetris

800 points x level

4 of 11

Let’s Watch some Pros…

5 of 11

So, watching this, we have some things to think about for any given piece dropping

Keep the build relatively flat

Don’t leave gaps

Leave a column open for Tetris

Don’t build completely flat for S and Z

If you’re not holding an I and you get one, hold it and build more

Stack columns opposite the open column

Only soft drop if necessary (try to build w/o)

6 of 11

And obviously these guys are thinking of all of these things but who can keep all that in their head at one time?

This is clearly wildly inefficient

We should come up with a list of precedence in which we can continuously build well given any piece

We should also have a mental list of the best situation for any piece

7 of 11

Build an algorithm such that you can be presented with any piece and have a spot that is ideal for it and allows for continuation of the algorithm.

Purpose:

8 of 11

We could even think of this as if/else

If:

And:

Then: fill these spots

Else: Wait for these and build higher

9 of 11

One more if/else

If: hold has something other than an I piece

and there is an I piece currently dropping

Then: move I piece to hold

and build with current hold piece

10 of 11

So let’s write our precedence list:

We’ve gone over what individual pieces do, so let’s consider the choices we can make for any piece…

  1. Do not leave gaps when possible
    1. This means not leaving gaps is more important than keeping flat
    2. Creating a column is fine if it means not creating a gap
  2. Keep building flat but…
    • Keep at least one or two divots, depth 1 or 2
  3. Hold I pieces when you get them
    • Unless you have one in your hold, in which case use it to tetris
    • Unless you don’t have a tetris ready, in which case defer to previous steps
  4. When you need to stack columns…
    • Try to keep them opposite your tetris column (so you have more time to pivot I pieces)
  5. Always play assuming you will get an I within 7 moves

11 of 11

What do we learn about algorithms as a whole from this?

  • Fewer cases makes for simpler algorithms
  • Knowing set cases up front helps so you don’t get lost in generalization
  • Approach should start wide with definition and then narrow in to exact processes
  • You don’t need to have seen every case to be able to account for most cases
  • Precedence is necessary