Skip to content

abdoitman/Tetris-Competition

Repository files navigation

Tetris Competition

tetris-multicolored-pattern-4u7ed6koskqhcez1

Files needed to participate in the friendly Tetris contest either to run the game locally or to submit a solution to the server.

Table of Contents


The contest is a game of Tetris where each team will try to implement the best algorithm to play the game and score the most points in 90 seconds by clearing more and more lines.

Each team can try and play the game locally as many times as they wish but will only have 10 submissions to the API from which their score will be calculated.
Although each team have 10 submissions to the API, their final ranking among other teams will be based on the average of their highest 3 runs.

The game field of a game of tetris consists of 10 tiles in width and 20 tiles in height with the falling point of the tetrominos in the middle of top row.
The origin point of the game field sets at the upper left corner with the positive x-axis in the right direction and the positive y-axis in the downward direction.


In the game, there are 7 shapes (tetrominos) that you'll be moving and playing with which are: L, J, S, Z, O, T, and I tetrominos. Each of the 7 falling tetrominos (shapes) consists of 4 blocks with different combination describing the tetromino. Note that on the game grid, the y axis is inverted, meaning that downwards is the positive y direction. Also the falling point of the tetrominos is (0, 5).

To represent a Tetromino, consider an origin point that all building blocks will be placed relative to, then the tetrominos are as following:


Note: The game has an FPS of 120, which means the tetrominos fall at a rate of 2 tiles per second.
Tetrominos can have to types of controlled movements:

  1. Linear Movement: Moving right, left, and, downwards.

    • Each tetromino falls by it's origin point; meaning that at the tetromino always starts falling with its origin point on (0,5).
    • Moving a tetromino downwards will cause it to hard drop untill it hits another tetromino or the ground.
  2. Rotational Movement: Rotating Clockwise and Conter-Clockwise.

    • When rotating a tetromino, it rotates around its origin point and it won't rotate if it's new position afterwards will be coliding with a wall or another tetromino.

7-bag randomizer is the algorithm determining which tetromino gets generated next based on some rules:

  1. During the span of any 7 moves, each tetromino should get generated at least once.
  2. No tetromino should get generated 3 times in a row.

This algorithms treats the randomization of the tetrominos as if they were drawn from a bag and refiling the bag when it gets empty.


First you need to install the required packages using:

pip install -r requirements.txt

Secondly, to test your algorithm locally, go to local_submission.py file and implement the algorithm inside local_solver function:

def local_solver(logical_map, current_tetromino, next_tetromino, time_left, level, score, lines_cleared) -> list:
    return []

At each state (before the next tetromino starts falling) this function will provide you with the following information:

  • logical_map : 20x10 binary numpy array providing you with the state of game field, with each element representing a cell in the game field. Each element can be 0 if that cell is empty on the game field, or a 1 if that cell has a block.
  • current_tetromino : String representing the shape of the falling tetromino in this move.
  • next_tetromino : String representing the shape of the faling tetromino in nex|t move.
  • time_left : Integer indicating the time left in seconds.
  • level : Integer indicating the current level of the player. (Explained more in detail in Scoring)
  • lines_cleared : Integer indicating the total lines cleared in the game so far.

The function should return a list of instructions to control the tetromino. Valid instructions are the following:

  • "MOV_L" → Makes the tetromino move 1 tile to the left (if possible).

  • "MOV_R" → Makes the tetromino move 1 tile to the right (if possible).

  • "MOV_D" → Makes the tetromino hard drop.

  • "ROT_CW" → Makes the tetromino rotate clockwise (if possible).

  • "ROT_CCW" → Makes the tetromino rotate counter clockwise (if possible).


Scoring points in the game depends solely on 2 parameters: lines_cleared at the time and level of the player.

Points per line

Points awarded after clearing the lines depends on how many lines are cleared in the single move according to the following table:

Lines cleared Points
1 800
2 1200
3 1800
4 2000

Level

Each run, the player starts at level 1. After clearing 10 lines the player levels up.

Total Score

After clearing any number of lines in a move, the points awarded for them are calculated. Then the total score gets updated as:

$Score_{total} \mathrel{+}= points \ \times \ level$


First, head to server_submission.py file and fill the TEAM_ID with your team_id.
Similar to the local submission, to submit your algorithm to the API, fill server_solver function with your algorithm

def server_solver(logical_map, current_tetromino, next_tetromino, time_left, level, score, lines_cleared) -> list:
    return []

This will send a GET request to the API to start the game and begin the trial for the team.
NOTE: Unfortunately the API is currently down, therefore server submissions doesn't work.

About

Code for participating in the Tetris contest

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages