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);
        }
Exemplo n.º 2
0
        //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());
            }
        }