public static void SaveEngineState() { if (StaticData.GameSessionMode != SessionMode.PlayingMode) { StaticData.SetEngineManagerLastLevel(ObjectSerializer.DeepCopy(StaticData.EngineManager)); } }
private void bPlayThisLevel_Click(object sender, EventArgs e) { if (StaticData.GameSessionMode != SessionMode.PlayingMode) { StaticData.SetEngineManagerLastLevel(ObjectSerializer.DeepCopy(StaticData.EngineManager)); StaticData.GameSessionMode = SessionMode.PlayingMode; StaticData.ManipulationGameMode = ManipulationGameMode.NeutralMode; } }
private void bLoadLastDesign_Click(object sender, EventArgs e) { if (StaticData.GetEngineManagerLastLevel() != null) { Game1 game1 = StaticData.EngineManager.Game1; StaticData.EngineManager = ObjectSerializer.DeepCopy(StaticData.GetEngineManagerLastLevel()); StaticData.EngineManager.Game1 = game1; StaticData.GameSessionMode = SessionMode.DesignMode; } }
public void AddNewMass() { if (this.Length < StaticData.MaxRopeLength) { RigidBody newRigid = ObjectSerializer.DeepCopy(this.Masses[1]); newRigid.PositionXNA = this.Masses[0].PositionXNA + new Vector3(0, 5, 0); StaticData.EngineManager.RigidsManagerEngine.AddRigidBody(newRigid); this.Masses.Insert(1, newRigid); var oldMass2 = this.Springs[0].Mass2; this.Springs[0].Mass2 = newRigid; this.Springs.Insert(1, new Spring(newRigid, oldMass2, this.Springs[0].SpringConstant, this.Springs[0].SpringLength, this.Springs[0].FrictionConstant)); } }
public static string TestObjectSerializer(ScreenManager screenMan, out int errorsAdded) { int num = 0; string str = ""; List <string> stringList1 = new List <string>(); List <string> stringList2 = (List <string>)ObjectSerializer.DeserializeObject(Utils.GenerateStreamFromString(ObjectSerializer.SerializeObject((object)stringList1)), stringList1.GetType()); if (stringList2 == null || stringList2.Count != 0) { ++num; str += "\nError deserializing empty list"; } stringList1.Add("test 1"); stringList1.Add("12345"); List <string> stringList3 = (List <string>)ObjectSerializer.DeepCopy((object)stringList1); if (stringList3.Count != 2 || stringList3[0] != "test 1" || stringList3[1] != "12345") { ++num; str += "\nError deserializing empty list"; } VehicleRegistration self = new VehicleRegistration() { licenceNumber = "1123-123", licencePlate = "11-11", vehicle = new VehicleType() { maker = "asdf", model = "another asdf" } }; VehicleRegistration to = (VehicleRegistration)ObjectSerializer.DeepCopy((object)self); if (!Utils.PublicInstancePropertiesEqual <VehicleRegistration>(self, to)) { ++num; str += "\nError auto deserializing vehicle info\n"; } errorsAdded = num; return(str); }
public static void WatchLivePlayabilityFromLevelsActionsFilesAllCompsForDesigner(int levelNr) { string path = @"C:\CTREngine\100 Playability PPr.txt"; StreamReader sr = new StreamReader(path); string line = String.Empty; int counter = 0; while ((line = sr.ReadLine()) != null) { if (counter == levelNr) { DesignEnhanceManager.GevaLevel = line.Split('\t')[12]; DesignEnhanceManager.PlayabilityActions = line.Split('\t')[13]; LevelBuilder.CreateRestedLevel(DesignEnhanceManager.GevaLevel, false); RyseAgent agent = new RyseAgent(10); agent.IsSaveImage = false; StaticData.SetEngineManagerLastLevel(ObjectSerializer.DeepCopy(StaticData.EngineManager)); break; } counter++; } sr.Close(); }
//"cookie( 300 , 120 ) frog( 360 , 300 ) rope( 550 , 50 , 100 ) rope( 440 , 50 , 180 ) blower( 490 , 180 , 4 )"; //"cookie(405, 130) frog(320, 70) rope(0, 326, 116, 100) rope(1, 705, 149, 180) rocket(672, 351, 5) bump(300, 150, 1) bump(300, 200, 1) bump(300, 250, 1) bump(300, 300, 1)"; //"cookie(405, 130) frog(400, 418) rope(0, 326, 116, 100) rope(1, 705, 149, 180) bubble(7, 672, 351) rocket(720, 60, 3) bump(300, 150, 1) bump(300, 200, 1) bump(300, 250, 1) bump(300, 300, 1)"; //"cookie(405, 130) frog(450, 450) rope(1, 705, 149, 180) rocket(672, 351, 5) bump(300, 150, 1) bump(300, 200, 1) bump(300, 250, 1) bump(300, 300, 1)"; //"cookie(471, 99) frog(336, 426) rope(0, 315, 44, 60) rope(1, 455, 43, 100) rope(2, 690, 31, 170) blower(680, 400, 4) bubble(0, 600, 320) rocket(458, 262, 3) bump(715, 165, 2) bump(714, 236, 2) bump(475, 206, 0) bump(409, 207, 0) bump(339, 207, 0) bump(502, 381, 5) bump(526, 442, 2) bump(526, 520, 2)"; //"cookie(471, 99) frog(336, 426) rope(2, 620, 31, 170) blower(650, 400, 4) bubble(0, 600, 320) rocket(458, 262, 3) bump(715, 165, 2) bump(714, 236, 2) bump(475, 206, 0) bump(409, 207, 0) bump(339, 207, 0) bump(502, 381, 5) bump(526, 442, 2) bump(526, 520, 2)"; //"cookie(471, 99) frog(336, 426) rope(2, 620, 31, 170) blower(650, 350, 4) bubble(0, 600, 320) rocket(458, 262, 3) bump(715, 165, 2) bump(714, 236, 2) bump(475, 206, 0) bump(409, 207, 0) bump(339, 207, 0) bump(502, 381, 5) bump(526, 442, 2) bump(526, 500, 2)"; //"cookie(700, 239) frog(356, 408) rope(0, 706, 103, 180) blower(746, 232, 4) bubble(0, 597, 240) rocket(600, 64, 3) bump(536, 210, 2) bump(536, 270, 2) bump(536, 339, 2) bump(537, 408, 2) bump(537, 478, 2) "; public static void GenerateLevelTesting() { LevelBuilder.CreateRestedLevel(StrLevelTesting, false); String str = EngineStateManager.GetEngineStateFactStringWithEnterDelimiterToProlog(); bool IsDesign = false; bool isSaveToFile = true; if (!IsDesign) { ActionsExecuterGenSim.IsSaveStateToFile = true; RyseAgent agent = new RyseAgent(0); agent.IsSaveImage = false; agent.Simulator = new PlayabilitySimulatorEngineProlog(agent.IsSaveImage); bool playability = false; List <Action> performedActions = new List <Action>(); List <Vector3> performedVel = new List <Vector3>(); EngineManager engine = ObjectSerializer.DeepCopy(StaticData.EngineManager); DateTime d1 = DateTime.Now; ActionNode baseNode = new ActionNode(null); agent.SimulatePlayability(baseNode, StaticData.EngineManager, ref playability, 0, performedActions, performedVel, 0, PlayabilityCheckMode.NormalCheck); DateTime d2 = DateTime.Now; agent.totalTime = (int)(d2 - d1).TotalSeconds; int avgLevels = 0; if (agent.NrOfTerminates > 0) { avgLevels = (int)(agent.TerminateLevelSum / agent.NrOfTerminates); } int nrOfNonVoids = agent.bestPerformedActions.FindAll(delegate(Action a) { return(!(a is VoidAction)); }).Count; //FilesHelperModule.PrintTreeToFile(baseNode); MessageBox.Show("The level is " + (playability ? "PLAYABLE" : "NOT PLAYABLE") + Environment.NewLine + "Finished processing in = " + agent.totalTime.ToString() + " sec." + Environment.NewLine + "Nodes explored = " + agent.nodesExplored + Environment.NewLine + "Nr of tree cuts = " + agent.NrOfTerminates + Environment.NewLine + "Average tree depth cut = " + avgLevels + Environment.NewLine + "Solution tree depth = " + agent.bestPerformedActions.Count + Environment.NewLine + "Best distance = " + agent.Simulator.ClosestCookieFrogDistance + Environment.NewLine + "Best Performed Actions are = " + HelperModules.GenericHelperModule.GetActionsString(agent.bestPerformedActions) + Environment.NewLine); if (isSaveToFile) { string strFile = "0" + "\t" + playability + "\t" + agent.prologTime / 1000 + "\t" + agent.totalTime + "\t" + String.Format("{0:0.00}", agent.bestClosestFrogCookieDist) + "\t" + agent.maxDepthArr + "\t" + agent.NrOfTerminates + "\t" + avgLevels + "\t" + agent.NrLevelterminatesStdMin + "\t" + agent.NrLevelterminatesStdMax + "\t" + agent.nodesExplored + "\t" + agent.bestPerformedActions.Count + "\t" + nrOfNonVoids + "\t" + StrLevelTesting + "\t" + HelperModules.GenericHelperModule.GetActionsString(agent.bestPerformedActions) + "\t" + HelperModules.GenericHelperModule.GetVector3ListString(performedVel); StreamWriter sw = new StreamWriter(@"C:\CTREngine\LevelsTestTemp.txt"); sw.WriteLine(strFile); sw.Flush(); sw.Close(); } StaticData.GameSessionMode = SessionMode.PlayingMode; if (!IsDesign) { if (playability) { LivePlayabilitySimulator liveSim = new LivePlayabilitySimulator(engine); liveSim.SimulateNewWindow(performedActions); } } } }
public static void GenerateGevaLevelRandPlayabilityFF(String[] args, bool isPrintPositionOnly, bool isSaveImage, int voidInitPlayTotalCount) { StaticData.EngineManager = null; LevelBuilder.CreateRestedLevel(args[1], true); RyseAgent agent = new RyseAgent(voidInitPlayTotalCount); agent.IsPrintPositionOnly = isPrintPositionOnly; agent.IsSaveImage = isSaveImage; agent.Simulator = new PlayabilitySimulatorEngineProlog(isSaveImage); bool playability = false; EngineManager engine = ObjectSerializer.DeepCopy(StaticData.EngineManager); DateTime d1 = DateTime.Now; List <Action> performedActions = new List <Action>(); List <Vector3> performedVel = new List <Vector3>(); double closestDistSoFar = Double.MaxValue; for (int j = 0; j < 10; j++) { if (!playability) { performedActions = new List <Action>(); StaticData.EngineManager = engine; ActionNode node = new ActionNode(new VoidAction()); agent.SimulatePlayability(node, StaticData.EngineManager, ref playability, 0, performedActions, performedVel, 0, PlayabilityCheckMode.RandomCheck); if (agent.bestClosestFrogCookieDist < closestDistSoFar) { closestDistSoFar = agent.bestClosestFrogCookieDist; } if (performedActions.Count <= 3) { closestDistSoFar = 70; break; } } else { break; } } DateTime d2 = DateTime.Now; agent.totalTime = (int)((d2 - d1).TotalMilliseconds); StreamWriter swGEVA = new StreamWriter(@"C:\CTREngine\PlayabilityVal_ZGTREngine.txt"); swGEVA.WriteLine(closestDistSoFar); swGEVA.Close(); int avgLevels = 0; if (agent.NrOfTerminates > 0) { avgLevels = (int)(agent.TerminateLevelSum / agent.NrOfTerminates); } int nrOfNonVoids = agent.bestPerformedActions.FindAll(delegate(Action a) { return(!(a is VoidAction)); }).Count; String strFile = "1" + "\t" + playability + "\t" + agent.prologTime / 1000 + "\t" + agent.totalTime + "\t" + String.Format("{0:0.00}", agent.bestClosestFrogCookieDist) + "\t" + agent.maxDepthArr + "\t" + agent.NrOfTerminates + "\t" + avgLevels + "\t" + agent.NrLevelterminatesStdMin + "\t" + agent.NrLevelterminatesStdMax + "\t" + agent.nodesExplored + "\t" + agent.bestPerformedActions.Count + "\t" + nrOfNonVoids + "\t" + args[1] + "\t" + HelperModules.GenericHelperModule.GetActionsString(agent.bestPerformedActions) + "\t" + HelperModules.GenericHelperModule.GetVector3ListString(performedVel); if (closestDistSoFar <= 50) { StreamWriter sw = new StreamWriter(@"C:\CTREngine\PhysicsEngine_EvolvePlayActions.txt", true); sw.WriteLine(strFile); sw.Flush(); sw.Close(); } { StreamWriter sw = new StreamWriter(@"C:\CTREngine\PhysicsEngine_EvolvePlayActionsAllLevels.txt", true); sw.WriteLine(strFile); sw.Flush(); sw.Close(); } }
//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()); } }
private void PlaceNewComp(CompTimePair nextCTP) { CompsScatteredSoFar++; //Shotter.TakeEngineShot(); var fEngine = ObjectSerializer.DeepCopy(StaticData.EngineManager); for (int i = 0; i < 15; i++) { fEngine.Update(new GameTime()); } Vector2 cPossss = StaticData.EngineManager.CookieRB.PositionXNA2D; Vector2 cPos = fEngine.CookieRB.PositionXNA2D; //StaticData.EngineManager.CookieRB.PositionXNACenter2D; int cX = (int)cPos.X; int cY = (int)cPos.Y; Component cAdd = new Rope(0, 0, 100); Vector3 acc = StaticData.EngineManager.CookieRB.GetAcceleration(); switch (nextCTP.CType) { case ComponentType.Cookie: break; case ComponentType.Frog: cAdd = GetFrogPosition(); break; case ComponentType.Blower: cAdd = GetBlowerPosition(nextCTP); break; case ComponentType.Rope: break; case ComponentType.Bubble: cAdd = new Bubble(cX - (int)StaticData.BubbleDimBubble / 2, cY - (int)StaticData.BubbleDimBubble / 2); //GetBubblePosition(); break; case ComponentType.Water: break; case ComponentType.Rocket: int dirR = _rand.Next(8); cAdd = new Rocket(cX - (int)StaticData.RocketCarrierHalfSize.X, cY - (int)StaticData.RocketCarrierHalfSize.Y, (Direction)dirR); //GetRocketPosition(nextCTP); break; case ComponentType.Bump: int dirB = _rand.Next(3); dirB = dirB == 2 ? 3 : dirB; if (dirB == 1 || dirB == 3) { var fEngineB = ObjectSerializer.DeepCopy(StaticData.EngineManager); for (int i = 0; i < 25; i++) { fEngineB.Update(new GameTime()); } cPos = fEngine.CookieRB.PositionXNA2D; cX = (int)cPos.X; cY = (int)cPos.Y; } cAdd = new Bump(cX - (int)StaticData.BumpHalfSize.X, cY - (int)StaticData.BumpHalfSize.Y, (Direction)dirB); //cAdd = GetBumperPosition(nextCTP); break; case ComponentType.Cracker: break; default: throw new ArgumentOutOfRangeException(); } if (!(cAdd is Rope)) { cAdd.AddSelfToEngine(); LevelStr += cAdd.ToString(); } }