Exemplo n.º 1
0
    void Update()
    {
        if (KeepGoing)
        {
            // Announce start of simulation, if it is the start
            if (StepsTaken == 0)
            {
                Debug.Log("Starting next replicate.");
            }



            // Step forward the specified number of steps for one frame
            for (int i = 0; i < StepsPerFrame; i++)
            {
                model.Step();
                StepsTaken++;
                StepsTakenSinceLastRecord++;
            }


            // Do group tracking, if enabled
            if (GroupTracking)
            {
                model.TrackGroups();
            }



            // Possibly save state
            if (RecordData)
            {
                if (StepsTakenSinceLastRecord >= StepsPerRecord)
                {
                    datarecorder.SaveNow();
                    StepsTakenSinceLastRecord = 0;
                }
            }



            // Check for halftime switch
            if (HalftimeSwitch)
            {
                if (!HalftimeSwitchIsComplete)
                {
                    if (StepsTaken > HalfMaxSteps)
                    {
                        model.CollectivePred     = !model.CollectivePred;
                        HalftimeSwitchIsComplete = true;
                        Debug.Log("Halftime switch complete.");
                    }
                }
            }


            // Check for doneness and respond accordingly
            bool IsCompletedRep = StepsTaken > MaxSteps | model.PredPopulationSize == 0;

            if (IsCompletedRep)
            {
                if (RecordData)
                {
                    datarecorder.CloseNow();
                }

                KeepGoing = false;
                ReplicatesCompleted++;
                Debug.Log("Replicate complete.");

                if (ReplicatesCompleted < Replicates)
                {
                    model.CarryingCapacity += EnrichmentIncrement;
                    SetupSimulation();
                }
                else
                {
                    Debug.Log("All replicates complete.");
                }
            }
        }
    }