1

background

This series of articles uses Python3 to record the entire process of writing Tetris games step by step. The game functions include manual games, game playback (database operations), automatic games (AI robots), reinforcement learning, and optimized AI robots. The C++ version has been completed, QGraphicsItem of Qt5 writes Tetris Tetris game .

planning

Design ideas

The game does not use third-party libraries as much as possible, and mainly focuses on algorithms, so the interface library chooses tkinter built in python. The design concept also adopts the traditional way, using a two-dimensional array to control the game space, similar to the way of a maze. One advantage of choosing this method is that the game data is intuitive and easy to obtain.

Effect picture

Game space size

10 x 20

Scoring design:
  • One level is scored
  • 3 points for the second floor
  • Eliminate three levels to get seven points
  • Eliminate four levels to get ten points
Control keys
  • Up arrow key: Rotate
  • Left arrow key: Move left
  • Right direction: move right
  • Down arrow key: Move down
  • Space key: move down to the end

project progress

The manual game, game playback, simple AI, manual and automatic switching at any time have been completed.

Item label (mileage tag)

  • v1.0.1(manual-play)-Milestone version of manual game function
  • v1.1(auto-play)-Milestone version of automatic game function, memory leak found
  • v1.2(less-block)-Solve memory leaks

project address

https://gitee.com/zhoutk/ptetris
或
https://github.com/zhoutk/ptetris

Operation method

1. install python3, git
2. git clone https://gitee.com/zhoutk/ptetris (or download and unzip source code)
3. cd ptetris
4. python3 tetris

This project surpport windows, linux, macOs

on linux, you must install tkinter first, use this command:  
sudo apt install python3-tk

Related items

C++ version has been implemented, project address:

https://gitee.com/zhoutk/qtetris

zhoutk
2.6k 声望1.2k 粉丝

自由程序员,技术路线c,delphi,c++,c#,java,php,node.js,python,golang,typescript;超喜欢react.js的设计思路,全栈开发成为我的终极目标。开发机器macbook pro,或装ubuntu、fedora的机器,编程用vim...