Skip to main content

PyTetris

PyPI GitHub GitHub repo size PyPI - Downloads

Table of Contents

Overview

Simple tetris game made by pygame

Inspired by react-tetris

AI algorithm: Pierre Dellacherie (El-Tetris)

Screenshots

Overview Overview Overview Overview

Play the Game

Install

pip3 install pytetris

Start

Run the following command in the environment which you installed the pytetris package or under the project folder:

python -m pytetris

or you can run the project in the project folder by

poetry run game

How to Play

In the home page, you can use ←→ or click the button to change to start level and use ↑↓ to change the start random line number.

  • ↑ : Rotate the piece
  • ←→ : Move the piece left or right
  • ↓ : Speed up the piece
  • SPACE : Drop down the piece
  • P : Pause the game
  • S : Mute control
  • R : Reset the game (will loss current score)
  • A : Make AI on or off

Pierre Dellacherie

Pierre Dellacherie is a one-piece algorithm.

Six main features:

Landing Height

The height where the piece is put. Top or center of the piece is both ok.

Example:

⬜⬜⬜⬜⬜🟦⬜⬜⬜⬜
⬜⬜⬛⬛🟦🟦⬛⬛⬜⬜
⬛⬛⬛⬛🟦⬛⬛⬛⬛⬛
⬛⬜⬜⬛⬛⬛⬛⬛⬛⬛

Height: 4 or 3

Eroded Piece Cells Metric

The number of rows eliminated × The number of the squares the piece contributed

Example:

⬜⬜⬜⬜⬜🟦⬜⬜⬜⬜
⬜⬜⬛⬛🟦🟦⬛⬛⬜⬜
⬛⬛⬛⬛🟦⬛⬛⬛⬛⬛
⬛⬜⬜⬛⬛⬛⬛⬛⬛⬛

Eliminated lines: 1

Contribute: 1

Eroded Piece Cells Metric: 1 × 1 = 1

Board Row Transitions

The total number of row transitions. A row transition occurs when an empty cell is adjacent to a filled cell on the same row and vice versa.

Tips: Both sides of the wall is concerned as filled.

Example:

❎⬜⬜⬛⬛⬜⬜⬛⬛⬜⬜❎

Single Row Transitions: 6

Board Column Transitions

The total number of column transitions. A column transition occurs when an empty cell is adjacent to a filled cell on the same column and vice versa.

Tips: Both sides of the wall is concerned as filled.

Example:

❎
⬜
⬛
⬛
⬜
⬛
❎

Single Column Transitions: 4

Board Buried Holes

The total number of column holes. A hole is an empty cell that has at least one filled cell above it in the same column.

Example:

⬜
⬛
⬛
⬜
⬛

Single Column Holes: 1

Board Wells

The total number of column wells. A well is a succession of empty cells such that their left cells and right cells are both filled.

Tips: As long as there are filled cells on both sides, the empty cell is concerned as well.

Example:

⬜⬜⬛
⬛⬜⬛
⬛⬛⬛
⬛⬜⬛
⬛⬜⬛

Wells: (1) + (1+2) = 4

Total

The evaluation function is a linear sum of all the above features. Bigger value will be better.

Feature Weight
Landing Height -4.500158825082766
Eroded Piece Cells Metric 3.4181268101392694
Board Row Transitions -3.2178882868487753
Board Column Transitions -3.2178882868487753
Board Buried Holes -7.899265427351652
Board Wells -3.3855972247263626

Priority

priority = 100 * moving_steps + rotation_times

We choose the action which priority is lower if there are two or more same evaluation actions.

Result Preview

Project Development Setup

Clone the repository then install dependencies.

poetry install --no-root

or you can install the dependencies using pip:

pip3 install pygame numpy

Metadata

Release files for pytetris 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytetris 1.0.0
File Size Uploaded
pytetris-1.0.0.tar.gz 8.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytetris 1.0.0
File Interpreter ABI Platform
pytetris-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 MB

Release files / pytetris-1.0.0.tar.gz

Download URL pytetris-1.0.0.tar.gz
Size 8.7 MB
Tags Source
SHA-256 checksum
How to use checksums
1da3d6e28975466dca319b246e20ca7914c3058b69aa4a142d48bb950e3d2422
BLAKE2b-256 checksum
How to use checksums
b3c7fa72c1d4a1899fe4e7ac2b41a31d7d3436f4073fdee01fd8459fdab3d063
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.8.3 Linux/5.3.0-53-generic

Release files / pytetris-1.0.0-py3-none-any.whl

Download URL pytetris-1.0.0-py3-none-any.whl
Size 8.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
23ed3ac06e32a64ee6ad5c4963ff05452f3f99a5f8a7b2ea1aeb344a1f16849f
BLAKE2b-256 checksum
How to use checksums
74392a83c19e2d47421c76172a7ae47d395ced890e25a8d6625fc07f431a79bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.8.3 Linux/5.3.0-53-generic

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page