Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
        public int ManDist(BoxList boxlist)
        {
            int goaldist = 0;

            foreach (char name in names)
            {
                goaldist += goalgroups[name].ManDist(boxlist, BoxList.boxNameGroups[name]);
            }
            return(goaldist);
        }
Ejemplo n.º 3
0
        public int ManDistAct(BoxList boxlist)
        {
            int Actdist = 0;

            foreach (Color color in ActorList.intToColorDict)
            {
                Actdist += ManDistAct(boxlist, BoxList.boxColorGroups[color]);
            }
            return(Actdist);
        }
Ejemplo n.º 4
0
 public bool IsInGoal(BoxList boxlist)
 {
     foreach (char name in names)
     {
         if (!goalgroups[name].IsInGoal(boxlist, BoxList.boxNameGroups[name]))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
        public Map(bool[] newwallMap, int mapwidth, Collection <Actor> newactors, Dictionary <Node, char> newboxes, GoalList newgoals, Dictionary <char, Color> colorDict)
        {
            id       = Map.nextId++;
            wallMap  = newwallMap;
            mapWidth = mapwidth;

            actors = new ActorList(newactors, colorDict);
            boxes  = new BoxList(newboxes, colorDict);
            goals  = newgoals;
            steps  = 0;
        }
Ejemplo n.º 6
0
 public Map(Map oldmap)
 {
     id            = Map.nextId++;
     parent        = oldmap;
     actors        = new ActorList(oldmap.actors);
     boxes         = new BoxList(oldmap.boxes);
     steps         = oldmap.steps + 1;
     pathOfActor   = (Path[])oldmap.pathOfActor.Clone();
     targetOfActor = (int[])oldmap.targetOfActor.Clone();
     boxPriority   = new Dictionary <int, byte>(oldmap.boxPriority);
     boxDistance   = new Dictionary <int, int>(oldmap.boxDistance);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
            }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 12
0
 public BoxList(BoxList oldlist)
 {
     boxes = (Node[])oldlist.boxes.Clone();
 }