Giter Site home page Giter Site logo

ashleve / evolution Goto Github PK

View Code? Open in Web Editor NEW
49.0 6.0 8.0 57.38 MB

A simple simulation in Unity, which uses genetic algorithm to optimize forces applied to cubes

License: MIT License

ShaderLab 10.20% C# 89.80%
unity ai genetic-algorithm evolutionary-algorithms pathfinding c-sharp fitness-score mutation natural-selection

evolution's Introduction

EvOLuTIoN

A simple simulation in Unity, which uses genetic algorithm to optimize forces applied to cubes.

Download

Unity game build:
https://github.com/hobogalaxy/EvOLuTIoN/releases/download/v1.0/GenAlgBuild.zip

How Does It Work

Each cube spawns with an instance of Player.cs script that contains his array of 3D vectors. Those vectors are applied to player as forces over time.

The genetic algorithm optimises those vectors.

What it means is players don't learn how to navigate in the environment, they only memorise the vectors that enable them to get closer to the goal.

You can find the algorithm scripts in Assets>>Scripts>>AlgorithmScripts

Population.cs contains the Genetic Algorithm applied by NaturalSelection() function.

    void NaturalSelection()
    {
        SetChampion();  //finds the best player from generation

        CalculateFitness();
        CalculateFitnessSum();  //needed for selecting parents

        CopyBrain(Players[0], champion);   //best player is always reborn in next generation 
                                           //unchanged as player0

        for (int i = 1; i < playerNum; i++)
        {
            GameObject parent = SelectParent();
            CopyBrain(Players[i], parent);
            Mutate(Players[i]);
        }
        
    }

Each player has only one parent, no crossover is used.

Other mechanics:

  • The green cube is the best player from previous generation, which is always reborn without any mutations
  • Incremental learning is applied, which means each player has a certain lifespan which is increased each 5 generations. This is to give them time to master their first moves before moving on to the next ones.
  • When the first player reaches the goal, the minStep variable is assigned which is the minimum of steps he needed to take to reach the goal. From now on, if any player takes more steps then minStep, he will die. This makes them optimise their way so they get to the goal faster each generation.
  • The jumping is enabled just by giving players the abilty to have vectors mutated on Y axis (they're mutated only on X and Z by default).

evolution's People

Contributors

ashleve avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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