Giter Club home page Giter Club logo

tetris's Introduction

Build codecov

Basic Tetris project

A basic Tetris game simulator where pieces never rotate and are just dropped onto a grid. The grid provides methods to add pieces and exposes its current height expressed as number of non-empty rows.

The game accepts sequences of Tetris pieces, one sequence per line, and will return the grid height once all the pieces have been added to the grid. Pieces and positions can be specified in the following format:

Q2,T3,S6

where each letter identifies a Tetris piece with a specific shape:

  • Q is the square
  • I is the straight piece, laid out horizontally
  • T, Z, S, J, L have the same shape as their letter

and the number represents the leftmost column occupied by this piece when dropped into the grid.

For example, the sequence above will result in a grid of height 3 and the following layout:

|          |
|   TTT    |
|  QQT  SS |
|  QQ  SS  |
------------

while the following sequence:

I0,I0,Q4,I6,I6

will result in an empty grid as two full lines will be eliminated.

Running

The program requires python 3 (it was tested with version 3.8.5). After checking out the project, run it like this:

$ python src/tetris/cmd.py

and it accepts alternatively:

  • a single file name argument:
$ echo "Q1,Q3" > in.txt
$ python src/tetris/cmd.py in.txt
2
  • sequences of pieces as arguments:
$ python src/tetris/cmd.py "Q0,Q2,Z0,I2,I6" "I3,Z2,S5"
4
3
  • piped input
$ echo "Q1,Q3,Z0,Z2,T1" | python src/tetris/cmd.py
6

Running tests

In order to run tests you will need poetry - it's also a good idea to make sure your pip is up to date:

python -m pip install --upgrade pip
pip install poetry

with poetry installed you can then run the tests locally:

poetry run pytest

tetris's People

Contributors

ilcatania avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.