GithubHelp home page GithubHelp logo

tetris-ai's Introduction

Tetris AI

A self-playing Tetris.

Usage

To play the the game interactively:

python tetris.py

To play the game automatically:

python tetris_ai.py

When playing the game interactively, use the arrow keys to control the tetromino's moving directions (<left>, <right>, <down>) and rotation (<up>), <space> to drop the tetromino straight down, <p> to pause or resume, and <q> to quit the game.

Implementations

The main idea is simply iterate through all the possible rotations and horizontal positions of a given tetromino, evaluate each result using a heuristic function and choose the one with the highest heuristic score. The heuristic function is based on Pierre Dellacherie’s Algorithm, read more details here.

We use depth first search in the implementaion, since there are at most two tetrominoes to consider when seaching for the optimal placement, whether to consider the next tetromino or not is a matter of choice and should be easily configured. To configure the depth of the DFS search, set LOOK_AHEAD to 1 or 2 in ai_config.py, if LOOK_AHEAD is set to 1, the algorithm would just consider the current tetromino, otherwise, it would take both one into account.

Copyright © 2016 Daogan Ao <[email protected]>

tetris-ai's People

Contributors

daogan avatar

Watchers

 avatar Hagin Onyango avatar

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.