Giter Site home page Giter Site logo

evofighters's Introduction

   __             ___
  /              /    /      /    /
 (___       ___ (___    ___ (___ (___  ___  ___  ___
 |     \  )|   )|    | |   )|   )|    |___)|   )|___
 |__    \/ |__/ |    | |__/ |  / |__  |__  |     __/
                       __/  1.0
Josh Kuhn <[email protected]>
Evolving fighting bots

USAGE:
    evofighters [OPTIONS] [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -f, --file <SAVEFILE>    Name of save file [default: evofighters.evo]

SUBCOMMANDS:
    cycle-check    Does a cycle detection on the given bases
    help           Prints this message or the help of the given subcommand(s)
    simulate       Main command. Runs an evofighters simulation

What is this?

This is a simulation I've written on and off over several years. It's fundamentally about little bots with a very simple fighting system. They attack, defend, pick up items, and occasionally try to mate with each other.

When they mate, they combine their dna similar to how sexually reproducing organisms in real life do, randomly selecting genes from each of the two parents. There's a chance of different kinds of mutations like gene swaps, transcription errors and the like.

Once you have replication, a competitive environment, and mutations, you get evolution. It's not super sensitive to starting conditions, it just works and is kind of fun.

How it works

There are some rough phases the simulation occurs in for each creature:

  1. Creating a new creature, which randomly chooses between each pair of genes from the parents. It also has a chance of random mutation.
  2. Compiling/Parsing, which iterates through the bases of the creature's dna, and builds an ast with the creature's program for how to behave in an encounter. The parsing process is very forgiving: if the next base isn't a valid value for the next term, we just skip it and go on to the next base. If we reach the end of the dna, we wrap around to the beginning. If parsing takes too many steps we abort.
  3. Evaluation, when the creature is in an actual encounter with another creature. The parsed ast is evaluated in the context of the fight (some variables depend on the opponent, some are random, so can't be done ahead of time). The outcome of this is a decision for which action the creature should take.
  4. The creature takes an action. The 3 most interesting actions are attacking, defending and mating. Mating requires some reciprocity and some spare energy (otherwise you could create something from nothing and mating constantly would be the best strategy to pass on genes). Fighting allows you to gain energy if you win, but if the opponent is smart and defends correctly against you, you will expend resources fighting and not get anything in return.

There is an initial population of creatures, with a bootstrapped DNA that parses out to "Turn 1: Try to mate. Turn 2: Flee". This is a reasonable starting point since it ensures mating gets off the ground (can't evolve if you don't reproduce), but it also ensures short fights since they flee right afterward (and don't waste all of their energy trying to mate over and over again).

For each encounter, two random creatures are selected from the population, and pitted against each other. The fight is given a randomized maximum number of rounds to last. Then the creatures go at it, fighting or mating as their dna instructs them.

History

I initially wrote a version of this in python. Being a simulation though, it needed to run fast, so I made it work in pypy. I left the project alone for a while.

When I came back about 3 years later, I rewrote the main portion of it in pre-1.0 rust. It used several experimental extensions which were never standardized. But I made some advances over the initial python version. Mostly in speed, but also I wrote a clever compiler that allowed precompiling and simplifying a creatures genes. Previously, every time a fight was run, some evaluation/parsing occurred. Then I left the project alone for a while.

When I came back about 3 years later, I fixed almost all of the pre-1.0 problems and got it almost working in standard rust. The only issue was that standard rust still didn't have box pattern syntax, which was really useful for digging through deep recursive data structures. So, we're on nightly rust, and only using two language extensions (box_syntax and nll which is actually expected to be standardized).

Contributing

This is mostly a fun project for me. I don't actually think it's useful for anyone else, nor is it very interesting to watch. The fun of it is developing it and seeing what kinds of strategies the creatures come up with after millions of generations.

So, since the goal isn't actually to create useful software, but to enjoy the process, I don't really forsee a need to accept contributions. That being said, if you want to fork this, be my guest, and if you feel like contributing, feel free to open up an issue and we can talk!

evofighters's People

Contributors

deontologician avatar

Watchers

 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.