{"id":16804323,"url":"https://github.com/yanyongyu/python-tetris","last_synced_at":"2025-03-22T02:31:22.385Z","repository":{"id":57456539,"uuid":"263919532","full_name":"yanyongyu/python-tetris","owner":"yanyongyu","description":"Tetris game with AI made by pygame, inspired by react-tetris","archived":false,"fork":false,"pushed_at":"2020-06-06T11:32:06.000Z","size":19479,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T07:11:41.238Z","etag":null,"topics":["pierre-dellacherie","pygame","tetris"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanyongyu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-14T13:14:57.000Z","updated_at":"2024-01-26T03:40:03.000Z","dependencies_parsed_at":"2022-09-13T14:42:47.543Z","dependency_job_id":null,"html_url":"https://github.com/yanyongyu/python-tetris","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanyongyu%2Fpython-tetris","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanyongyu%2Fpython-tetris/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanyongyu%2Fpython-tetris/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanyongyu%2Fpython-tetris/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanyongyu","download_url":"https://codeload.github.com/yanyongyu/python-tetris/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244898008,"owners_count":20528331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pierre-dellacherie","pygame","tetris"],"created_at":"2024-10-13T09:44:45.164Z","updated_at":"2025-03-22T02:31:20.648Z","avatar_url":"https://github.com/yanyongyu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n * @Author         : yanyongyu\n * @Date           : 2020-05-14 22:26:04\n * @LastEditors    : yanyongyu\n * @LastEditTime   : 2020-06-06 19:13:19\n * @Description    : None\n * @GitHub         : https://github.com/yanyongyu\n--\u003e\n\n# PyTetris\n\n![PyPI](https://img.shields.io/pypi/v/pytetris)\n![GitHub](https://img.shields.io/github/license/yanyongyu/python-tetris)\n![GitHub repo size](https://img.shields.io/github/repo-size/yanyongyu/python-tetris)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pytetris)\n\n## Table of Contents\n\n- [PyTetris](#pytetris)\n  - [Table of Contents](#table-of-contents)\n  - [Overview](#overview)\n  - [Screenshots](#screenshots)\n  - [Play the Game](#play-the-game)\n    - [Install](#install)\n    - [Start](#start)\n    - [How to Play](#how-to-play)\n  - [Pierre Dellacherie](#pierre-dellacherie)\n    - [Landing Height](#landing-height)\n    - [Eroded Piece Cells Metric](#eroded-piece-cells-metric)\n    - [Board Row Transitions](#board-row-transitions)\n    - [Board Column Transitions](#board-column-transitions)\n    - [Board Buried Holes](#board-buried-holes)\n    - [Board Wells](#board-wells)\n    - [Total](#total)\n    - [Priority](#priority)\n    - [Result Preview](#result-preview)\n  - [Project Development Setup](#project-development-setup)\n\n## Overview\n\nSimple tetris game made by pygame\n\nInspired by [react-tetris](https://github.com/chvin/react-tetris)\n\nAI algorithm: Pierre Dellacherie ([El-Tetris](https://imake.ninja/el-tetris-an-improvement-on-pierre-dellacheries-algorithm/))\n\n## Screenshots\n\n\u003cimg src=\"./static/overview1.png\" alt=\"Overview\" width=\"40%\"\u003e\n\u003cimg src=\"./static/overview2.png\" alt=\"Overview\" width=\"40%\"\u003e  \n\u003cimg src=\"./static/overview3.png\" alt=\"Overview\" width=\"40%\"\u003e\n\u003cimg src=\"./static/overview4.png\" alt=\"Overview\" width=\"40%\"\u003e\n\n## Play the Game\n\n### Install\n\n```shell\npip3 install pytetris\n```\n\n### Start\n\nRun the following command in the environment which you installed the pytetris package or under the project folder:\n\n```shell\npython -m pytetris\n```\n\nor you can run the project in the project folder by\n\n```shell\npoetry run game\n```\n\n### How to Play\n\nIn the home page, you can use `←→` or click the button to change to start level and use `↑↓` to change the start random line number.\n\n- `↑` : Rotate the piece\n- `←→` : Move the piece left or right\n- `↓` : Speed up the piece\n- `SPACE` : Drop down the piece\n- `P` : Pause the game\n- `S` : Mute control\n- `R` : Reset the game (will loss current score)\n- `A` : Make AI on or off\n\n## Pierre Dellacherie\n\nPierre Dellacherie is a one-piece algorithm.\n\nSix main features:\n\n### Landing Height\n\nThe height where the piece is put. Top or center of the piece is both ok.\n\nExample:\n\n:white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::blue_square::white_large_square::white_large_square::white_large_square::white_large_square:  \n:white_large_square::white_large_square::black_large_square::black_large_square::blue_square::blue_square::black_large_square::black_large_square::white_large_square::white_large_square:  \n:black_large_square::black_large_square::black_large_square::black_large_square::blue_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square:  \n:black_large_square::white_large_square::white_large_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square:\n\nHeight: `4` or `3`\n\n### Eroded Piece Cells Metric\n\nThe number of rows eliminated × The number of the squares the piece contributed\n\nExample:\n\n:white_large_square::white_large_square::white_large_square::white_large_square::white_large_square::blue_square::white_large_square::white_large_square::white_large_square::white_large_square:  \n:white_large_square::white_large_square::black_large_square::black_large_square::blue_square::blue_square::black_large_square::black_large_square::white_large_square::white_large_square:  \n:black_large_square::black_large_square::black_large_square::black_large_square::blue_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square:  \n:black_large_square::white_large_square::white_large_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square::black_large_square:\n\nEliminated lines: `1`\n\nContribute: `1`\n\nEroded Piece Cells Metric: `1 × 1 = 1`\n\n### Board Row Transitions\n\nThe 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.\n\n**Tips:** Both sides of the wall is concerned as filled.\n\nExample:\n\n:negative_squared_cross_mark::white_large_square::white_large_square::black_large_square::black_large_square::white_large_square::white_large_square::black_large_square::black_large_square::white_large_square::white_large_square::negative_squared_cross_mark:\n\nSingle Row Transitions: `6`\n\n### Board Column Transitions\n\nThe 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.\n\n**Tips:** Both sides of the wall is concerned as filled.\n\nExample:\n\n:negative_squared_cross_mark:  \n:white_large_square:  \n:black_large_square:  \n:black_large_square:  \n:white_large_square:  \n:black_large_square:  \n:negative_squared_cross_mark:\n\nSingle Column Transitions: `4`\n\n### Board Buried Holes\n\nThe total number of column holes. A hole is an empty cell that has at least one filled cell above it in the same column.\n\nExample:\n\n:white_large_square:  \n:black_large_square:  \n:black_large_square:  \n:white_large_square:  \n:black_large_square:\n\nSingle Column Holes: `1`\n\n### Board Wells\n\nThe total number of column wells. A well is a succession of empty cells such that their left cells and right cells are both filled.\n\n**Tips:** As long as there are filled cells on both sides, the empty cell is concerned as well.\n\nExample:\n\n:white_large_square::white_large_square::black_large_square:  \n:black_large_square::white_large_square::black_large_square:  \n:black_large_square::black_large_square::black_large_square:  \n:black_large_square::white_large_square::black_large_square:  \n:black_large_square::white_large_square::black_large_square:\n\nWells: `(1) + (1+2) = 4`\n\n### Total\n\nThe evaluation function is a linear sum of all the above features. Bigger value will be better.\n\n| Feature                   | Weight              |\n| ------------------------- | ------------------- |\n| Landing Height            | -4.500158825082766  |\n| Eroded Piece Cells Metric | 3.4181268101392694  |\n| Board Row Transitions     | -3.2178882868487753 |\n| Board Column Transitions  | -3.2178882868487753 |\n| Board Buried Holes        | -7.899265427351652  |\n| Board Wells               | -3.3855972247263626 |\n\n### Priority\n\npriority = 100 \\* moving_steps + rotation_times\n\nWe choose the action which priority is lower if there are two or more same evaluation actions.\n\n### Result Preview\n\n\u003cimg src=\"./static/ai.gif\" width=\"40%\"\u003e\n\u003cimg src=\"./static/ai.png\" width=\"40%\"\u003e\n\n## Project Development Setup\n\nClone the repository then install dependencies.\n\n```shell\npoetry install --no-root\n```\n\nor you can install the dependencies using pip:\n\n```shell\npip3 install pygame numpy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanyongyu%2Fpython-tetris","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanyongyu%2Fpython-tetris","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanyongyu%2Fpython-tetris/lists"}