Example #1
0
 public bool isLegal(BoxList boxes)
 {
     bool[] tempmap = new bool[Map.wallMap.Length];
     for (int i = 0; i < actors.Length; i++)
     {
         if (tempmap[actors[i].y * Map.mapWidth + actors[i].x] == true)
         {
             return(false);
         }
         else
         {
             tempmap[actors[i].y * Map.mapWidth + actors[i].x] = true;
         }
     }
     for (int i = 0; i < boxes.boxes.Length; i++)
     {
         if (tempmap[boxes.boxes[i].y * Map.mapWidth + boxes.boxes[i].x] == true)
         {
             return(false);
         }
         else
         {
             tempmap[boxes.boxes[i].y * Map.mapWidth + boxes.boxes[i].x] = true;
         }
     }
     return(true);
 }
Example #2
0
File: Map.cs Project: neroes/AI-MAS
        public Map(bool[] newwallMap, int mapwidth, HashSet <Actor> newactors, Dictionary <Node, char> newboxes, GoalList newgoals, Dictionary <char, Color> colorDict)
        {
            id       = Map.nextId++;
            wallMap  = newwallMap;
            mapWidth = mapwidth;
            HashSet <Color> newactorcolors = new HashSet <Color>(); int i = 0;

            foreach (Actor a in newactors)
            {
                newactorcolors.Add(colorDict[i.ToString()[0]]);
                i++;
            }

            actors = new ActorList(newactors, newactorcolors);
            boxes  = new BoxList(newboxes, colorDict);
            goals  = newgoals;
            steps  = 0;

            /*
             * for (int j = 0; j<wallMap.Count(); j++)
             * {
             *  if (j%mapWidth == 0) { Console.Error.WriteLine(""); }
             *  if (isWall(j % mapWidth, j / mapwidth)) { Console.Error.Write("+"); }
             *  else { Console.Error.Write(" "); }
             * }*/
        }
Example #3
0
File: Map.cs Project: neroes/AI-MAS
 public Map(Map oldmap)
 {
     id     = Map.nextId++;
     parent = oldmap;
     actors = new ActorList(oldmap.actors);
     boxes  = new BoxList(oldmap.boxes);
     steps  = oldmap.steps + 1;
 }
Example #4
0
File: Map.cs Project: neroes/AI-MAS
        public int ManDistAct(BoxList boxlist)
        {
            int Actdist = 0;

            foreach (Color color in ActorList.intToColorDict)
            {
                Actdist += ManDistAct(boxlist, BoxList.boxColorGroups[color]);
            }
            return(Actdist);
        }
Example #5
0
        public int ManDist(BoxList boxlist)
        {
            int goaldist = 0;

            foreach (char name in names)
            {
                goaldist += goalgroups[name].ManDist(boxlist, BoxList.boxNameGroups[name]);
            }
            return(goaldist);
        }
Example #6
0
 public bool IsInGoal(BoxList boxlist)
 {
     foreach (char name in names)
     {
         if (!goalgroups[name].IsInGoal(boxlist, BoxList.boxNameGroups[name]))
         {
             return(false);
         }
     }
     return(true);
 }
Example #7
0
 public bool IsInGoal(BoxList boxlist, HashSet <int> boxes)
 {
     foreach (Node goal in goals)
     {
         bool res = false;
         foreach (int boxnumber in boxes)
         {
             if (boxlist[boxnumber] == goal)
             {
                 res = true; break;
             }
         }
         if (res == false)
         {
             return(false);
         }
     }
     return(true);
 }
Example #8
0
            public int ManDist(BoxList boxlist, HashSet <int> boxes) // Manhattan Distance
            {
                int totaldist = 0;

                foreach (Node goal in goals)
                {
                    int minDistToGoal = 1000000;
                    foreach (int boxnumber in boxes)
                    {
                        int dist = boxlist[boxnumber] - goal;
                        if (dist < minDistToGoal)
                        {
                            minDistToGoal = dist;
                        }
                    }
                    totaldist += minDistToGoal;
                }
                return(totaldist);
            }
Example #9
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null || !(obj is BoxList))
            {
                return(false);
            }
            BoxList bl = (BoxList)obj;

            for (int i = 0; i < boxes.Length; i++)
            {
                if (this.boxes[i] != bl.boxes[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Example #10
0
File: Map.cs Project: neroes/AI-MAS
        public int ManDistAct(BoxList boxlist, HashSet <int> boxes)//manhattendistance
        {
            int totaldist = 0;

            foreach (Actor actor in actors.getAllActors())
            {
                int minDistToActor = 1000000;
                foreach (int boxnumber in boxes)
                {
                    Node actorpos = new Node(actor.x, actor.y);
                    int  dist     = boxlist[boxnumber] - actorpos;
                    if (dist < minDistToActor)
                    {
                        minDistToActor = dist;
                    }
                    if (isGoal() == true)
                    {
                        minDistToActor = 0;
                    }
                }
                totaldist += minDistToActor;
            }
            return(totaldist);
        }
Example #11
0
        internal bool PerformActions(act[] actions, ref BoxList boxes)
        {
            bool[] activeboxlist = new bool[boxes.boxes.Length];
            for (int i = 0; i < actions.Count(); i++)
            {
                switch (actions[i].inter)
                {
                case Interact.MOVE:
                    actors[i] = new Actor(actors[i]);
                    Move(actors[i], actions[i].dir);
                    break;

                case Interact.PUSH:
                    actors[i] = new Actor(actors[i]);
                    Node pushbox = new Node(boxes[actions[i].box]);
                    Push(actors[i], ref pushbox, actions[i].dir, actions[i].boxdir);
                    boxes[actions[i].box] = pushbox;

                    if (activeboxlist[actions[i].box] == true)
                    {
                        return(false);
                    }
                    else
                    {
                        activeboxlist[actions[i].box] = true;
                    }
                    break;

                case Interact.PULL:
                    actors[i] = new Actor(actors[i]);
                    Node pullbox = new Node(boxes[actions[i].box]);
                    Pull(actors[i], ref pullbox, actions[i].dir, actions[i].boxdir);
                    boxes[actions[i].box] = pullbox;

                    if (activeboxlist[actions[i].box] == true)
                    {
                        return(false);
                    }
                    else
                    {
                        activeboxlist[actions[i].box] = true;
                    }
                    break;

                case Interact.WAIT:
                    break;
                }
            }

            /*string line = "[";
             * for (int i = 0; i < actions.Count() - 1; i++)
             * {
             *  line = line + actions[i].ToString();
             *  line = line + ", ";
             * }
             * line = line + actions[actions.Count() - 1].ToString();
             * line = line + "]";
             * System.Console.WriteLine(line);*///debug code for seeing what moves are sent

            return(isLegal(boxes));
        }
Example #12
0
 public BoxList(BoxList oldlist)
 {
     boxes = (Node[])oldlist.boxes.Clone();
 }