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 ~

Multi minecraft server helper for python

呐 Yuki 您的群组服操作小助手。 使用Python3编写。使用 .yaml 配置文件记录子服,配合Screen管理Linux系统上的Minecraft子服,支持MCDR子服与非MCDR子服。 功能: 开启所有子服 关闭所有子服 重载所有子服MCDR 重载所有子服ChatBridge 使用方法:

3 Mar 17, 2022
Text-Adventure-Game [Open Source] A group project by the Python TASK Force

Text-Adventure-Game [Open Source] A group project by the Python TASK Force

Mircea Dumitrescu 2 Sep 17, 2021
Visualizing and learning from games on chess.com

Better Your Chess What for? This project aims to help you learn from all the chess games you've played online, starting with a simple way to download

Luc d'Hauthuille 0 Apr 17, 2022
This is a python implementation of wordle, which uses the same set of available words as the hit game, Wordle

Wordle Game This is a python implementation of wordle, which uses the same set of available words as the hit game, Wordle. Play the game manually pyth

Pierre Theo Klein 11 Mar 04, 2022
Use different orders of N-gram model to play Hangman game.

Hangman game The Hangman game is a game whereby one person thinks of a word, which is kept secret from another person, who tries to guess the word one

ZavierYang 4 Oct 11, 2022
Tool for Path of Exile game to automatically scan Archemesis inventory and display related information

poe-archnemesis-scanner Tool for Path of Exile game to automatically scan Archemesis inventory and display related information Features Controls When

70 Nov 10, 2022
Hagia is a 2D game engine and toolset for Python.

HAGIA What is Hagia? Hagia is a 2D game engine and toolset for Python. Hagia has

star 3 Jun 01, 2022
Exposè for i3 WM. Fork of https://gitlab.com/d.reis/i3expo to fix crashes and improve features/usability

Overwiew Expo is an simple and straightforward way to get a visual impression of all your current virtual desktops that many compositing window manage

137 Nov 03, 2022
Multiplayer 2D shooter made with Pygame

PyTanks This project started as a one day project with two goals: Create a simulated environment with as much logic as possible written in Numpy, to o

Felix Chippendale 1 Nov 07, 2021
Made with pygame. Multiplayer game using socket module and threading.

Rock Paper Scissor made with python-pygame. Poorly made, as a beginner in programming. Multiplayer with server code and client code provided.

AllenJo 1 Dec 29, 2021
A python script to solve Wordle puzzles

Wordle solver A python script to solve Wordle puzzles.

Felix Weinberger 1 Feb 12, 2022
Continuous form of the game Wits & Wagers

wager Continuous form of the game Wits & Wagers Requires: Pygame, Pygame_gui

1 Nov 22, 2021
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
A solution program of 24. game.

A solution program of 24. game.

1 Dec 12, 2022
Ghdl-interactive-sim - Interactive GHDL simulation of a VHDL adder using Python, Cocotb, and pygame

GHDL Interactive Simulation This is an interactive test bench for a simple VHDL adder. It uses GHDL to elaborate/run the simulation. It is coded in Py

Chuck Benedict 2 Aug 11, 2022
Tic tac toe game developed by naman in python

TIC TAC TOE GAME DEVELOPED BY NAMAN IN PYTHON . IT USES MINMAX ALGORITHM TO COMPETE IN DIFFICULTY MODE

Naman Anand 4 Jun 24, 2022
A puzzle game coded entirely in Python.

Pyzzle A puzzle game coded entirely in Python. This is a school project created by me, Mohit Singh. The .exe file, created from the main.py script, is

Mohit Singh 1 Mar 19, 2022
A python game engine.

PursuedPyBear, also known as ppb, exists to be an educational resource. Most obviously used to teach computer science, it can be a useful tool for any topic that a simulation can be helpful.

PPB 235 Jan 08, 2023
Open source Brawl Stars server emulator for version 29 of the game!

Welcome to Classic-Brawl v29 Remake 👋 Open source Brawl Stars server emulator for version 29 of the game! (Remake) What's working ? Battles Trophies

CrossFire 4 Jan 19, 2022
Quantum version of the game Tic Tac Toe.

QTicTacToe Quantum version of the game Tic Tac Toe. This game was inspired by the game at this site. Installation The game requires the qiskit python

1 Jan 05, 2022