示例#1
0
        //called for homogeneous agents, each one runs thier sensors through the network
        public void determineAction()
        {
            brain.SetInputSignals(sensors);
            brain.MultipleSteps(2);
            float[] outputs = new float[3];
            outputs[0] = (float)brain.GetOutputSignal(0);
            outputs[1] = (float)brain.GetOutputSignal(1);
            outputs[2] = (float)brain.GetOutputSignal(2);

            //the rest is the same as the heterogeneous, so call that fucntion
            determineAction(outputs);
        }
示例#2
0
        public bool timeStepMulti()
        {
            int predCount = Player.Count;

            float[] inputs;
            inputs = new float[Player.Count * 5];
            if (Enemy.Count == 0)
            {
                return(false);
            }


            //fill the predators' sensors and then copy those inputs to a big array that will input to the big ANN
            for (int pred = 0; pred < predCount; pred++)
            {
                Player[pred].clearSensors();

                Player[pred].fillSensorsFront(Enemy);

                //Here we assume 5 sensors per predator
                for (int sense = 0; sense < 5; sense++)
                {
                    inputs[sense + pred * 5] = Player[pred].sensors[sense];
                }
            }
            bigBrain.SetInputSignals(inputs);
            bigBrain.MultipleSteps(2);
            float[] outputs = new float[3];


            for (int agent = 0; agent < predCount; agent++)
            {
                outputs[0] = (float)bigBrain.GetOutputSignal(0 + agent * 3);
                outputs[1] = (float)bigBrain.GetOutputSignal(1 + agent * 3);
                outputs[2] = (float)bigBrain.GetOutputSignal(2 + agent * 3);
                (Player[agent]).determineAction(outputs);

                //If you're running the visualization, uncomment this line otherwise the sensor displays will lag by 1 timestep
                //pred.fillSensorsFront(Enemy);
            }
            int preyCount = Enemy.Count;

            for (int prey = 0; prey < preyCount; prey++)
            {
                //mark the dead guys for deletion
                if (Enemy[prey].hitpoints <= 0)
                {
                    removeThese.Add(Enemy[prey]);
                    continue;
                }

                Enemy[prey].determineAction();
            }

            foreach (Prey a in removeThese)
            {
                Enemy.Remove(a);
            }
            removeThese.Clear();
            return(true);
        }