public AgentAlreadyExistsException(Agent agent, Agent otheragent)
     : base("Attempted to add agent of type " + agent.GetType().Name + ", but another agent of type "+otheragent.GetType().Name+". Already has the name: "+agent.Name)
 {
     this.agent = agent;
     this.otheragent = otheragent;
     this.name = agent.Name;
 }
Пример #2
0
        //[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));
        }
        public HumanInterfaceController(Agent agent, KeyboardSettings settings)
            : base(agent)
        {
            this.settings = settings;

            this.actionMap.Add(settings.MoveUp(),new MoveUnitAction(new Vector(0,1)));
            this.actionMap.Add(settings.MoveDown(),new MoveUnitAction(new Vector(0,-1)));
            this.actionMap.Add(settings.MoveRight(),new MoveUnitAction(new Vector(1,0)));
            this.actionMap.Add(settings.MoveLeft(),new MoveUnitAction(new Vector(-1,0)));

            this.currentAction = this.actionMap[this.settings.MoveUp()];
        }
Пример #4
0
        public EISAgentController(Agent agent, TcpClient client, ActionManager actman, PacketStream packetstream, StreamReader sreader, StreamWriter swriter, EisConversionTool tool,
		                          IILActionParser actionparser)
            : base(agent)
        {
            this.client = client;
            this.packetstream = packetstream;
            this.sreader = sreader;
            this.swriter = swriter;
            PerceptsRecieved += EISAgentController_PerceptsRecieved;
            this.tool = tool;
            this.actionparser = actionparser;
            this.actman = actman;
        }
Пример #5
0
        protected override Func<KeyValuePair<string, AgentController>> AquireAgentControllerContructor()
        {
            TcpClient client = listener.AcceptTcpClient();
            string agentName = agentid + "";
            agentid++;
            Func<KeyValuePair<string, AgentController>> func = () =>
            {

                Agent agent = new Agent(agentName);
                XmlReader reader = XmlReader.Create(client.GetStream(),new XmlReaderSettings(){ConformanceLevel=ConformanceLevel.Fragment});
                XmlWriter writer = XmlWriter.Create(client.GetStream(),new XmlWriterSettings(){ConformanceLevel = System.Xml.ConformanceLevel.Fragment});
                XmlPacketTransmitter<IilAction, IilPerceptCollection> transmitter = new XmlPacketTransmitter<IilAction, IilPerceptCollection>(reader, writer);
                AgentConnection connection = new AgentConnection(agent,transmitter);
                this.ActionManager.Queue(new AddStandbyAgentAction(agent));
                return new KeyValuePair<string,AgentController>(agentName, connection);
            };
            return func;
        }
Пример #6
0
 /// <summary>
 /// Attempts to locate an agent through a certain name
 /// </summary>
 /// <param name="name">The name of the agent</param>
 /// <param name="agent">The agent that is being located</param>
 /// <returns>Whether or not the agent could be located</returns>
 public bool TryGetAgent(string name, out Agent agent)
 {
     return this.agentLookup.TryGetValue(name, out agent);
 }
 public AgentHasNoNameException(Agent agent)
     : base("Attempted to add agent of type " + agent.GetType().Name + ", without a name")
 {
     this.agent = agent;
 }
Пример #8
0
 public VacuumAgentController(Agent agent)
     : base(agent)
 {
     this.PerceptsRecieved += agent_perceptRecieved;
 }
Пример #9
0
 /// <summary>
 /// Constructs the AgentController
 /// </summary>
 /// <param name="agent">Name of the agent the controller is meant to control</param>
 public AgentController(Agent agent)
 {
     this.agent = agent;
     agent.Register(new Trigger<RetreivePerceptsEvent>(agent_RetrievePercepts));
 }
 public EisAgentDisconnectedEvent(Agent agent, Exception exception)
 {
     this.agent = agent;
     this.exception = exception;
 }
Пример #11
0
 public AgentConnection(Agent agent, XmlPacketTransmitter<IilAction, IilPerceptCollection> transmitter)
     : base(agent)
 {
     this.transmitter = transmitter;
     evtman.AddEventQueue(agent.ConstructEventQueue());
 }
Пример #12
0
 public AddStandbyAgentAction(Agent agent)
 {
     this.agent = agent;
 }
Пример #13
0
 public EisAgentTimingEvent(Agent agent, string description, TimeSpan timespan)
 {
     this.agent = agent;
     this.description = description;
     this.timespan = timespan;
 }
Пример #14
0
 public void AddAgent(Agent agent)
 {
     this.agents.Enqueue(agent);
 }