Esempio n. 1
0
        private void Fight(Agent agent, Agent opponent)
        {
            var agentIndex = agent is Hawk ? 0 : 1;
            var opponentIndex = opponent is Hawk ? 0 : 1;

            agent.Fitness += _payoffMatrix[agentIndex, opponentIndex];
            agent.HasMoved = true;
            opponent.Fitness += _payoffMatrix[opponentIndex, agentIndex];
            opponent.HasMoved = true;
        }
Esempio n. 2
0
 private void MoveToCell(Agent agent, Coordinate coordinate, Coordinate newCoordinate)
 {
     World[coordinate].Agent = null;
     World[newCoordinate].Agent = agent;
     agent.HasMoved = true;
 }
Esempio n. 3
0
        private static Agent CreateChild(Agent parent)
        {
            Agent child;

            if (parent is Hawk)
                child = new Hawk { HasMoved = true };
            else
                child = new Dove { HasMoved = true };

            DistributeFitness(parent, child);

            return child;
        }
Esempio n. 4
0
 private static void DistributeFitness(Agent parent, Agent child)
 {
     var fitness = parent.Fitness / 2;
     parent.Fitness = fitness;
     child.Fitness = fitness;
 }
Esempio n. 5
0
        private void Breed(Agent parent, Coordinate coordinate)
        {
            Coordinate newCoordinate;
            _cellFinder.PickWithoutAgent(World.Field, coordinate, out newCoordinate);

            if (newCoordinate == Coordinate.Empty)
                return;

            var child = CreateChild(parent);

            World[newCoordinate].Agent = child;
        }