This is the Python emulator of qntm's HATETRIS game.
The Tetris and Genetic Algorithm Tetris solvers are based on hiyuzawa's tetris_ai.
I have tested it with Python 3.9.6 on Windows 10 and macOS 12.6.1.
# Clone the repository
git clone
cd hatetris-python
# Install dependencies
pip install -r requirements.txt
Play mode: You can play the game with the arrow keys. Almost all the features of the original game are implemented. If you game over, you can see the score and the number of lines you cleared, and string of hexadecimal to replay.
python3 play.py
Replay mode: You can replay the game with the string of hexadecimal.
python3 replay.py
# Example 11 lines of replay data
Enter the code: ϥقໂɝƐඖДݹஶʈງƷ௨ೲໃܤѢقҾחࢲටฅڗ௨ΡІݪ௨ళȣݹࢴටງ໒௨ஶໃܥ௨റІݮ௨ఴІݥذඡଈݹƍق๓অஒॴแђञඖЅи௨sǶɔۑడПݷޠقԩݹࠉൿຟɓతණງஈশ੬෪অࠑථධٽଫ൝ଆࡨশ૫СܭߜయլݚɶऋഭܭرɤธӃస൯
Genetic Algorithm mode: You can see the result of the Genetic Algorithm. In each generation, the best model's selected and displaying the result of emulation including the score, lines, and the string of hexadecimal. If you want to stop the process, press Ctrl+C.
python3 main.py
You can change the configurations in config.py
.
The default configurations are:
elitism_pct = 0.2 # percentage of the best individuals to keep
mutation_prob = 0.2 # probability of mutation
weights_mutate_power = 0.5 # power of mutation for weights
and the population size settings is in main.py
:
pop_size = 50 # population size
hatetris.py
- The HATETRIS AI tetrimino generator (enemy-ai)
- including the global search method
- The HATETRIS AI tetrimino generator (enemy-ai)
replay_codecs
- A python package for encoding and decoding the replay data
- The encoding and decoding methods are based on the original JavaScript code
- For details, see replay_codecs/README.md