Esempio n. 1
0
        public static List <Action> GetNextActionsSet(ref int voidInitPlayCount, PlayabilityCheckMode checkMode)
        {
            if (voidInitPlayCount < VoidInitPlayTotalCount)
            {
                voidInitPlayCount++;
                return(new List <Action>()
                {
                    new VoidAction()
                });
            }
            List <Action> listOfAllPossibleActions = null;

            switch (checkMode)
            {
            case PlayabilityCheckMode.NormalCheck:
                // Set Engine State Into Predicates File
                SetEngineStateIntoPredicatesFile();

                // Run Prolog
                GenericHelperModule.RunJavaProcess(_prologEnginePath);

                // Get new actions to test
                String fullPrologString = GetPrologActionsString();
                listOfAllPossibleActions = GetAllPossibleActions(fullPrologString);
                break;

            case PlayabilityCheckMode.RandomCheck:
                listOfAllPossibleActions = new List <Action>()
                {
                    RandomPlayabilityGenerator.GetNewRandomAction()
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("checkMode");
            }
            return(listOfAllPossibleActions);
        }
Esempio 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());
            }
        }