Learntris

Learntris

Take the Learntris Challenge!

Learntris is a programming challenge: a set of automated tests that guide you through implementing a simple version of Tetris, the famous Russian falling blocks game.

Is this a tutorial?

Nope.

A tutorial shows you how to do something. A programming challenge tells you what to do, but it's up to you to figure out the implementation.

You can use any programming language, libraries, or tools you like, as long as your solution passes the tests.

What do the tests look like?

Each test is a short script of commands sent to your program, plus the output it should print. Here is an early one:

Input to your program

T t q

These are commands on stdin, not command-line arguments.

Expected output

  • T (upper case) spawns a T tetromino.
  • t (lower case) prints the current tetromino.
  • q quits the program.

The letter m is a magenta-colored block, and . is an empty space. The printout is the tetromino in its bounding box, which is always a square so it can rotate.

How does it work?

The challenge is composed of a series of acceptance tests that specify input to be sent to your program along with the expected output.

To work through the challenge, you install a small python program called tanco and tell it how to run your program on your local machine.

You run tanco login to connect to the challenge server, tanco init to select and start a challenge, and tanco check to make sure it can run your program.

Next, you log into the server with your web browser to read and run the tests. When you start, it will look something like this:

The tanco web interface at the start of a challenge

The circles in the upper right indicate your connection status. The rightmost circle is green because this browser has a websocket open to the server.

The left circle is red because tanco has not yet connected to the server. The tanco share tells tanco to open its own websocket connection to share your program with the server.

The tests are given to you in sequence, one at a time, so at the start, there are no tests. You use the tanco next command (or the "Next" button in the web interface) to take on a new test. You must pass all the current tests before you can add a new one.

The reason you have to explicitly ask for each test is so that between tests, you have time to make changes to your program and run all the previously passed tests to make sure you haven't broken anything.

The workflow looks like this:

The tanco workflow: login, check, share, next, and pass tests

Here is how that same early test, shape.T, appears in the tanco web interface:

The tanco web interface showing test shape.T with title, description, input T t q, and the expected T tetromino printout

Tests are written in tanco's org-mode format (version 0.2). Here is the same test as it appears in the test file:

*** TEST shape.T : The T Tetramino

#+begin_src
> T t q
. m .
m m m
. . .
#+end_src

The T is is colored magenta and spawns upside down in a 3x3 matrix.

The TEST headline names the test and gives it a title. Lines that start with > are input sent to your program. The other lines in the source block are the expected output. The description comes after the block.

Once you've implemented enough tests, you will have the internal logic for a simple version of Tetris. You can then write your own frontend, or you can use the graphical lt-shell to play the game on your own machine. (Note: lt-shell is usable, but still under development. Maybe you can help?)

The graphical lt-shell playing a game

What does it cost?

Nothing! Learntris is free!

Wait. Why is it free?

I wrote the Learntris test suite many years ago (early 2010s) while mentoring programming students over IRC. At the time it only ran in the terminal, and the interface was quite clunky.

As of 2024, I'm working on a new series of programming courses that follow this approach. I built tanco so that I could make much richer and more interactive challenges (like adding diagrams or allowing students to choose different paths), and also so I can see what students are doing and figure out where they need help.

Anyway, since Learntris has always been free, I decided to keep it that way. My hope is that people will try it out, I'll get feedback on the test platform, and maybe some of you will like it enough to sign up for future challenges.

If you want to know more about future developments, you can join our discord server or the tangentcode-news mailing list.

But who are you?

Oh, right. :)

My name's Michal, but I go by @tangentstorm online.

Okay, How do I take the challenge?

You need to install tanco and set things up. The tanco setup page will step you through it.

Have fun!