NEAT in Unity
NEAT in Unity
Generic;
using UnityEngine;
// Create two new connections, one from the from node to the new node,
and one from the new node to the to node
connections.Add(new Connection(connection.FromNode, node, 1.0f));
connections.Add(new Connection(node, connection.ToNode,
connection.Weight));
break;
// Add a connection
case 1:
// Choose two random nodes that are not already connected
Node fromNode = nodes[Random.Range(0, nodes.Count)];
Node toNode = nodes[Random.Range(0, nodes.Count)];
// Check if the nodes are not the same and if the connection does not
already exist
if (fromNode.ID != toNode.ID && !connections.Exists(x => x.FromNode.ID
== fromNode.ID && x.ToNode.ID == toNode.ID))
{
// Add the connection
connections.Add(new Connection(fromNode, toNode, Random.Range(-
1.0f, 1.0f)));
}
break;
// Change a weight
case 2:
// Choose a random connection
Connection c = connections[Random.Range(0, connections.Count)];
// Change the weight of the connection
c.Weight += Random.Range(-0.1f, 0.1f);
break;
}
}
// List of genomes
private List<Genome> genomes = new List<Genome>();