Example #1
0
    public void AddNoteMutation_Test()
    {
        //Test list size before modifying
        Assert.AreEqual(parent1Genome.Connections.Values.Count, 6);
        Assert.AreEqual(parent1Genome.Nodes.Values.Count, 5);

        ConnectionGene splittedConnection = parent1Genome.Connections[3];
        object[] result = parent1Genome.AddNodeMutation(splittedConnection, 7, 11, 12);

        //Test if a node and connections were added
        Assert.AreEqual(parent1Genome.Connections.Values.Count, 8);
        Assert.AreEqual(parent1Genome.Nodes.Values.Count, 6);

        //Test the amount of results
        Assert.AreEqual(result.Length, 4);

        //Compare the disabled connection with the connection from the result
        Assert.AreEqual(splittedConnection, (ConnectionGene)result[0]);
        Assert.AreEqual(false, splittedConnection.Expressed);

        //Check ne newly created node
        NodeGene newNode = (NodeGene)result[1];
        Assert.AreEqual(NodeGeneType.HIDDEN, newNode.Type);
        Assert.AreEqual(newNode, parent1Genome.Nodes[newNode.ID]);
        Assert.AreEqual(7, newNode.ID);

        //Check the new connections
        ConnectionGene inToNew = (ConnectionGene)result[2];
        ConnectionGene newToOut = (ConnectionGene)result[3];

        //Check the in to new connection
        Assert.AreEqual(splittedConnection.InNode, inToNew.InNode);
        Assert.AreEqual(1.0, inToNew.Weight);
        Assert.AreEqual(newNode.ID, inToNew.OutNode);
        Assert.AreEqual(11, inToNew.InnovationNumber);
        Assert.AreEqual(inToNew, parent1Genome.Connections[inToNew.InnovationNumber]);

        //Check the new to out connection
        Assert.AreEqual(newNode.ID, newToOut.InNode);
        Assert.AreEqual(splittedConnection.Weight, newToOut.Weight);
        Assert.AreEqual(splittedConnection.OutNode, newToOut.OutNode);
        Assert.AreEqual(12, newToOut.InnovationNumber);
        Assert.AreEqual(newToOut, parent1Genome.Connections[newToOut.InnovationNumber]);
    }
Example #2
0
        public void TestAddNodeMutation()
        {
            Simulation tmpSim = new Simulation(r, gen1, 1);

            gen1.ParentSimulation = tmpSim;


            List <Innovation> innovations = new List <Innovation>();
            Genome            gen3        = new Genome(r);

            gen3.ParentSimulation = tmpSim;

            gen3.AddNode(new Node(Node.ENodeType.SENSOR, 1));
            gen3.AddNode(new Node(Node.ENodeType.SENSOR, 2));
            gen3.AddNode(new Node(Node.ENodeType.OUTPUT, 3));

            gen3.AddConnectionGene(1, 3, 0.5f);
            gen3.AddConnectionGene(2, 3, 1.0f);

            Assert.IsTrue(gen3.Nodes.Count == 3);
            gen3.AddNodeMutation(innovations);
            Assert.IsTrue(gen3.Nodes.Count == 4);
        }
Example #3
0
    private void Awake()
    {
        if (Manager.gameType == Manager.GameType.Train)
        {
            // add initial sensors for board
            for (int y = 1; y < 21; y++)
            {
                for (int x = 1; x < 11; x++)
                {
                    startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, (y - 1) * 10 + x));
                }
            }
            // add initial sensors for current tetromino
            for (int y = 1; y < 5; y++)
            {
                for (int x = 1; x < 5; x++)
                {
                    startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, (y - 1) * 4 + x + 200));
                }
            }
            // add initial sensor for next tetromino
            startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, 217));
            // add tetromino position sensor
            startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, 218));
            startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, 219));
            // add initial sensor for previous frame DAS
            startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, 220));
            // add initial BIAS SENSOR - SHOULD ALWAYS BE SET TO 1
            startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.SENSOR, 221));

            //add initial out nodes
            // 222 - null
            // 223 - left
            // 224 - down
            // 225 - right
            // 226 - a
            // 227 - b
            for (int i = 222; i < 228; i++)
            {
                startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.OUTPUT, i));
            }

            startingGenome.AddConnectionGene(new ConnectionGene(221, 223, 2f, true, History.Innovate()));

            startingGenome.AddConnectionMutation();
            startingGenome.AddNodeMutation();

            for (int y = 0; y < 20; y++)
            {
                startingGenome.AddNodeGene(new NodeGene(NodeGene.TYPE.HIDDEN, 228 + y));
                startingGenome.AddConnectionGene(new ConnectionGene(228 + y, Random.Range(222, 228), Random.Range(-2f, 2f), true, History.Innovate()));
            }

            for (int y = 0; y < 20; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    startingGenome.AddConnectionGene(new ConnectionGene(y * 10 + x + 1, 228 + y, Random.Range(0.5f, 2f), true, History.Innovate()));
                }
            }
        }
    }