public double RunEngine(ActionsGenerator actionsGenerator)
        {
            GameTime gameTime        = new GameTime();
            bool     canExecuteMore  = true;
            bool     reachedFrog     = false;
            int      counterTime     = 1;
            bool     firstTimeInLoop = true;

            if (IsSaveImage)
            {
                ShotsManager.TakeEngineShot();
            }

            while (true)
            {
                if (!SetPlayability())
                {
                    DistancesList.Add((int)GetCookieFrogDistance());
                    CookiePosList.Add(StaticData.EngineManager.CookieRB.PositionXNA.ToString());
                    if (firstTimeInLoop)
                    {
                        if (actionsGenerator.Actions.Count > 0)
                        {
                            //CookiePosList.Add(
                            //    actionsGenerator.Actions[actionsGenerator.currentActionIndex].AType.ToString());
                            canExecuteMore = actionsGenerator.ExecuteNextActions();
                            counterTime    = 1;
                            //if(actionsGenerator.Actions[0] is VoidAction)
                            //{
                            //    counterTime = 10000;
                            //}
                            if (IsSaveImage)
                            {
                                ShotsManager.TakeEngineShot();
                            }
                        }
                        firstTimeInLoop = false;
                    }
                    if (counterTime <= ActionsFrequency)
                    {
                        StaticData.EngineManager.Update(gameTime);
                    }
                    else
                    {
                        break;
                    }
                    counterTime++;
                }
                else
                {
                    if (IsSaveImage)
                    {
                        ShotsManager.TakeEngineShot();
                    }
                    break;
                }
            }
            return(ClosestCookieFrogDistance);
        }
        private void Init()
        {
            CompsScatteredSoFar  = 0;
            OverlappedComponents = 0;
            UpdateActionsIds     = new List <UpdateActionPair>();
            //CookieFrogMinDist = Int32.MaxValue;
            ActionsSoFar     = 0;
            _rand            = new Random(DateTime.Now.Millisecond);
            _placedCompSoFar = new List <Vector2>();
            //this.CATPairs[3].KeyTime = 412;
            //CATPairs[2].KeyTime = 367;
            IsPathIntersection = false;
            _ropeId            = 0;
            _bubbleId          = 0;
            IsSuccess          = false;
            Simulator          = new PlayabilitySimulatorEngineProlog(false);
            Actions            = new List <Action>();

            _rand = new Random(DateTime.Now.Millisecond);
            InitializeRanges();
            _nextCTP = CATPairs[0];

            String[] args = new String[2];

            String ropesStr = String.Empty;

            if (_isRopesRandomized)
            {
                ropesStr = GenerateRopesString();
            }
            else
            {
                ropesStr = GenerateRopesStringFromCatPairs();
            }

            LevelStr = "cookie(200, 300)" + ropesStr;
            args[1]  = LevelStr;

            LevelBuilder.CreateRestedLevel(LevelStr, false);
            AddCandyPlacement();
            if (IsTesting)
            {
                Shotter.TakeEngineShot(false);
            }
        }
Beispiel #3
0
 public static void GenerateGevaLevel(String[] args, String imageName = null)
 {
     LevelBuilder.CreateRestedLevelForLevelsShots(args[1], false);
     if (imageName != null)
     {
         EngineShotsManager shotsManager = new EngineShotsManager();
         shotsManager.TakeEngineShot(imageName);
     }
 }
Beispiel #4
0
        public static void GenerateGevaLevel(String[] args, bool isPrintPositionOnly, bool isSaveImage)
        {
            LevelBuilder.CreateRestedLevelForLevelsShots(args[1], isPrintPositionOnly);
            if (isSaveImage)
            {
                EngineShotsManager shotsManager = new EngineShotsManager();
                shotsManager.TakeEngineShot();
            }

            if (isPrintPositionOnly)
            {
                string       pos = EngineStateManager.GetEngineStatePositionsOnlyFactString();
                StreamWriter sw  = new StreamWriter("PhysicsEngine_PositionsOnly.txt", true);
                sw.WriteLine(pos);
                sw.Flush();
                sw.Close();
            }
        }
