public String GetPrefCompsToGrammarFile()
        {
            String strFinalGrammar = String.Empty;
            String compLevelBase   = String.Empty;
            String compShouldPres  = String.Empty;
            String compAlreadyPres = EngineStateManager.GetEngineStateFactStringWithSpaceDelimiterGEVAStyle(_comps);
            int    compPresCounter = 0;

            if (!compAlreadyPres.Contains("frog"))
            {
                compShouldPres += "<frog>";
            }
            if (!compAlreadyPres.Contains("rope"))
            {
                compShouldPres += "<rope>";
                compPresCounter++;
            }
            if (!compAlreadyPres.Contains("blower"))
            {
                compShouldPres += "<blower>";
                compPresCounter++;
            }
            if (!compAlreadyPres.Contains("rocket"))
            {
                compShouldPres += "<rocket>";
                compPresCounter++;
            }
            if (!compAlreadyPres.Contains("bump"))
            {
                compShouldPres += "<bump>";
                compPresCounter++;
            }
            if (!compAlreadyPres.Contains("bubble"))
            {
                compShouldPres += "<bubble>";
                compPresCounter++;
            }


            if (compPresCounter < 5)
            {
                compLevelBase = "<level>::=<cookie><comps_design><comps>";
            }
            else
            {
                compLevelBase = "<level>::=<cookie><comps_design>";
            }

            strFinalGrammar  = compLevelBase;
            strFinalGrammar += Environment.NewLine
                               +
                               @"<cookie>::=cookie(<x>,<y>)
<frog>::=frog(<x>,<y>)
<comps_design>::="
                               + compAlreadyPres + compShouldPres;

            strFinalGrammar += Environment.NewLine
                               + GrammarRest;
            return(strFinalGrammar);
        }
        private void bSaveLevel_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StreamWriter sw = new StreamWriter(dialog.FileName, true);
                sw.WriteLine(EngineStateManager.GetEngineStateFactStringWithSpaceDelimiterGEVAStyle());
                sw.Close();
            }
        }
