示例#1
0
    // The recursive higher-order observation method as described in the thesis.
    // It has a height limiter to specify the desired max order of observation.
    public void UpdateToM(Subject s, Beliefs b, HashSet <Location> fov, int height)
    {
        if (height == 0 || b.Sees.Agents.Count == 0)
        {
            return;
        }

        foreach (KeyValuePair <char, Subject> kvp in b.Sees.Agents)
        {
            HashSet <Location> intersectFov = FOV.GetSharedFov(kvp.Value, s);

            VisionPercept vp = Sight.Perceive(kvp.Key, intersectFov);
            AudioPercept  ap = Hearing.Perceive(kvp.Key, kvp.Value.Location);

            if (!b.ToM.ContainsKey(kvp.Key))
            {
                b.ToM.Add(kvp.Key, new Beliefs());
            }

            b.ToM[kvp.Key].Update(vp);
            b.ToM[kvp.Key].Update(ap);

            UpdateToM(kvp.Value, b.ToM[kvp.Key], intersectFov, height - 1);
        }
    }
示例#2
0
    // Stores and returns the objects within the agents FOV in a percept.
    public static VisionPercept Perceive(char agtID, HashSet <Location> locs)
    {
        VisionPercept p = new VisionPercept
        {
            Locations = new HashSet <Location>(locs)
        };

        foreach (Location loc in locs)
        {
            foreach (char id in Manager.Board.Agents.Keys)
            {
                if (id == agtID)
                {
                    continue;
                }

                if (Util.AgentAt(id, loc))
                {
                    p.Agents[id] = new Subject(id, loc, Manager.Board.Agents[id].Direction);
                }
            }

            if (Util.ObstacleAt(loc))
            {
                p.Obstacles.Add(loc, new Obstacle(loc));
            }

            if (Util.FoodAt(loc))
            {
                p.Foods.Add(loc, new Food(loc));
            }
        }

        return(p);
    }
示例#3
0
文件: Beliefs.cs 项目: s162995/CtC
 public Beliefs()
 {
     Agents    = new Dictionary <char, Subject>();
     Obstacles = new Dictionary <Location, Obstacle>();
     Foods     = new Dictionary <Location, Food>();
     Rooms     = new Dictionary <char, Room>();
     Sees      = new VisionPercept();
     Hears     = new AudioPercept();
     ToM       = new Dictionary <char, Beliefs>();
 }
示例#4
0
文件: Agent.cs 项目: s162995/CtC
    // The agent generates audio and vision percept from the locations
    // within the agent's field of view.
    protected List <IPercept> Perceive()
    {
        HashSet <Location> fov = FOV.GetFov(Direction, Location);

        VisionPercept p  = Sight.Perceive(ID, fov);
        AudioPercept  p2 = Hearing.Perceive(ID, Location);

        Piece.DisplayFeature(fov.ToList(), Feature.Vision);
        Piece.DisplayFeature(fov.Intersect(Manager.Board.Obstacles.Keys).ToList(), Feature.Obstacle);
        Piece.DisplayFeature(fov.Intersect(Manager.Board.Foods.Keys).ToList(), Feature.Food);

        return(new List <IPercept>()
        {
            p, p2
        });
    }
示例#5
0
文件: Agent.cs 项目: s162995/CtC
    // The percepts are passed to the belief-revision function, which updates
    // the agent's beliefs.
    protected virtual Beliefs BRF(Beliefs b, List <IPercept> p)
    {
        VisionPercept vp = new VisionPercept();
        AudioPercept  ap = new AudioPercept();

        foreach (IPercept ip in p)
        {
            if (ip is VisionPercept)
            {
                vp = (VisionPercept)ip;
            }
            else
            {
                ap = (AudioPercept)ip;
            }
        }

        b.Update(vp);
        b.Update(ap);

        return(b);
    }
示例#6
0
文件: Beliefs.cs 项目: s162995/CtC
    // This method receives a vision percept which updates the
    // agent's beliefs about its surroundings.
    public void Update(VisionPercept vp)
    {
        Sees = vp;

        List <char> aIDs = new List <char>(vp.Agents.Keys);

        foreach (char id in aIDs)
        {
            Agents[id] = vp.Agents[id];
        }

        List <Location> fLocs = new List <Location>(vp.Foods.Keys);

        foreach (Location loc in fLocs)
        {
            Foods[loc] = vp.Foods[loc];
        }

        List <Location> oLocs = new List <Location>(vp.Obstacles.Keys);

        foreach (Location loc in oLocs)
        {
            Obstacles[loc] = vp.Obstacles[loc];
        }

        List <char> rIDs = new List <char>(Rooms.Keys);

        foreach (char id in rIDs)
        {
            Rooms[id].ExploreTiles(vp.Locations);

            if (Rooms[id].IsExplored())
            {
                Rooms.Remove(id);
            }
        }
    }