Coder Social home page Coder Social logo

hatetris-ai's Introduction

HATETRIS - in Python

This is the Python emulator of qntm's HATETRIS game.

The Tetris and Genetic Algorithm Tetris solvers are based on hiyuzawa's tetris_ai.

Setup

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

Usage

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

configurations

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

What I implemented

  • hatetris.py
    • The HATETRIS AI tetrimino generator (enemy-ai)
      • including the global search method
  • 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.