evolution-ai

Develop entity by evolution algorithm


Keywords
AI, evolution, machine, learning, biological, selection, algorithm, entity, natural, life, method, search
License
MIT
Install
npm install evolution-ai@1.5.0

Documentation

logo

EvolutionAI

versionversion

Develops entity's genome by "natural" selection. It works extremly fast and effective.

Install

NPM:

$ npm install evolution-ai

Documetation

|Object|Description| |--------|-----------| |Kill()|Kills entity by ID| |Mutate()|Gives entity new childs to next generation and randomly mutate their genome, can choose intensity of mutation and extendion of genome| |Pair()|Gives childs to new generation with genomes of combination parents's genome, can choose count of childs and preference of one of the parents| |PairandMutate()|Combination of Pair() and Mutate()| |isAlive()|Sends true, if entity is alive (checks if entity has any genome code)| |PushNextSurvivors()|Moves live entities to next generation| |Entities|Array of entities in actual generation| |NewGen|Array of entities in next generation| |NextGen()|Switch next generation to actual generation|

Example

const evolution = require("evolution-ai")

const world = new evolution.Simulation() //Start simulation
for (let i = 0; i < 100; i++) { // Loop for every generation

    for (let i = 0; i < world.Entities.length; i++) { //Loop for every entity 
        const Genome = world.Entities[i].split(""); //split for better reading of genome
        
        let have = false
        for (let idat = 0; idat < Genome.length; idat++) { //loop for every piece of genome
            const element = Genome[idat];
            
            // ! -- There belongs a "Natural" selection code -- !

            //----EXAMPLE----
            if(element === "A") {
                world.Kill(i) // This function will kill entity, if its has "A" in genome
                have = true
                break; // breaks genome scanning
            }
            //--END-EXAMPLE--
        }
        if(have === false) {
            world.Mutate(i, 3) // If hasnt it will multiply itself three times with little mutations
        }

    }

    console.log(world.Entities.length) //Writes number of nextgen entities to console
    world.NextGen() // Changes next generation to actual generation
}