예제 #1
0
    public void AddConnectionMutation_Test()
    {
        NodeGene node1 = parent1Genome.Nodes[3];
        NodeGene node2 = parent1Genome.Nodes[5];

        //Test list size before modifying
        Assert.AreEqual(parent1Genome.Connections.Values.Count, 6);

        //Add the connection
        ConnectionGene newConnection = parent1Genome.AddConnectionMutation(node1, node2, 11);

        //Test if a connection was added to the list
        Assert.AreEqual(parent1Genome.Connections.Values.Count, 7);
        Assert.NotNull(newConnection);

        //Test if connection is added to the list
        Assert.AreEqual(newConnection, parent1Genome.Connections[newConnection.InnovationNumber]);

        //Test if connection has correct input node
        Assert.AreEqual(newConnection.InNode, node1.ID);
        Assert.AreEqual(newConnection.OutNode, node2.ID);
        Assert.GreaterOrEqual(newConnection.Weight, -1.0f);
        Assert.LessOrEqual(newConnection.Weight, 1.0f);
        Assert.AreEqual(11, newConnection.InnovationNumber);
    }
예제 #2
0
        public void TestAddConnectionMutation()
        {
            List <Innovation> innovations = new List <Innovation>();


            Simulation tmpSim = new Simulation(r, gen1, 1);

            gen1.ParentSimulation = tmpSim;


            Genome gen4 = new Genome(r);

            gen4.ParentSimulation = tmpSim;

            // Create 3 sensors
            gen4.AddNode(new Node(Node.ENodeType.SENSOR, 1));
            gen4.AddNode(new Node(Node.ENodeType.SENSOR, 2));
            gen4.AddNode(new Node(Node.ENodeType.SENSOR, 3));

            // Create 1 output
            gen4.AddNode(new Node(Node.ENodeType.OUTPUT, 4));

            // Create 1 hidden node
            gen4.AddNode(new Node(Node.ENodeType.HIDDEN, 5));

            // Add connections from the paper
            gen4.AddConnectionGene(1, 4);
            gen4.AddConnectionGene(2, 4);
            gen4.AddConnectionGene(3, 4);
            gen4.AddConnectionGene(2, 5);
            gen4.AddConnectionGene(5, 4);

            Assert.IsTrue(gen4.ConnectionGenes.Count == 5);
            gen4.AddConnectionMutation(innovations);
            Assert.IsTrue(gen4.ConnectionGenes.Count == 6);
        }
예제 #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()));
                }
            }
        }
    }