Beispiel #5
0
        public static void SetFitnessValueForLevelTest(String[] args, int counter)
        {
            GenManager.GenerateGevaLevel(args, null);
            String levelStr = args[1];
            bool   isShortestPathOnlyComparsion = args[2] != "0";

            DateTime         d1 = DateTime.Now;
            EntraAgentSimple entraAgentSimple = new EntraAgentSimple();
            var res = entraAgentSimple.CheckPlayability(StaticData.EngineManager);

            DateTime d2               = DateTime.Now;
            int      fitness          = Int32.MaxValue;
            int      usedNoRopes      = -1;
            int      generatedNoRopes = -1;
            float    usageFit         = -1;

            if (res.IsPlayable)
            {
                EntraPathAgent pathAgent = new EntraPathAgent(entraAgentSimple);
                GetFitnessUsage(pathAgent.AllPaths, levelStr, isShortestPathOnlyComparsion, out usedNoRopes,
                                out generatedNoRopes, out usageFit);
                fitness = (int)(40 * 0 + 60 * usageFit);

                EngineShotsManager shots = new EngineShotsManager();
                shots.TakeEngineShot(StaticData.EntraImageInput);
                pathAgent.DrawShortestPath(counter);
            }
            else
            {
                fitness = (int)(40 * MathHelperModule.Normalize((int)res.MinDistToFrog, 300, 50) + 60);
            }

            DateTime d3 = DateTime.Now;

            StreamWriter sw = new StreamWriter(@"PolysTesting\test.txt", true);

            sw.WriteLine(res.IsPlayable + "\t"
                         + fitness + "\t"
                         + usedNoRopes + "\t"
                         + generatedNoRopes + "\t"
                         + String.Format("{0:0.00}", usageFit));
            sw.Close();
            //PrintDataToFiles(d1, d2, d3, res, fitness, args);
        }
Beispiel #6
0
        public static void ManipulateActions(GameTime gameTime)
        {
            if (IsSimulatingGamePlayability)
            {
                if (ListOfActions != null)
                {
                    if (ActionsNotifManager != null)
                    {
                        ActionsNotifManager.Update(gameTime);
                    }
                    if (!isFinished)
                    {
                        //if (!waitForNextAction)
                        {
                            if (IsSaveStateToFile)
                            {
                                FilesHelperModule.SaveToStateFile(ListOfActions[nextActionIndex]);
                            }
                            Action currentAction = ListOfActions[nextActionIndex];
                            if (!(currentAction is VoidAction))
                            {
                                if (ActionsNotifManager != null)
                                {
                                    ActionsNotifManager.PushNextNotification();
                                }
                            }
                            if (IsSaveImage)
                            {
                                _shotsManager = _shotsManager ?? new EngineShotsManager();
                                _shotsManager.TakeEngineShot(false);
                            }

                            //if (!(currentAction is VoidAction))
                            //{
                            //    if (GenSimAgent.UpdateActionsIds.Count > actionId)
                            //    {
                            //        var res = GenSimAgent.UpdateActionsIds[actionId];
                            //        long uGen = res.UpdateId;
                            //        Action actionGen = res.Action;

                            //        long i = StaticData.UpdatesSoFar;
                            //        Action action = currentAction;
                            //    }
                            //}
                            actionId++;
                            CookiePosList.Add(StaticData.EngineManager.CookieRB.PositionXNA.ToString());
                            currentAction.ExcecuteAction();

                            if (RyseFreq)
                            {
                                actionFreq = RyseAgent.GetActionsFrequency(currentAction);
                            }
                            else
                            {
                                actionFreq = GenSimAgent.GetActionsFrequency(currentAction);
                            }
                            updateIdForNextAction = StaticData.UpdatesSoFar + actionFreq;
                            //waitForNextAction = true;
                        }
                        //else
                        //{
                        //if (StaticData.UpdatesSoFar == updateIdForNextAction)
                        {
                            //StaticData.UpdatesSoFar = 0;
                            //waitForNextAction = false;
                            if (nextActionIndex < ListOfActions.Count - 1)
                            {
                                nextActionIndex++;
                            }
                            else
                            {
                                isFinished = true;
                            }
                        }
                        //}
                    }
                    else
                    {
                        ActionsNotifManager = null;
                        //StaticData.EngineManager.Game1.TargetElapsedTime = TimeSpan.FromSeconds(1.0f/60.0f);
                    }
                }
            }
        }