// Update is called once per frame void Update() { if (numSimulated == carsPerGeneration && totalFailure) { smolBrains = GenerateChildren(brains); numSimulated = 0; currentGeneration++; FindBest(); Death(); Cleanup(); totalFailure = false; } else if (totalFailure) { SpawnCars(); totalFailure = false; } else { totalFailure = true; // TODO: Optimize me cap'n for (int i = 0; i < cars.Length; i++) { if (cars[i] != null) { // Save data and destroy failed cars if (cars[i].GetComponent <Car2DTrainer>().hasFailed) { Car2DTrainer car = cars[i].GetComponent <Car2DTrainer>(); // Saving important car info carData[i] = new Car2DData(car.GetNetwork(), car.numberOfSightLines, car.FOV, car.sightDistance); Destroy(cars[i]); } } if (cars[i] != null) { // Update each car's progress along the track TrackProgress(cars[i]); totalFailure = false; if (cars[i].GetComponent <Car2DTrainer>().lap > numberOfLaps) { cars[i].GetComponent <Car2DTrainer>().hasFailed = true; // Stop a car that has completed all laps Destroy(cars[i]); } } } } }
private bool LoadTest() { Car2DData loadedData; if (!Load(out loadedData)) { return(false); } GameObject loadCar = Instantiate(carPrefab, startLine.transform.position, startLine.transform.rotation); Car2DTrainer carData = loadCar.GetComponent <Car2DTrainer>(); loadCar.name = "Loaded Car"; loadCar.GetComponent <Renderer>().material.color = Color.green; carData.SetNetwork(loadedData.GetNetwork()); carData.numberOfSightLines = loadedData.GetSightLines(); carData.FOV = loadedData.GetFOV(); carData.sightDistance = loadedData.GetSightDistance(); return(true); }