Git Product home page Git Product logo

rubiks_cube_ai's Introduction

Rubik's Cube AI

The goal of this project is to make a simple AI learn a Rubik's Cube from scratch, provided no prior knowledge of the puzzle. No algorithms specific to solving Rubik's Cubes are in place, so the AI learns solely through trial and error.

rubiks.py creates and scrambles a Rubik's Cube, and can output a flattened, coloured visual representation to the console. Any cube size may be created and fully manipulated.

ai_learner.py attempts to solve a Rubik's Cube strictly through Deep Q-Learning. The current reward system primarily focuses on the number of entirely-correct blocks.

There are two simple rules in place, to expedite the learning:

  • Don't counter the previous rotation
  • Don't make the same rotation 4 times consecutively

A PyTorch tutorial was roughly followed to implement the starting AI.

Dependencies

  • Numpy
  • PyTorch

Usage

Run with the following command:

python ai_learner.py [OPTIONS]

Options:

  • -s N | --size=N: Cube size (number of squares per edge). Default: 2
  • -l N | --layers=N: Number of layers in the neural network. Default: 3
  • --seed=N: Set the RNG seed
  • --random: Only use random choice
  • -h | --help: Display the help page and exit

Performance

Due to the complexity of the puzzle and the simplicity of the AI, it's unlikely to solve large cubes as of yet; regardless, the AI fares substantially better than if random choices were taken. Random choice gives a short-term average of 1 correct block for a 2x2x2 cube, and 7 for a 3x3x3 cube. The AI may sustain an average of 6+ and 14+ correct blocks respectively within an hour of learning. Correct corner pieces are easy to achieve, but great difficulty comes with then also correcting the edge pieces.

Below are the best solutions found between the AI and random choice, each allowed up to 600,000 rotations (5 minutes) on 5 different Rubik's Cubes.

AI Random Choice
3x3x3: 38 Correct 3x3x3: 23 Correct
2x2x2: 24 Correct 2x2x2: 15 Correct

Given a few hours of training, 2x2x2 cubes are usually solved within 10,000 rotations. See below for results late into the learning process.

AI: 2x2x2 Cube Solution Stats

rubiks_cube_ai's People

Contributors

shumaym avatar

Watchers

James Cloos 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.