Code Monkey home page Code Monkey logo

genetic's Introduction

Genetic

Welcome to Genetic, an app running tournament-based genetic algorithms. This console app is mainly based on the component symfony/console. It is tested with PHPUnit.

Purpose

Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection. This app can simulate the Darwin's theory and find the best creature in a randomly-generated population using iteration process :

  • tournament (competition-based, multiple fights)
  • selection
  • crossover
  • and mutation

This app is particular as it could use gene with different costs and uses an innovative fitness algorithm.

Examples

Configuring a genetic algorithms could be somewhat tedious so I leave 3 samples in this app. Feel free to erase them as you wish. To make a real life challenge I simulate 3 roleplaying game rules and select the best character for fight. Of course, not all rules are implemented (and need too many genes)

L5r namespace

It simulate the Legend of the Five Rings. In a character, the are gene to simulate traits and skills of course but also void spending stategy and stances.

SaWo namespace

Savage Worlds Deluxe Edition rules. It simulate melee fights between characters with Edge such as Trademark weapon and Block. It does not implement Initiative card.

Vda namespace

Vampire Dark Age 20th anniversary. Melee fights with Potence, Celerity and Fortitude. Blood Pool is not simulated.

How I add my game ?

You have 3 main tasks :

  • create a new Command by subclassing GameFree (a Template Method pattern)
  • create a new Character by subclassing MutableFighter. Genes are created by implementing Property interface or subclassing CappedProperty abstract class
  • create a new evolution "world" by subclassing DarwinWorld (mainly initiative rules). It contains all game master decision process.

Printing solutions

This app uses 4 different loggers : TextLogger for printing creature, GrafxLogger for viewing the population graphically (requirement: GD2), StatLogger to estimate if the evolution process is convergent or not and finally, FileLogger to store population genomes in files. An AggregateLogger is added to aggregate multiple loggers.

Results

Here's an example with L5r. Running 200 iterations with 1000 characters.

Command

php app.php l5r:free --extinct=1 --round=3 --plot=l5r --animate --stat --dump 1000 200
  • This command means 1% is extinct and replace each iteration.
  • 3 rounds are run to estimate which is the best fighter between two.
  • --plot is the prefix name for image plotting.
  • --animate option generates multiple PNG images (manually compiled with ffmpeg)
  • --stat option prints statistics and creates a CSV file
  • 1000 creatures
  • 200 iterations

Evolution of cost and victory

Horizontal axis is the genome cost and vertical axis is the victory count for each creatures : Evolution of population

The evolution of average cost for the best creatures (10% of all victories) : Convergent cost

Best fit

Final iteration :

0 - agility:4 kenjutsu:5 void:2 reflexe:5 earth:2 voidStrat:soak stance:full strength:2 win:445 cost:90
1 - agility:4 kenjutsu:3 void:2 reflexe:5 earth:2 voidStrat:soak stance:full strength:2 win:443 cost:81
2 - agility:4 kenjutsu:4 void:2 reflexe:5 earth:2 voidStrat:armor stance:standard strength:2 win:434 cost:85
3 - agility:5 kenjutsu:3 void:2 reflexe:5 earth:2 voidStrat:soak stance:standard strength:2 win:433 cost:101
4 - agility:4 kenjutsu:3 void:2 reflexe:5 earth:2 voidStrat:soak stance:standard strength:2 win:432 cost:81
5 - agility:4 kenjutsu:4 void:2 reflexe:5 earth:2 voidStrat:armor stance:standard strength:2 win:430 cost:85

genetic's People

Contributors

trismegiste avatar

Stargazers

 avatar

Watchers

 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.