A Tetris Game for programming education

Overview

Tetris Game

プログラミング学習を目的とした、ブロックを操作してスコアを競うゲームです。
FAQはこちら。
tutorialはこちら。

実行環境準備

Mac環境

Finder→Application→Utility→Terminalから、ターミナルを起動して以下コマンドを実行する。

# install pyqt5 and NumPy
brew install python3
pip3 install pyqt5
pip3 install numpy
# install other packages
brew install git

doc/files/install_mac.mdに上記手順を記載

Ubuntu/JetsonNano環境

doc/files/install_ubuntu.mdに手順を記載

windows環境

WSL(Windows Subsystem for Linux)を使う場合の手順
Docker for Windowsを使う場合の手順

docker環境

docker/README.mdに手順を記載

実行方法

本リポジトリを取得

cd $HOME
git clone https://github.com/seigot/tetris_game

ゲーム開始用スクリプトを実行

cd tetris_game
bash start.sh

Screenshot

ファイル構成

ファイル一覧

  • game_manager/game_manager.py : ゲーム管理用プログラム
  • game_manager/board_manager.py : ボード管理用プログラム
  • block_controller.py : ブロック操作用プログラム(ブロックの操作は、このファイルを更新して下さい。)
  • start.sh : ゲーム開始用スクリプト

詳細

以下のような構成になっています。
ブロック操作用プログラムは、管理プログラムから定期的に呼び出されるので、ボード情報から次の動作を決定して下さい。

Screenshot

詳細

手動操作

実行時、以下のようにオプションを与えることで、手動操作が可能です。 操作方法は、PC操作準拠とゲーム機コントローラ準拠の2種類を選択できるようにしています。

手動操作 PC操作準拠 ゲーム機コントローラ準拠
実行コマンド bash start.sh -m y bash start.sh -m g
up key 回転 落下
left key 左に移動 左に移動
right key 右に移動 右に移動
m key 下に移動 下に移動
space key 落下 回転
P key Pause Pause

スコアアタック用サンプルコード

実行時、以下のようにオプションを与えることで、スコアアタック用サンプルコードの実行が可能です。
サンプルコードについてブロック操作用サンプルプログラムを参照下さい。

bash start.sh -s y

Play rules

制限時間内の獲得スコアを評価します。

Score

加点

項目 得点 備考
1ライン消し + 100点 -
2ライン消し + 300点 -
3ライン消し + 700点 -
4ライン消し + 1300点 -
落下ボーナス + 落下したブロック数を得点に加算 -

減点

項目 得点 備考
gameover - 500点 ブロック出現時にフィールドが埋まっていたらgameover

game level

実行時、オプションを与えることで、難易度(レベル)を指定できます。

level1 level2 level3
実行方法 bash start.sh bash start.sh -l2 bash start.sh -l3
制限時間 180秒 180秒 180秒
ブロックの順番 固定(1-7まで順番に繰り返し) ランダム ランダム
フィールドの初期ブロック なし なし あり
フレーム更新頻度 約1秒 約1秒 約1秒
備考 - - -

各レベルの参考スコア

コード作成のはじめかた

本リポジトリのfork

まず、Githubアカウントを取得して本リポジトリを自リポジトリにforkして下さい。

リポジトリのフォークの例

  1. GitHubアカウントを作成/ログインする。
  2. GitHub で、https://github.com/seigot/tetris_gameリポジトリに移動します
  3. ページの右上にある [Fork] をクリックします。
    参考:リポジトリをフォークする

その後、自リポジトリにforkしたtetris_gameをローカルマシンに取得して下さい。

"さん(yourname=自分のアカウント名に読みかえて下さい)のリポジトリを取得する場合 git clone https://github.com/seigot/tetris_game # このリポジトリを取得する場合 ">
cd ~
git clone https://github.com/
    
     /tetris_game   # "
     
      "さん(yourname=自分のアカウント名に読みかえて下さい)のリポジトリを取得する場合
git clone https://github.com/seigot/tetris_game       # このリポジトリを取得する場合

     
    

既にtetris_gameが存在しており、これを削除したい場合はrm -fを実行して下さい。

sudo rm -rf tetris_game

取得後はソースコード変更、変更リポジトリに反映する等してアップデートを進めて下さい。

実行

実行方法を参考に実行環境の構築をして下さい。
環境構築の完了後、ブロック操作用プログラムblock_controller.pyを更新していってください。

自リポジトリのバイナリを公式リリースする

提出時、自リポジトリのバイナリを公式リリースする場合は、Githubリリースの機能を使うと簡単なのでお勧めです。

自リポジトリのコードを提出(バイナリリリース)する場合の手順参考
リポジトリのリリースを管理する
7.オプションで、コンパイルされたプログラムなどのバイナリファイルをリリースに含めるには、ドラッグアンドドロップするかバイナリボックスで手動で選択します。

本リポジトリの最新バージョン取り込み

今後、本リポジトリもバージョンアップしていく予定です。
本リポジトリのバージョンアップを取り込む場合は、forkしたリポジトリにて以下を実行して下さい。

※追記 2021/5より、Github UI上から操作可能になったようです。
GitHub新機能「Fetch upstream」使ってみた! 1クリックで親リポジトリに追従(同期)

git checkout master                                        # ローカルのmainブランチに移動
git remote add upstream https://github.com/seigot/tetris_game  # fork元のリポジトリをupstream という名前でリモートリポジトリに登録(名前はなんでもいい。登録済みならスキップ)
git fetch upstream                                         # upstream から最新のコードをfetch
git merge upstream/master                                  # upstream/main を ローカルのmaster にmerge
git push                                                   # 変更を反映

参考:github で fork したリポジトリで本家に追従する

