示例#1
0
 public void AddNodeGene(NodeGene toAdd)
 {
     if (!NodeGenes.ContainsKey(toAdd.Id))
     {
         NodeGenes.Add(toAdd.Id, toAdd);
     }
 }
示例#2
0
        public void Init(int inputNodesCount, int outputNodesCount)
        {
            var initSpecie = new Specie();

            var progenitorGenome = new Genome();

            for (int j = 0; j < inputNodesCount; j++)
            {
                var inputNode = new NodeGene(NodeGeneType.Input);
                progenitorGenome.AddNodeGene(inputNode, inputNode.Id);
            }
            for (int j = 0; j < outputNodesCount; j++)
            {
                var outputNode = new NodeGene(NodeGeneType.Output);
                progenitorGenome.AddNodeGene(outputNode, outputNode.Id);
            }

            for (int i = 0; i < Config.Population; i++)
            {
                var newGenome = new Genome(progenitorGenome);
                newGenome.TryMutate();
                initSpecie.Genomes.Add(newGenome);
            }

            Species.Add(initSpecie);
            CurrentSpecie = Species.First();
            CurrentPlayer = CurrentSpecie.Genomes.First();
        }
示例#3
0
 public void AddNodeGene(NodeGene toAdd, int index)
 {
     if (!NodeGenes.ContainsKey(index))
     {
         NodeGenes.Add(index, toAdd);
     }
 }
示例#4
0
 public NodeGene(NodeGene source)
 {
     Id      = source.Id;
     Type    = source.Type;
     Value   = source.Value;
     IsReady = source.IsReady;
 }
示例#5
0
        public Genome(JToken json)
        {
            ConnectionGenes = new Dictionary <int, ConnectionGene>();
            NodeGenes       = new Dictionary <int, NodeGene>();
            foreach (var nodeJson in json["NodeGenes"].Children())
            {
                var node = new NodeGene(nodeJson);
                AddNodeGene(node);
            }
            foreach (var connectionJson in json["ConnectionGenes"].Children())
            {
                var id    = connectionJson.Value <int>("Key");
                var value = connectionJson.Value <JToken>("Value");

                var connection = new ConnectionGene(value);

                AddConnectionGene(connection, id);
            }
        }