Skip to content

Setting up the Protocol

tangentstorm edited this page May 6, 2013 · 1 revision

the test protocol

The tests communicate with your game through standard i/o.

To make this happen, you will need to create a very simple interactive prompt that allows the test to issue commands.

Here are the first three commands:

cmd meaning notes
q quit quit the loop
p print print the state of the board
g given as in: /given the following data…/

The p and g commands deal with 2d arrays of characters, which you will need to to be able to read and generate. The characters are separated by spaces and newlines, which you will need to insert when printing and discard when reading.

Here is an example of what the format looks like:

:. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :. . . . . . . . . . :… m … r r . :… m m . r r y y :… m c c c c y y

The 22 lines correspond to the official Tetris matrix. (The official size is 10 × 20. The Tetriminos spawn in the extra 2 lines at the top.)

The . character is meant to indicate an empty square, and the letters represent colors.

The color codes are:

char meaning tetramino
. empty n/a
m magenta T
c cyan I
b blue J
r red Z (or N)
g green S
y yellow O
o orange L

q / quit

When the input

p / print

g / given

This command will be followed by 22 lines, each containing 10 space-separated characters. For example:

Clone this wiki locally