public double RunEngineFreelyWithPlayabilityCheck(int time, GameTime gameTime) { int counterTime = 0; while (counterTime <= time) { if (!GenericHelperModule.CookieOutsideWindow()) { if (!SetPlayability()) { StaticData.EngineManager.Update(gameTime); counterTime++; } else { break; } } else { break; } } return(this.ClosestCookieFrogDistance); }
public override void Draw(GameTime gameTime) { float angle = -1 * MathHelper.ToRadians(GenericHelperModule.GetProperOrientation(this.Dir)); this.SetOrientation(angle); base.Draw(gameTime); }
public static void EnhanceDesign(bool gammarsSetByUser) { if (!gammarsSetByUser) { String strGrammar = String.Empty; strGrammar = StaticData.EngineManager.PrefCompsManager.GetPrefCompsToGrammarFile(); StreamWriter sw = new StreamWriter(FileGrammarPath); sw.Write(strGrammar); sw.Flush(); sw.Close(); } if (StaticData.CtrLevelDesigner.rbPCNone.Checked || ( (StaticData.CtrLevelDesigner.rbPCNone.Checked == false && StaticData.CtrLevelDesigner.rbPCNormalCheck.Checked == false) && StaticData.CtrLevelDesigner.rbPCRandom.Checked == false ) ) { GenericHelperModule.RunJavaProcess(@"C:\CTREngine\AuthoringToolEngineGEVAOnly.jar"); StreamReader sr = new StreamReader(@"C:\CTREngine\EvolvedLevel.txt"); GevaLevel = sr.ReadToEnd().Split('\n')[0]; PlayabilityActions = String.Empty; sr.Close(); } else { if (StaticData.CtrLevelDesigner.rbPCNormalCheck.Checked) { GenericHelperModule.RunJavaProcess( @"C:\CTREngine\AuthoringToolEngineWithNormalPlayFitness.jar"); } else { if (StaticData.CtrLevelDesigner.rbPCRandom.Checked) { GenericHelperModule.RunJavaProcess( @"C:\CTREngine\AuthoringToolEngineWithRandomPlayFitness.jar"); } } StreamReader sr = new StreamReader(@"C:\CTREngine\PhysicsEngine_EvolvePlayActions.txt"); String line = sr.ReadToEnd(); GevaLevel = line.Split('\t')[13]; PlayabilityActions = line.Split('\t')[14]; if (line.Split('\t')[1].ToLower() == "true") { MessageBox.Show( @"Playability-check is finished. The engine has found a playable level."); } sr.Close(); } LevelBuilder.CreateRestedLevel(DesignEnhanceManager.GevaLevel, false); StaticData.ManipulationGameMode = ManipulationGameMode.NeutralMode; StaticData.GameSessionMode = SessionMode.DesignMode; }
private static void PrintToFile(String[] args, bool isGinSimComp, GenSimAgent agent, float fitness, DateTime d1, DateTime d2) { StreamWriter swGEVA = new StreamWriter(@"C:\CTREngine\PlayabilityVal_ZGTREngine.txt"); swGEVA.WriteLine(fitness); swGEVA.Flush(); swGEVA.Close(); String playableFileName = isGinSimComp ? @"C:\CTREngine\GenSimCompLevelsPlayable.txt" : @"C:\CTREngine\GenSimLevelsPlayable.txt"; String nonPlayableFileName = isGinSimComp ? @"C:\CTREngine\GenSimCompLevelsNonPlayable.txt" : @"C:\CTREngine\GenSimLevelsNonPlayable.txt"; bool solved = false; if (agent.IsSuccess) { solved = true; StreamWriter swPlayLevelGeva = new StreamWriter(@"C:/CTREngine/GenSimPlayabilityLevel_ZGTREngine.txt"); swPlayLevelGeva.WriteLine(agent.LevelStr); swPlayLevelGeva.Flush(); swPlayLevelGeva.Close(); } String strToFile = solved + "\t" + agent.ActionsSoFar + "\t" + agent.GetActionsToDo().Count + "\t" + (d2 - d1).TotalMilliseconds + "\t" + String.Format("{0:0.00}", fitness) + "\t" + agent.LevelStr + "\t" + args[1] + "\t" + GenericHelperModule.GetActionsString(agent.Actions) + "\t" + GenericHelperModule.GetCTPString(agent.BestCTPPairs, true) + "\t" + GenericHelperModule.GetCTPString(agent.BestCTPPairs, false); if (agent.IsSuccess) { StreamWriter sw = new StreamWriter(playableFileName, true); sw.WriteLine(strToFile); sw.Flush(); sw.Close(); } else { StreamWriter sw2 = new StreamWriter(nonPlayableFileName, true); sw2.WriteLine(strToFile); sw2.Flush(); sw2.Close(); } }
private void bGenerateSamples_Click(object sender, EventArgs e) { GenericHelperModule.RunJavaProcess(@"C:\CTREngine\AuthoringToolEngineGEVAOnly.jar"); StreamReader sr = new StreamReader(@"C:\CTREngine\EvolvedLevel.txt"); String gevaLevel = sr.ReadToEnd().Split('\n')[0]; sr.Close(); LevelBuilder.CreateRestedLevel(gevaLevel, false); StaticData.ManipulationGameMode = ManipulationGameMode.NeutralMode; StaticData.GameSessionMode = SessionMode.DesignMode; }
public static List <Action> GetNextActionsSet(ref int voidInitPlayCount, PlayabilityCheckMode checkMode) { if (voidInitPlayCount < VoidInitPlayTotalCount) { voidInitPlayCount++; return(new List <Action>() { new VoidAction() }); } List <Action> listOfAllPossibleActions = null; switch (checkMode) { case PlayabilityCheckMode.NormalCheck: // Set Engine State Into Predicates File SetEngineStateIntoPredicatesFile(); // Run Prolog GenericHelperModule.RunJavaProcess(_prologEnginePath); // Get new actions to test String fullPrologString = GetPrologActionsString(); listOfAllPossibleActions = GetAllPossibleActions(fullPrologString); break; case PlayabilityCheckMode.RandomCheck: listOfAllPossibleActions = new List <Action>() { RandomPlayabilityGenerator.GetNewRandomAction() }; break; default: throw new ArgumentOutOfRangeException("checkMode"); } return(listOfAllPossibleActions); }
//public void SimulatePlayability(EngineManager engineManager, ref bool isPlayable, // int nrOfActionSoFar, List<Action> performedActions, List<Vector3> velocitesInActions, int voidInitPlayCount, PlayabilityCheckMode checkMode) //{ // SimulatePlayability(null, engineManager, ref isPlayable, // nrOfActionSoFar, performedActions, velocitesInActions, voidInitPlayCount, checkMode); //} public void SimulatePlayability(ActionNode node, EngineManager engineManager, ref bool isPlayable, int nrOfActionSoFar, List <Action> performedActions, List <Vector3> velocitesInActions, int voidInitPlayCount, PlayabilityCheckMode checkMode) { try { StaticData.GameSessionMode = SessionMode.PlayingMode; nrOfActionSoFar++; if (nrOfActionSoFar == 1) { int k = 0; } //EngineManager currentOriginalEngineManager = ObjectSerializer.DeepCopy(engineManager); //StaticData.EngineManager = currentEngineManager; if (!isPlayable) { if (nodesExplored < MaxNrOfNodesExplored) { if (nrOfActionSoFar < MaxNrOfActionsPreformed) { if (nrOfActionSoFar > maxDepthArr) { maxDepthArr = nrOfActionSoFar; } // Shortcut - Check if the cookie is so far away; cut this branch of tree then! if (StaticData.EngineManager.CookieRB.GetVelocity() == Vector3.Zero) { return; } if (GenericHelperModule.CookieOutsideWindow()) { return; } DateTime d1 = DateTime.Now; List <Action> listOfAllPossibleActions = GetNextActionsSet(ref voidInitPlayCount, checkMode); DateTime d2 = DateTime.Now; prologTime += (d2 - d1).Milliseconds; if (node != null) { node.Childs.AddRange(listOfAllPossibleActions.ConvertAll(a => new ActionNode(a))); } if (listOfAllPossibleActions.Count == 1) { if (listOfAllPossibleActions[0] is TerminateBranch) { NrOfTerminates++; TerminateLevelSum += nrOfActionSoFar; if (nrOfActionSoFar < NrLevelterminatesStdMin) { NrLevelterminatesStdMin = nrOfActionSoFar; } if (nrOfActionSoFar > NrLevelterminatesStdMax) { NrLevelterminatesStdMax = nrOfActionSoFar; } return; } } if (listOfAllPossibleActions.Count == 0) { listOfAllPossibleActions.Add(new VoidAction()); } //listOfAllPossibleActions = ReOrderActions(listOfAllPossibleActions); foreach (Action action in listOfAllPossibleActions) { if (action is RocketPress) { //if (((RopeCut)action).RopeId == 2 || ((RopeCut)action).RopeId == 3) //{ int i = 231231231; //} } if (action is BubblePinch) { //if (((RopeCut)action).RopeId == 2 || ((RopeCut)action).RopeId == 3) //{ int i = 231231231; //} } this.Simulator.ActionsFrequency = GetActionsFrequency(action); if (!isPlayable) { nodesExplored++; StaticData.EngineManager = ObjectSerializer.DeepCopy(engineManager); performedActions.Add(action); velocitesInActions.Add(StaticData.EngineManager.CookieRB.GetVelocity()); isPlayable = SimulatePlayabilityForPartialAction(new List <Action>() { action }); if (IsShowWindow) { EngineShotsManager.ShowXNAWindow(); } double newBest = Simulator.ClosestCookieFrogDistance; if (newBest < bestClosestFrogCookieDist) { bestClosestFrogCookieDist = newBest; bestPerformedActions = new List <Action>(); bestPerformedActions.AddRange(performedActions); bestPerformedActionsVelocities = new List <Vector3>(); bestPerformedActionsVelocities.AddRange(velocitesInActions); } ActionNode childNode = null; if (node != null) { childNode = node.Childs.Where(cNode => cNode.Action == action).First(); } SimulatePlayability(childNode, StaticData.EngineManager, ref isPlayable, nrOfActionSoFar, performedActions, velocitesInActions, voidInitPlayCount, checkMode); if (!isPlayable) { if (performedActions.Count > 0) { performedActions.RemoveAt(performedActions.Count - 1); } if (velocitesInActions.Count > 0) { velocitesInActions.RemoveAt(velocitesInActions.Count - 1); } } } else { return; } } } else { StaticData.EngineManager = ObjectSerializer.DeepCopy(engineManager); isPlayable = SimulatePlayabilityForNoCurrentAction(RunFreelyToRestFreq); return; } } } else { return; } } catch (Exception e) { MessageBox.Show("In Simulate " + e.ToString()); } }