private static void SimulateOnWindow(GenSimAgent agent)
        {
            LevelBuilder.CreateRestedLevel(agent.LevelStr, false);
            StaticData.GameSessionMode = SessionMode.PlayingMode;
            LivePlayabilitySimulator simulator = new LivePlayabilitySimulator(StaticData.EngineManager);

            simulator.SimulateNewWindow(agent.Actions, false, false);
        }
        private static void PrintToFile(String[] args, bool isGinSimComp,
                                        GenSimAgent agent, float fitness, DateTime d1, DateTime d2)
        {
            StreamWriter swGEVA = new StreamWriter(@"C:\CTREngine\PlayabilityVal_ZGTREngine.txt");

            swGEVA.WriteLine(fitness);
            swGEVA.Flush();
            swGEVA.Close();

            String playableFileName = isGinSimComp
                                          ? @"C:\CTREngine\GenSimCompLevelsPlayable.txt"
                                          : @"C:\CTREngine\GenSimLevelsPlayable.txt";

            String nonPlayableFileName = isGinSimComp
                                             ? @"C:\CTREngine\GenSimCompLevelsNonPlayable.txt"
                                             : @"C:\CTREngine\GenSimLevelsNonPlayable.txt";

            bool solved = false;

            if (agent.IsSuccess)
            {
                solved = true;
                StreamWriter swPlayLevelGeva = new StreamWriter(@"C:/CTREngine/GenSimPlayabilityLevel_ZGTREngine.txt");
                swPlayLevelGeva.WriteLine(agent.LevelStr);
                swPlayLevelGeva.Flush();
                swPlayLevelGeva.Close();
            }

            String strToFile = solved
                               + "\t" + agent.ActionsSoFar
                               + "\t" + agent.GetActionsToDo().Count
                               + "\t" + (d2 - d1).TotalMilliseconds
                               + "\t" + String.Format("{0:0.00}", fitness)
                               + "\t" + agent.LevelStr
                               + "\t" + args[1]
                               + "\t" + GenericHelperModule.GetActionsString(agent.Actions)
                               + "\t" + GenericHelperModule.GetCTPString(agent.BestCTPPairs, true)
                               + "\t" + GenericHelperModule.GetCTPString(agent.BestCTPPairs, false);

            if (agent.IsSuccess)
            {
                StreamWriter sw = new StreamWriter(playableFileName, true);
                sw.WriteLine(strToFile);
                sw.Flush();
                sw.Close();
            }
            else
            {
                StreamWriter sw2 = new StreamWriter(nonPlayableFileName, true);
                sw2.WriteLine(strToFile);
                sw2.Flush();
                sw2.Close();
            }
        }
        public static float GetFitness(GenSimAgent agent)
        {
            float fitness = 0;

            if (agent.IsSuccess)
            {
                fitness = 0;
            }
            else
            {
                float pIntersection = agent.IsPathIntersection ? 1 : 0;
                float pOverlapping  = MathHelperModule.Normalize(agent.CompsScatteredSoFar - 1,
                                                                 agent.GetAllComponents().Count, 0);
                float pEventsExec = 1 - MathHelperModule.Normalize(agent.ActionsSoFar, agent.GetActionsToDo().Count, 0);
                //fitness = (1 / (float)2) * pEventsExec +
                //          (1 / (float)2) * pIntersection;
                if (pIntersection == 1)
                {
                    fitness = 1;
                }
                else
                {
                    if (pEventsExec == 0)
                    {
                        if (pOverlapping == 0)
                        {
                            fitness = 0.1f;
                        }
                        else
                        {
                            fitness = pOverlapping;
                        }
                    }
                    else
                    {
                        fitness = pEventsExec;
                    }
                }
            }
            return(fitness);
        }
示例#4
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);
                    }
                }
            }
        }