//[Test]
        public void SingleUpdate_RecievedGetAllPercepts_PickUpPerceptsAndReturnThemThroughWriter()
        {
            ActionManager manager = new ActionManager(new EventManager());
            TileWorldBuilder worldBuilder = new TileWorldBuilder(new Size(4, 4));

            Agent agent = new Agent("testagent");
            worldBuilder.AddEntity(() => agent, new TileSpawnInformation(new TilePosition(new Point(0, 0))));

            XmasFactory fact = new XmasFactory(manager);
            TileWorld world = (TileWorld)worldBuilder.Build();
            agent.ActionManager = manager;
            agent.World = world;
            agent.Factory = fact;

            Thread thread1 = new Thread(test2);
            thread1.Name = "TCP Server";
            thread1.Start();

            while (lock1)
            {
            }
            TcpClient client = new TcpClient("localhost", 6661);
            Stream stream = client.GetStream();

            StringBuilder sb = new StringBuilder();

            EisConversionTool ctool = new EisConversionTool();
            ctool.AddConverter(new GetAllPerceptsActionConverter());
            ctool.AddConverter(new EISPerceptCollectionSerializer());
            ctool.AddConverter(new EisTileVisionSerializer());
            ctool.AddConverter(new EISSingleNumeralSerializer());

            IILActionParser parser = new IILActionParser();

            XmlReaderSettings set = new XmlReaderSettings();
            set.ConformanceLevel = ConformanceLevel.Fragment;
            XmlReader xreader = XmlReader.Create(new StreamReader(stream, Encoding.UTF8));
            XmlWriterSettings wset = new XmlWriterSettings();
            wset.OmitXmlDeclaration = true;
            XmlWriter xwriter = XmlWriter.Create(sb, wset);
            controller = new EISAgentController(agent, client, manager, new PacketStream(stream), new StreamReader(stream), new StreamWriter(stream), ctool, parser);

            Thread thread2 = new Thread(test1);
            thread2.Name = "Controller";
            thread2.Start();

            while (manager.ExecuteActions() == 0) ;
            string returned = null;
            do
            {
                try
                {
                    returned = sb.ToString();
                }
                catch
                {
                }
            } while (String.IsNullOrEmpty(returned));
        }
Beispiel #2
0
        public XmasModel(XmasWorld world, ActionManager actman, EventManager evtman, XmasFactory factory)
        {
            World = world;
            ActionManager = actman;
            EventManager = evtman;
            Factory = factory;
            world.EventManager = evtman;

            EventManager.Register(new Trigger<EngineCloseEvent>(evtman_EngineClose));
            ActionManager.ActionQueuing += actman_ActionQueuing;
            ActionManager.ActionQueued += actman_ActionQueued;

            foreach (var action in ActionManager.QueuedActions)
            {
                this.AddActor(action);
            }
        }