Coder Social home page Coder Social logo

2048-dnn-solver's Introduction

2048-solver

An 2048 solver using TensorFlow and its abstraction library TFLearn. The 2048 game is implemented (and I believe it works fine), but the neural network is currently not working.

How to run

Note that TensorFlow, TFLearn, and NumPy are all required dependencies.

To generate training data, run python generate_training_data.py.

To train the neural net on the generated training data, run python train_nn.py

Once the neural net is trained, you can check the accuracy by running python test_nn.py.

If you want to see how well the neural net does compared to a random player, try python random_test.py.

With the neural net testing, for some reason it will hit a max accuracy of about .55 with a loss around 1. When testing is done, the score is about 160 over 1000 runs. For reference, a random player will get on average 180.

How it works/how it's supposed to work:

generate_training_data.py produces a numpy array called saved_training.npy containing random games, that had a threshold of at least score_requirement. Each entry in the numpy array looks like:

    [[0, 2, 4, 8, 2, 8, 4, 8, 16, 32, 2, 4, 8, 16, 32, 64], [0, 1, 0, 0]]

Where the first element is the flattened (raveled) array of the 2048 game, and the second element is a one-hotted array of the move made at that position, with the positions meaning [up, down, left, right].

train_nn.py opens saved_training.npy and trains the neural net using the following formula with the model provided in nn_model.py, and saves the model in models/trained_nn.model.

test_nn.py opens the model located at models/trained_nn.model and runs 1000 (or whatever num_tests is) games and calculates the average accuracy and the amount that each button was pressed

2048-dnn-solver's People

Contributors

kevin-fang avatar

Watchers

 avatar  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.