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; }
private void MoveToCell(Agent agent, Coordinate coordinate, Coordinate newCoordinate) { World[coordinate].Agent = null; World[newCoordinate].Agent = agent; agent.HasMoved = true; }
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; }
private static void DistributeFitness(Agent parent, Agent child) { var fitness = parent.Fitness / 2; parent.Fitness = fitness; child.Fitness = fitness; }
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; }