//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()); } }
public static void ExtractComponentToActionExperiment() { string path = "100 Playability PPr.txt"; StreamReader sr = new StreamReader(path); StreamWriter sw = new StreamWriter("ComponentToActionExperiment.txt"); string line = String.Empty; while ((line = sr.ReadLine()) != null) { String levelStr = line.Split('\t')[12]; String actionsStr = line.Split('\t')[13]; LevelBuilder.CreateRestedLevel(levelStr, false); StaticData.GameSessionMode = SessionMode.PlayingMode; ActionsExecuterGenSim.ListOfActions = new ActionsGenerator(actionsStr).Actions; ActionsExecuterGenSim.IsSimulatingGamePlayability = true; ActionsExecuterGenSim.nextActionIndex = 0; ActionsExecuterGenSim.isFinished = false; ActionsExecuterGenSim.IsSaveStateToFile = false; if (false) { EngineShotsManager.ShowXNAWindow(); } var gameTime = new GameTime(); for (int i = 0; i < 1300; i++) { ActionsExecuterGenSim.ManipulateActions(gameTime); StaticData.EngineManager.Update(gameTime); } List <Component> items = new LevelGenerator(levelStr).Items; items.RemoveAt(0); items.RemoveAt(0); List <Action> actions = ActionsExecuterGenSim.ListOfActions; int nrOfNonVoids = actions.FindAll(a => !(a is VoidAction)).Count; actions = actions.FindAll(a => !(a is VoidAction)).ToList(); RyseUsageManager usageManager = new RyseUsageManager(items, actions); StaticData.RyseComponentsUsageHelper = usageManager; usageManager.DoAnalysis(); int nrOfBumps = items.FindAll(item => (item is Bump)).Count; int nrOfRockets = items.FindAll(item => (item is Rocket)).Count; int nrOfRopes = items.FindAll(item => (item is Rope)).Count; int nrOfBubbles = items.FindAll(item => (item is Bubble)).Count; int nrOfBlowers = items.FindAll(item => (item is Blower)).Count; int nrOfUsedComps = usageManager.UsedRopes + usageManager.UsedRocket + usageManager.UsedBlowers + usageManager.UsedBubbles + usageManager.UsedBumps; int nrONonfUsedComps = items.Count - nrOfUsedComps; double actionsToComponentsRatio = (nrOfUsedComps) / (double)items.Count; sw.WriteLine(items.Count + "\t" + (nrOfNonVoids + usageManager.UsedBumps) + "\t" + nrOfUsedComps + "\t" + nrONonfUsedComps + "\t" + actionsToComponentsRatio + "\t" + usageManager.UsedRopes + "\t" + usageManager.UsedRocket + "\t" + usageManager.UsedBlowers + "\t" + usageManager.UsedBubbles + "\t" + usageManager.UsedBumps + "\t" + nrOfRopes + "\t" + nrOfRockets + "\t" + nrOfBlowers + "\t" + nrOfBubbles + "\t" + nrOfBumps + "\t" + usageManager.UsedRopes / (double)nrOfRopes + "\t" + usageManager.UsedRocket / (double)nrOfRockets + "\t" + usageManager.UsedBlowers / (double)nrOfBlowers + "\t" + usageManager.UsedBubbles / (double)nrOfBubbles + "\t" + usageManager.UsedBumps / (double)nrOfBumps); sw.Flush(); } sr.Close(); }