
Purpose of this post
This post publishes the source code used for the Tetris AI. The code is loaded only when you open a file.
Models used
- stable-baselines3 DQN: the low-level 7-action models (300,000 and 370,000 steps) and the macro 40-action model (300,000 steps). The model files are not included.
- Qwen2.5-3B-Instruct GGUF q4_k_m (llama-cpp-python): text board judge, picking a candidate number
- Qwen2.5-VL-3B-Instruct (transformers): image board judge, picking spots directly
Folder layout
- tetris: C++ engine (tetris_engine), C API (tetris_c_api), Qt6 screen and TCP server (main_window, tetris_widget), CMake
- local_tetris_env.py: gymnasium environment wrapping the engine with ctypes
- simple_tetris_env.py: a pure Python environment used when the engine is not built. Its observation and action formats differ, so models cannot be swapped between them.
- macro_planning_env.py: the 40-action environment that chooses once per piece
- train_tetris_rl.py: DQN training without a screen
- train_qt_live.py: shows the current model on the Qt screen while training. It also has a mode that trains on games played by a person.
- qt_rl_client.py: attaches a trained model to the Qt screen
- llm_teacher.py, vlm_teacher.py, llm_reward_wrapper.py: LLM and VLM reward judges
- vlm_macro_client.py: client where the VLM picks spots directly
- llm_macro_client.py: candidate computation and LLM number picking
- moe_macro_policy.py: candidate selection mixing four rules
- config/rl_config.py: training settings
Build outputs, virtual environments, model weights and trained model files are excluded.
Full source
25 files · 4,969 lines — open a folder and click a file to load its code.
Project root
llm_macro_client.py
Loading code…
llm_reward_wrapper.py
Loading code…
llm_teacher.py
Loading code…
local_tetris_env.py
Loading code…
macro_planning_env.py
Loading code…
moe_macro_policy.py
Loading code…
project.md
Loading code…
qt_rl_client.py
Loading code…
requirements.txt
Loading code…
simple_tetris_env.py
Loading code…
train_qt_live.py
Loading code…
train_tetris_rl.py
Loading code…
vlm_macro_client.py
Loading code…
vlm_teacher.py
Loading code…
config/
config/__init__.py
Loading code…
config/rl_config.py
Loading code…
tetris/
tetris/CMakeLists.txt
Loading code…
tetris/src/main_window.cpp
Loading code…
tetris/src/main_window.h
Loading code…
tetris/src/main.cpp
Loading code…
tetris/src/tetris_c_api.cpp
Loading code…
tetris/src/tetris_engine.cpp
Loading code…
tetris/src/tetris_engine.h
Loading code…
tetris/src/tetris_widget.cpp
Loading code…
tetris/src/tetris_widget.h
Loading code…
COMMENTS · CHAPTER 06
The full source code and the models used 0 comments
No comments yet. Leave a question or anything you would like to add.
To post a comment, continue with Google and register a nickname and email address.
Continue with Google