Exemple #3
0
        //public static RYSEManager SimulatePlayabiltityFromDesigner(bool isSaveImage)
        //{
        //    RYSEManager manager = new RYSEManager(10);
        //    manager.IsSaveImage = isSaveImage;
        //    manager.Simulator = new PlayabilitySimulatorEngineProlog(manager.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 node = new ActionNode(new VoidAction());
        //    manager.SimulatePlayability(node, StaticData.EngineManager, ref playability, 0, performedActions, performedVel, 0, PlayabilityCheckMode.NormalCheck);
        //    DateTime d2 = DateTime.Now;
        //    manager.totalTime = (int)(d2 - d1).TotalSeconds;
        //    //if (playability == true)
        //    //{
        //    //    MessageBox.Show("Playable! " + this.Simulator.ClosestCookieFrogDistance);
        //    //}
        //    if (playability)
        //    {
        //        MessageBox.Show("The level is Playable!" + Environment.NewLine
        //                        + "Finished processing in = " + manager.totalTime.ToString() + " sec." + Environment.NewLine
        //                        + "Nodes explored = " + manager.nodesExplored + Environment.NewLine
        //                        + "Nr of tree cuts = " + manager.NrOfTerminates + Environment.NewLine
        //                        + "Solution tree depth = " + performedActions.Count + Environment.NewLine
        //                        + "Best distance = " + manager.Simulator.ClosestCookieFrogDistance);
        //        LivePlayabilitySimulator liveSim = new LivePlayabilitySimulator(engine);
        //        liveSim.SimulateSameWindow(performedActions);
        //    }
        //    else
        //    {
        //        MessageBox.Show(@"Can't find a solution for this level.");
        //    }
        //    //StaticData.EngineManager.Game1 = DesignerManager.Game;
        //    return manager;
        //}


        //public static RYSEManager SimulatePlayabiltityFromDesigner(bool isSaveImage)
        //{
        //    String gevaStr = EngineStateManager.GetEngineStateFactStringWithSpaceDelimiterGEVAStyle();
        //    //LevelBuilder.CreateRestedLevel(gevaStr, false);
        //    RYSEManager manager = new RYSEManager(10);
        //    manager.Simulator = new PlayabilitySimulatorEngineProlog(false);
        //    manager.IsSaveImage = false;
        //    StaticData.GameSessionMode = SessionMode.PlayingMode;

        //    bool playability = false;
        //    List<Action> performedActions = new List<Action>();
        //    List<Vector3> performedVel = new List<Vector3>();
        //    DateTime d1 = DateTime.Now;
        //    ActionNode baseNode = new ActionNode(new VoidAction());
        //    manager.SimulatePlayability(baseNode, StaticData.EngineManager, ref playability, 0, performedActions, performedVel, 0, PlayabilityCheckMode.NormalCheck);
        //    DateTime d2 = DateTime.Now;
        //    manager.totalTime = (int)(d2 - d1).TotalSeconds;
        //    FilesHelperModule.PrintTreeToFile(baseNode);
        //    FilesHelperModule.DeepCopyTreeToFile(baseNode);
        //    if (playability)
        //    {
        //        MessageBox.Show("The level is Playable!" + Environment.NewLine
        //                        + "Finished processing in = " + manager.totalTime.ToString() + " sec." + Environment.NewLine
        //                        + "Nodes explored = " + manager.nodesExplored + Environment.NewLine
        //                        + "Nr of tree cuts = " + manager.NrOfTerminates + Environment.NewLine
        //                        + "Solution tree depth = " + performedActions.Count + Environment.NewLine
        //                        + "Best distance = " + manager.Simulator.ClosestCookieFrogDistance);

        //        StaticData.EngineManager.Game1 = DesignerManager.Game;
        //        LevelBuilder.CreateRestedLevel(gevaStr, false);
        //        FilesHelperModule.PrintTreeToFile(baseNode, StaticData.EngineManager, performedActions);
        //        StaticData.GameSessionMode = SessionMode.PlayingMode;
        //        LivePlayabilitySimulator simulator = new LivePlayabilitySimulator(StaticData.EngineManager);
        //        simulator.SimulateSameWindow(performedActions);
        //    }
        //    else
        //    {
        //        MessageBox.Show(@"Can't find a solution for this level.");
        //    }
        //    StaticData.EngineManager.Game1 = DesignerManager.Game;
        //    return manager;
        //}

        public static void SimulatePlayabiltityFromDesigner()
        {
            var          strGeva = EngineStateManager.GetEngineStateFactStringWithSpaceDelimiterGEVAStyle();
            StreamWriter sw      = new StreamWriter(@"C:\CTREngine\LevelToPlayCheckDesigner.txt");

            sw.WriteLine(strGeva);
            sw.Close();
            //System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo();
            //proc.FileName = @"C:\CTREngine\CRUSTEngine_PlayabilityChecker.exe";
            //proc.Arguments = "0" + " " + @strGeva;
            //proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            //System.Diagnostics.Process.Start(proc);


            var process = new Process();

            process.EnableRaisingEvents       = false;
            process.StartInfo.FileName        = @"C:\CTREngine\CRUSTEngine_PlayabilityChecker_ToDesigner.exe";
            process.StartInfo.Arguments       = "";
            process.StartInfo.CreateNoWindow  = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            process.WaitForExit();
            process.Close();

            StreamReader sr =
                new StreamReader(@"C:\CTREngine\PhysicsEngine_EvolvePlayActions.txt");
            String line = sr.ReadToEnd();

            DesignEnhanceManager.GevaLevel          = line.Split('\t')[13];
            DesignEnhanceManager.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.");
            }
            else
            {
                MessageBox.Show(
                    @"Playability-check is finished. The engine hasn't found a playable level.");
            }
            sr.Close();
        }