void NewGeneration() { generationBestActions.Clear(); generation++; if (generation > setUp.endAfterGen || bestFitnessOverall >= setUp.endFitnessReq) { EndGeneration(); } GetComponent <CSVWriter>().WriteConvergenceNewGen(generation); //write out generation data. UImanager.UpdateGeneration(generation); candidate = 0; UImanager.UpdateCandidate(candidate); UImanager.UpdateTests(0); //clear old offspring CurrentOffspring.Clear(); //generate new offspring for (int i = 0; i < offSpringPopulation; i++) { Selection(); } //preperation for new generation CandidateList.Clear(); CandidateFitness.Clear(); currentProbabilityTransMatrix = CurrentOffspring[Random.Range(0, CurrentOffspring.Count)]; foreach (var LGM in levelGMs) { LGM.GetComponent <LevelGenerator>().SetNewChain(currentProbabilityTransMatrix); LGM.GetComponent <LevelGenerator>().NewLevelCandidate(); } }
// Use this for initialization void Start() { GetComponent <CostFunction>().SetMapping(setUp.mapping); candidateGoal = setUp.candidateReq; offSpringPopulation = setUp.populationOffspring; generation = 1; candidate = 0; UImanager.UpdateCandidate(candidate); UImanager.UpdateGeneration(generation); //States based on level height to deterimine transition amount; transitions = setUp.height; // ground transitions += setUp.height; // gaps if (setUp.spikes == true) { transitions = transitions + setUp.height; // spikes transitions = transitions + setUp.height; // spike gaps } stateAmounts = transitions; transitions = (int)Mathf.Pow(transitions, setUp.historySteps + 1); //generates empty matrix List <int> x = new List <int>(); for (int j = 0; j < transitions; j++) { x.Add(100 / transitions); } currentProbabilityTransMatrix = new List <int[]>(); for (int i = 0; i < transitions; i++) { currentProbabilityTransMatrix.Add(x.ToArray()); } levelGMs.Clear(); int y = 0; //greaate level generation managers; for (int i = 0; i < setUp.testersOnScreen; i++) { Vector2 pos = transform.position - new Vector3(0, y); GameObject gobj = Instantiate(LevelGenerator, pos, transform.rotation); levelGMs.Add(gobj); y += setUp.height + 10; } //set up and begin parameters of level generators RandomChain(); foreach (var LGM in levelGMs) { LGM.GetComponent <LevelGenerator>().MyStart(setUp.height, setUp.length, transitions, setUp.mapping, setUp.historySteps, stateAmounts); LGM.GetComponent <LevelGenerator>().SetNewChain(currentProbabilityTransMatrix); LGM.GetComponent <LevelGenerator>().NewLevelCandidate(); } GetComponent <CSVWriter>().WriteConvergenceDesignCurve(GetComponent <CSVReader>().getOrderedCurveValues()); GetComponent <CSVWriter>().WriteConvergenceNewGen(generation); GetComponent <CSVWriter>().WriteTestInfo(setUp.height, setUp.length, setUp.minimumFitnessReq); GetComponent <CSVWriter>().WriteCandidate(currentProbabilityTransMatrix, candidate, generation); GetComponent <ScreenCaptureHandler>().ClearFolder(); }
protected override void Shutdown() { try { lib.gameStatus = 0; if (lib.status == 0) { Utility.WindowText("Asheron's Call"); } else if (lib.Autorelog == false) { Utility.AddWindowText(lib.MyServer + " : " + lib.MyName + " logged off by " + lib.reason + " at " + DateTime.Now.ToString("h:mm:ss tt")); if (lib.UseMacroLogic == true && lib.reason != "user") { Utility.ActivateWindow(); } } else if (lib.Autorelog == true && lib.longcycle == false) { Utility.AddWindowText(lib.MyServer + " : " + lib.MyName + " logged off by " + lib.reason + " at " + DateTime.Now.ToString("h:mm:ss tt") + ". Relogger is set to " + lib.Timer + " seconds. Counter: " + lib.relogcounter); if (lib.UseMacroLogic == true) { Utility.ActivateWindow(); } } else if (lib.Autorelog == true && lib.longcycle == true) { Utility.AddWindowText(lib.MyServer + " : " + lib.MyName + " logged off by " + lib.reason + " at " + DateTime.Now.ToString("h:mm:ss tt") + ". Relogger is on Long Cycle (10 minutes)."); lib.longcycle = false; if (lib.UseMacroLogic == true) { Utility.ActivateWindow(); } } lib.MyCore.CharacterFilter.Login -= Core_Login_Init; if (lib.AuthInstance > 0) { ATH.Dispose(); } if (lib.CommandsInstance > 0) { CMD.Dispose(); } if (lib.LoggingInstance > 0) { LGM.Dispose(); } if (lib.ViewControlInstance > 0) { VCT.Dispose(); } if (lib.ScannerInstance > 0) { SCN.Dispose(); } if (lib.DeathParseInstance > 0) { DTH.Dispose(); } if (lib.SoundInstance > 0) { SND.Dispose(); } if (lib.MacroInstance > 0) { MCL.Dispose(); } if (lib.VersInstance > 0) { VSC.Dispose(); } if (lib.HUDInstance > 0) { HUD.Dispose(); } if (lib.ReportInstance > 0) { REP.Dispose(); } if (SCN != null) { SCN = null; } if (SND != null) { SND = null; } if (ATH != null) { ATH = null; } if (VCT != null) { VCT = null; } if (DTH != null) { DTH = null; } if (CMD != null) { CMD = null; } if (VSC != null) { VSC = null; } if (LGM != null) { LGM = null; } if (MCL != null) { MCL = null; } if (HUD != null) { HUD = null; } if (REP != null) { REP = null; } if (ShrtTmr.Enabled == true) { ShrtTmr.Stop(); ShrtTmr.Dispose(); } if (LngTmr.Enabled == true) { LngTmr.Stop(); LngTmr.Dispose(); } if (LogTmr.Enabled == true) { LogTmr.Stop(); LogTmr.Dispose(); } PGCore = null; lib.PluginInstance--; lib.Dispose(); } catch (Exception ex) { Repo.RecordException(ex); } }
void NewCandidate() { float currentBestFit = 0; float totalCost = 0; //find most fit level generated of the matrix from this candidate for (int i = 0; i < candidateAllActions.Count; i++) { float cost = GetComponent <CostFunction>() .CalculateCost(GetComponent <CSVReader>().getOrderedCurveValues(), candidateAllActions[i]); totalCost += cost; float fits = 1 - cost; if (fits > (float)bestFitnessOverall) { UImanager.UpdateFitness((int)(System.Math.Round(fits, 2) * 100)); bestFitnessOverall = fits; bestTransitionMatrix = currentProbabilityTransMatrix; bestCandidateActions = candidateAllActions[i].ToArray(); bestTransitionPath = candidateAllPaths[i]; } if (fits > currentBestFit) { currentBestFit = fits; } } //updates if a new best level generation path has been found. float totalAvg = totalCost / testersDone; if (currentBestFit >= setUp.minimumFitnessReq) { GetComponent <CSVWriter>().WriteConvergence(candidateAllActions[Random.Range(0, testersDone)]); CandidateList.Add(currentProbabilityTransMatrix); CandidateFitness.Add((currentBestFit * currentBestFit)); //multiplcation to weed out worse candidates futher in Selection() GetComponent <CSVWriter>().WriteFitness(currentBestFit); GetComponent <CSVWriter>().CandidateToCSVAndClear(true); candidate++; UImanager.UpdateCandidate(candidate); } else { GetComponent <CSVWriter>().CandidateToCSVAndClear(false); } candidateAllActions.Clear(); candidateAllPaths.Clear(); testersDone = 0; //generates/selects new transition matrix, and sets it for each level generator if (generation == 1) { RandomChain(); foreach (var LGM in levelGMs) { LGM.GetComponent <LevelGenerator>().SetNewChain(currentProbabilityTransMatrix); LGM.GetComponent <LevelGenerator>().NewLevelCandidate(); } } else { currentProbabilityTransMatrix = CurrentOffspring[Random.Range(0, CurrentOffspring.Count)]; foreach (var LGM in levelGMs) { LGM.GetComponent <LevelGenerator>().SetNewChain(currentProbabilityTransMatrix); LGM.GetComponent <LevelGenerator>().NewLevelCandidate(); } } //new Generation if (CandidateList.Count >= setUp.candidateReq) { NewGeneration(); } }
public void Core_Login_Retry() { try { if (lib.PluginInstance == 1) { if (lib.DFTEXT != null) { lib.DFTEXT.Dispose(); lib.DFTEXT = null; } if (lib.DF2TEXT != null) { lib.DF2TEXT.Dispose(); lib.DF2TEXT = null; } if (lib.AuthInstance > 0) { ATH.Dispose(); } if (lib.CommandsInstance > 0) { CMD.Dispose(); } if (lib.LoggingInstance > 0) { LGM.Dispose(); } if (lib.ViewControlInstance > 0) { VCT.Dispose(); } if (lib.ScannerInstance > 0) { SCN.Dispose(); } if (lib.DeathParseInstance > 0) { DTH.Dispose(); } if (lib.SoundInstance > 0) { SND.Dispose(); } if (lib.MacroInstance > 0) { MCL.Dispose(); } if (lib.VersInstance > 0) { VSC.Dispose(); } if (lib.HUDInstance > 0) { HUD.Dispose(); } if (lib.ReportInstance > 0) { REP.Dispose(); } if (SCN != null) { SCN = null; } if (SND != null) { SND = null; } if (ATH != null) { ATH = null; } if (VCT != null) { VCT = null; } if (DTH != null) { DTH = null; } if (CMD != null) { CMD = null; } if (VSC != null) { VSC = null; } if (LGM != null) { LGM = null; } if (MCL != null) { MCL = null; } if (HUD != null) { HUD = null; } if (REP != null) { REP = null; } CMD = new Commands(); CMD.InitCommands(PGCore); Core_Login_Check(); } } catch (Exception ex) { Repo.RecordException(ex); } }