Pull Requestを送る(Optional)

本リポジトリへ修正リクエストを送ることが可能です。詳しくは参考をご参照下さい。

※追記 Pull Request練習用リポジトリを作成しました。
test_pull_request

参考:
GitHub-プルリクエストの作成方法
[実践] はじめてのPull Requestをやってみよう
【GitHub】Pull Requestの手順

FAQ

doc/files/FAQ.mdを参照下さい。

参考

https://github.com/LoveDaisy/tetris_game
https://github.com/seigot/tetris_game(2021.12時点まで使用) http://zetcode.com/gui/pyqt5/tetris/
テトリスの歴史を「ブロックが落ちるルール」の進化から学ぶ

今後の課題

次のブロックのランダム性

次のブロックのランダム性は、現在はrandom関数の出力に依存しています。
しかし、こちらの記事によると選択方式が色々ありそうです。
有識者の方からアドバイス頂けると助かります。

nextShapeIndex = np_randomShape.random.randint(1, 8)

対戦モード実装

準備中

AI実装

準備中

自動評価

準備中

LICENSE

MIT LICENSE

Finnaly

~ HAVE FUN ~

Follow the numbers - A simple game where the player should follow the numbers and connect the dots

follow_the_numbers This is a simple game where the player should follow the numb

Sammy Mishinev 3 Nov 22, 2022
I automated the lumberjack game on telegram, by recognising pixels and using pyautogui module

Lumberjack Automated: @gamebot According to the official documentation, @gamebot is a demo bot for the Telegram Gaming Platform.` It provides some sam

Yew Chong 1 Dec 07, 2021
The Original Snake Game. Maneuver a snake in its burrow and earn points while avoiding the snake itself and the walls of the snake burrow.

Maneuver a snake in its burrow and earn points while avoiding the snake itself and the walls of the snake burrow. The snake grows when it eats an apple by default which can be disabled in the setting

17 Nov 12, 2022
An single python server emulator of MMORPG game WindSlayer also known as WS1.

PySlayer An single python server emulator of MMORPG game WindSlayer also known as WS1. Requirements Python = 3.7 Old windslayer client (Korea Yahoo!

mirusu400 29 Dec 19, 2022
Minecraft - Online Players Overlay Generator

Minecraft - Online Players Overlay Generator Contents About Quick Start Download Pre-Built Binary Run from Source Configuration Command-Line Options F

4 Sep 12, 2022
Wordle Solver: A simple script which is also called Wordle solver

wordle-solver this code is a simple script which is also called Wordle solver. t

amirreza 1 Feb 15, 2022
Tic Tac Toe Game build with Python

Tic Tac Toe Game Description two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing th

Kemal Kochekov 2 Jan 21, 2022
A Python tic tac toe game

Tic Tac Toe A Python tic tac toe game To start the game, run python3 main.py First, you have to select the game level. Today, it has three levels In a

Phant 1 Jan 14, 2022
A Tetris Game for programming education

Tetris Game プログラミング学習を目的とした、ブロックを操作してスコアを競うゲームです。 FAQはこちら。 tutorialはこちら。 実行環境準備 Mac環境 Finder→Application→Utility→Terminalから、ターミナルを起動して以下コマンドを実行する。 # i

11 Dec 01, 2022
Un semplice Snake game , come negli anni 90!

Project-SnakeGame Un semplice Snake game , come negli anni 90! ITA VI porto un semplice giochino per i nostalgini degli anni 90 , ispirato al vecchio

Matt K Lawrence 1 Oct 17, 2021
Multiple hacks that breaks the game

Blooket-Hack All of the cheats are based on a game mode.

glizzz_y 484 Feb 25, 2022
The original Tetris tile-matching game as adopted by IBM PC.

🕹️ Tetris Game The original Tetris tile-matching game as adopted by IBM PC. Game developed purely on python using the Dear PyGui Framework. 📖 Instru

14 Nov 12, 2022
A popular children's game developed in Python.

Pedra Papel e Tesoura Um dos jogos mais populares da infância... 🪨 📜 ✂️ 💻 Situação do projeto: Projeto finalizado ✔️ 🛠 Tecnologias: Python Tkinter

Arthur V.B.S. 2 Dec 05, 2022
A game developed while learning python

Alien_Invasion a game developed while learning python you must have python-3 installed in your computer. and pygame module is also required for this.

Jani Shubham 0 Oct 10, 2022
使用python编写2048游戏及自动玩

使用python编写2048游戏及自动玩

tiger-wang 68 Dec 23, 2022
Game-of-life - A simple python program to simulate and visualise the Conway's Game of life

Conway's game of life A simple python program to simulate and visualise the Conw

Dhravya Shah 3 Feb 20, 2022
Find live blooket games easy with python.

Blooket-pin-finder Find live blooket games easy with python. info when you start you will see what looks like error DON'T STOP those are just the thre

Crazedpotato 1 Mar 07, 2022
Navicella cavallo, gioco 2D stile space shooter

Navicella Cavallo Il miglior gioco in circolazione Navicella cavallo è un gioco 2D basato sullo stile dei giochi space shooter Come installare Navicel

Matteo 6 Jul 03, 2022
An algorithm to reach a correlated equilibrium in multiplayer games.

Correlatedpy: a python library for distributed learning of correlated equilibrium in multiplayer strategic games. View Demo · Report Bug · Request Fea

Omar Boufous 2 Feb 01, 2022
Playing memory game is fun and the more harder it is the more challenging it is.

Playing memory game is fun and the more harder it is the more challenging it is. Playing thi sgame make us stress free and also happy. So, I have decided to make a memory Game which people can play w

Shreejan Dolai 3 Nov 11, 2022