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 ~

A Python based program that displays Your Minecraft Server's Status Infos.

Minecraft-server-Status This (very) small python script allows you to view any Minecraft server's status Information Usage Download the file, install

Jonas_Jones 2 Oct 05, 2022
A tool to design a planet for Galaxy Life Reborn game.

GLRBaseDesigner A program to design your planet for Galaxy Life Reborn game. Description Do you want to share your base design with friends? Now it's

jjay31 9 Dec 16, 2022
Orbital-patterns - A program which plots pattern that revolving planets make

orbital-patterns Click to spawn planets Press "S" to capture screenshot. Image w

Yuvraj.M 11 Dec 24, 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
Repository for the DecodED2 Game Project!

DecodED2 Game Project Hello everyone! Welcome to the GitHub Repository for DecodED2, as a start you'll need to clone this repository and make sure you

6 Sep 29, 2021
Automatic game data translator for RPGMaker-MV

RPGMaker-MV Translator 🕹️ 🎮 Use AI to translate all the dialogs and texts of your RPGMaker automatically. 👊 You worked hard to make your game, now

Davide Liu 11 Dec 26, 2022
A Frogger game in Python with pygame

CrockiCrocki A personal project of a simple "game" in Python to learn Pygame and Python. Requires: pygame: In Linux: pip3 install pygame In MacOS: pip

Jorge Abreu 1 Nov 07, 2021
Repository with console python implementation of Simple Artificial Life (simplified MAS) and Conway's game of life

artificial-life-game Repository with console python implementation of Simple Artificial Life (simplified MAS) and Conway's game of life Installation c

Vladislav 6 Nov 14, 2022
Just a copied of flappy bird game made by Thuongton999

flappy-bird Just a copied of flappy bird game made by Thuongton999 Installation and Usage Using terminal (on Window) Make sure you installed Python an

ThuongTon 9 Aug 08, 2021
This is a simple game of rock-paper-scissors developed in Python

This is a simple game of rock-paper-scissors developed in Python. It allows two players to play with one another on different command lines through networking.

NAMAN JAIN 3 Oct 21, 2022
A first-person shooting game developed by using OpenGL

OpenGL-MazeSurvivor-FirstPerson Shooting Game This application named ‘MAZE SURVIVOR’ is a first-person shooting game that finished within a month. It

JunHong 2 Jan 04, 2023
A sprite ripper and converter for Com2uS' 2007 game Music World.

Music World Sprite Dumper This repository contains a python script reads an UNCOMPRESSED Music World pxo file and attempts to dump sprites from it. Th

Buu342 1 Mar 16, 2022
Code and outputs from analysis determining that the wordle game can always be won in six moves.

wordle_worst_case_analysis Code and outputs from analysis determining that the wordle game can always be won in six moves. This is for the general cas

2 Aug 19, 2022
Guess Your Card - A Multiplayer Python Game

Guess Your Card - A Multiplayer Python Game This is a guessing card game having two levels - Developed in Python and can be played between two to four

Hammad Ahmed ~ 1 Oct 20, 2021
Turtle Road Crossing Game in Turtle(python module)

Turtle Road Crossing Game in Turtle(python module) In this project we have built a road crossin game in python with Object-Oriebted Programming. This

Jhenil Parihar 3 Jun 15, 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
A simple python script to pregenerate minecraft worlds.

mcloady mcloady is a lightweight python script used to pre-generate Minecraft terrain using MCRcon and carpet mod (optional). Inspired by Pre-Generati

5 Dec 08, 2021
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
Ladder network is a deep learning algorithm that combines supervised and unsupervised learning

This repository contains source code for the experiments in a paper titled Semi-Supervised Learning with Ladder Networks by A Rasmus, H Valpola, M Hon

Curious AI 505 Nov 15, 2022
A coven of tools to assist in PnP RPGs.

pupillae A coven of tools to assist PnP RPGs. Status: Pre-alpha. Testing. Adding necessary functions and features as discovered/required. Other-than-P

0 Dec 09, 2021