private IEnumerator DisplayNetworkCoroutine(GenomeWrapper genome) { yield return(null); foreach (var connection in genome.Genome.Connections.Where(c => c.Value.Expressed)) { var newConnection = Instantiate(connectionPrefab, transform.position, Quaternion.identity).transform; newConnection.SetParent(networkConnectionsContainer, false); var newConnectionLine = newConnection.GetComponent <LineRenderer>(); newConnectionLine.SetPosition(0, currentNodes[connection.Value.InNode].transform.position); newConnectionLine.SetPosition(1, currentNodes[connection.Value.OutNode].transform.position); var lineColor = connection.Value.Weight < 0 ? negativeColor : positiveColor; lineColor.a = (connection.Value.Weight + 2) / 4; newConnectionLine.startColor = lineColor; newConnectionLine.endColor = lineColor; } }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { const float MaxVelociyTollerance = 100; const float DefaultVelociyTolleranceProportion = 0.1f; ShootAngle = genomeWrapper.GetScaledNumber(180); LocationAimWeighting = genomeWrapper.GetScaledNumber(2); SlowdownWeighting = genomeWrapper.GetScaledNumber(70); MaxRange = genomeWrapper.GetScaledNumber(5000, 0, 0.1f); MinRange = genomeWrapper.GetScaledNumber(1000, 0, 0.1f); MaxTangentialVelocity = genomeWrapper.GetScaledNumber(MaxVelociyTollerance, 0, DefaultVelociyTolleranceProportion); MinTangentialVelocity = genomeWrapper.GetScaledNumber(MaxVelociyTollerance, 0, DefaultVelociyTolleranceProportion); TangentialSpeedWeighting = genomeWrapper.GetScaledNumber(70); AngularDragForTorquers = genomeWrapper.GetScaledNumber(2, 0, 0.2f); RadialSpeedThreshold = genomeWrapper.GetScaledNumber(MaxVelociyTollerance, 0, DefaultVelociyTolleranceProportion); return(genomeWrapper); }
public GenomeWrapper Configure(GenomeWrapper genomeWrapper) { if (GetConfigFromGenome) { if (!HasBeenConfiguredByGenome) { HasBeenConfiguredByGenome = true; ConfigIndex = genomeWrapper.Position; return(SubConfigure(genomeWrapper)); } } else { HasBeenConfiguredByGenome = false; ConfigIndex = -1; } return(genomeWrapper); }
public void InitializeGenome(GenomeWrapper genome) { alivePopulation.Clear(); var newPlayerAI = Instantiate(playerAI, transform.position, Quaternion.identity); newPlayerAI.name = "0"; var newPlayerController = newPlayerAI.GetComponent <PlayerController>(); newPlayerController.genome = genome; newPlayerController.genome.Best = true; newPlayerController.instanceId = 0; alivePopulation.Add(newPlayerAI.GetComponent <PlayerController>()); NetworkDisplayer.Instance.DisplayNetwork(genome); newPlayerAI.GetComponent <SpriteRenderer>().color = Color.white; newPlayerAI.transform.GetChild(0).GetComponent <SpriteRenderer>().color = Color.white; newPlayerAI.transform.GetChild(1).GetComponent <MeshRenderer>().enabled = true; }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { const float MaxShootAngle = 180; const float DefaultShootAngleProportion = 0.5f; const float MaxLocationAimWeighting = 2; const float DefaultLocationAimWeightingProportion = 0.5f; const float MaxSlowdownWeighting = 70; const float DefaultSlowdownWeightingProportion = 0.5f; const float MaxTangentialVelosityWeighting = 70; const float DefaultTangentialVelosityWeightingProportion = 0.5f; const float MaxMaxAndMinRange = 1000; const float DefaultMaxAndMinRangeProportion = 0.1f; const float MaxVelociyTollerance = 100; const float DefaultVelociyTolleranceProportion = 0.1f; const float MaxAngularDragForTorquers = 2; const float DefaultAngularDragForTorquersProportion = 0.2f; ShootAngle = genomeWrapper.GetScaledNumber(MaxShootAngle, 0, DefaultShootAngleProportion); LocationAimWeighting = genomeWrapper.GetScaledNumber(MaxLocationAimWeighting, 0, DefaultLocationAimWeightingProportion); SlowdownWeighting = genomeWrapper.GetScaledNumber(MaxSlowdownWeighting, 0, DefaultSlowdownWeightingProportion); MaxRange = genomeWrapper.GetScaledNumber(MaxMaxAndMinRange, 0, DefaultMaxAndMinRangeProportion); MinRange = genomeWrapper.GetScaledNumber(MaxMaxAndMinRange, 0, DefaultMaxAndMinRangeProportion); MaxTangentialVelocity = genomeWrapper.GetScaledNumber(MaxVelociyTollerance, 0, DefaultVelociyTolleranceProportion); MinTangentialVelocity = genomeWrapper.GetScaledNumber(MaxVelociyTollerance, 0, DefaultVelociyTolleranceProportion); TangentialSpeedWeighting = genomeWrapper.GetScaledNumber(MaxTangentialVelosityWeighting, 0, DefaultTangentialVelosityWeightingProportion); AngularDragForTorquers = genomeWrapper.GetScaledNumber(MaxAngularDragForTorquers, 0, DefaultAngularDragForTorquersProportion); RadialSpeedThreshold = genomeWrapper.GetScaledNumber(MaxVelociyTollerance, 0, DefaultVelociyTolleranceProportion); return(genomeWrapper); }
public void ResetGameAndNetwork(GenomeWrapper startingGenome = null) { foreach (var leftOvers in GameObject.FindGameObjectsWithTag("Flappy")) { Destroy(leftOvers); } PipeSpawner.Instance.Reset(); mainCamera.transform.position = new Vector3(7, 0, -10); NEATHandler.Instance.InitializeNetwork(startingGenome); if (raceNetwork.isOn) { Instantiate(flappy, transform.position, Quaternion.identity); } else { inRaceMode = false; NEATHandler.Instance.sevenInputsMode.interactable = true; PipeSpawner.Instance.automaticPipes.interactable = true; } playerAlive = true; generation = 0; }
public void DisplayNetwork(GenomeWrapper genome) { currentNetwork = genome.Network; currentNodes.Clear(); foreach (Transform layer in networkContainer) { Destroy(layer.gameObject); } foreach (Transform layer in networkConnectionsContainer) { Destroy(layer.gameObject); } var nodes = new SortedDictionary <float, List <int> >(); foreach (var node in genome.Genome.Nodes) { if (!nodes.ContainsKey(node.Value.X)) { nodes[node.Value.X] = new List <int>(); } nodes[node.Value.X].Add(node.Key); } foreach (var nodeLayer in nodes) { var newLayer = Instantiate(layerPrefab, transform.position, Quaternion.identity).transform; newLayer.SetParent(networkContainer, false); foreach (var node in nodeLayer.Value) { var newNode = Instantiate(nodePrefab, transform.position, Quaternion.identity).transform; newNode.SetParent(newLayer, false); currentNodes.Add(node, newNode.GetComponent <Image>()); } } StartCoroutine(DisplayNetworkCoroutine(genome)); }
public void ResetGameAndNetwork(GenomeWrapper startingGenome = null, bool resetGeneration = true) { if (resetGeneration) { generation = 0; } Settings.Instance.maxBalloons = survivalMode.isOn ? generation + 5 : 3; globalBalloonSpawner.balloonsSpawned = 0; globalBalloonSpawner.balloonsText.text = $"{0}/{Settings.Instance.maxBalloons}"; foreach (var food in GameObject.FindGameObjectsWithTag("Arrow")) { Destroy(food); } foreach (var tail in GameObject.FindGameObjectsWithTag("Player")) { Destroy(tail); } foreach (var snake in GameObject.FindGameObjectsWithTag("Balloon")) { Destroy(snake); } foreach (var snake in GameObject.FindGameObjectsWithTag("EvilBalloon")) { Destroy(snake); } NEATHandler.Instance.InitializeNetwork(startingGenome); if (!useTrainedNetwork.isOn) { Instantiate(player, transform.position, Quaternion.identity); } playerAlive = true; }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { MotorForce = genomeWrapper.GetScaledNumber(MotorForce * 2); return(genomeWrapper); }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { genomeWrapper = new ShipBuilder(genomeWrapper, this).BuildShip(true); return(genomeWrapper); }
public void SetGenome(GenomeWrapper genomeWrapper) { _genome = genomeWrapper; }
//private void LogTargetChange(Target old, PotentialTarget newTarget, bool oldWasInvalid) //{ // var log = transform.name + " has started targeting "; // if (newTarget != null) // { // log += newTarget.Transform.name + " (score=" + newTarget.Score + ") at " + newTarget.Transform.position; // } else // { // log += "nothing"; // } // if (oldWasInvalid) // { // log += " because the previous target was invalid"; // } else if (old != null) // { // log += ". Previously " + old.Transform.name + " at " + old.Transform.position; // Debug.Log(log); //log only retargets. // return; // } // //Debug.Log(log); //} protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { PollInterval = genomeWrapper.GetScaledNumber(10, 1); return(genomeWrapper); }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { ShootAngle = genomeWrapper.GetScaledNumber(20, 0, 0.01f); return(genomeWrapper); }
protected abstract GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper);
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { return(genomeWrapper); }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { Fuel = genomeWrapper.GetScaledNumber(Fuel, 0, 0.9f); return(genomeWrapper); }
protected override GenomeWrapper SubConfigure(GenomeWrapper genomeWrapper) { Friction = genomeWrapper.GetScaledNumber(Friction * 2); return(genomeWrapper); }
public void UpdateGeneration_SavesCurrentGeneration() { Generation gen = new Generation(); gen.Individuals.Add(new Individual("abc")); gen.Individuals.Add(new Individual("def")); _handler.SaveNewGeneration(gen, 3, 4); Generation RetrievedGen1 = _handler.ReadGeneration(3, 4); Assert.IsNotNull(RetrievedGen1); Assert.AreEqual(2, RetrievedGen1.Individuals.Count); var i1 = RetrievedGen1.Individuals.First(); Assert.AreEqual("abc", i1.Genome); Assert.AreEqual(0, i1.Score); Assert.AreEqual(0, i1.MatchesAsLastSurvivor); Assert.AreEqual("", i1.PreviousCombatantsString); Assert.AreEqual(0, i1.PreviousCombatants.Count); var i2 = RetrievedGen1.Individuals[1]; Assert.AreEqual("def", i2.Genome); Assert.AreEqual(0, i2.Score); Assert.AreEqual(0, i2.MatchesAsLastSurvivor); Assert.AreEqual("", i2.PreviousCombatantsString); Assert.AreEqual(0, i2.PreviousCombatants.Count); var gwA = new GenomeWrapper("abc") { Budget = 59 }; gen.RecordMatch(gwA, 5, true, false, 0, new List <string> { "abc", "def" }, true); gen.RecordMatch(new GenomeWrapper("def"), 15, false, false, 0, new List <string> { "abc", "def" }, false); _handler.UpdateGeneration(gen, 3, 4); Generation RetrievedGen2 = _handler.ReadGeneration(3, 4); Assert.IsNotNull(RetrievedGen2); Assert.AreEqual(2, RetrievedGen2.Individuals.Count); var i1b = RetrievedGen2.Individuals.First(i => i.Genome == "abc"); Assert.AreEqual(5, i1b.Score); Assert.AreEqual(1, i1b.MatchesAsLastSurvivor); Assert.AreEqual(1, i1b.MatchesPlayed); Assert.AreEqual(1, i1b.MatchesSurvived); Assert.AreEqual("def", i1b.PreviousCombatantsString); Assert.AreEqual(1, i1b.PreviousCombatants.Count); Assert.AreEqual("def", i1b.PreviousCombatants.First()); var i2b = RetrievedGen2.Individuals.First(i => i.Genome == "def"); Assert.AreEqual(15, i2b.Score); Assert.AreEqual(0, i2b.MatchesAsLastSurvivor); Assert.AreEqual(0, i2b.MatchesSurvived); Assert.AreEqual(1, i2b.MatchesPlayed); Assert.AreEqual("abc", i2b.PreviousCombatantsString); Assert.AreEqual(1, i2b.PreviousCombatants.Count); Assert.AreEqual("abc", i2b.PreviousCombatants.First()); }