예제 #1
0
    def runGeneration(self):
        time = 0
        crashed = [False for c in range(self.numCars)]
        numCrashed = 0
        path = Path(500, 500)
        self.generation += 1
        # drives cars until they crash
        while numCrashed < self.numCars:
            for c in range(self.numCars):
                if not crashed[c]:
                    # car attempts to drive
                    car = self.cars[c]
                    car.drive(path)

                    # tests if the car crashed
                    maxTime = 5000
                    if car.checkCrash(path) or time >= maxTime:
                        print("Cars Remaining: %d Fitness: %d" %
                              ((self.numCars - numCrashed), time))
                        crashed[c] = True
                        numCrashed += 1
                        self.fitness[c] = time
                    path.generatePath(car)
            time += 1