Esempio n. 1
0
        //Draw process of expanding node
        public void Draw(posContain initial, posContain goal, List <grid> wall, posContain visitedNode, int mapWidth, int mapLength)
        {
            Console.Clear();
            bool wallDrawn = false;

            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapLength; j++)
                {
                    if ((initial.X == j) && (initial.Y == i))
                    {
                        Console.Write("|i");
                        continue;
                    }

                    if ((goal.X == j) && (goal.Y == i))
                    {
                        Console.Write("|g");
                        continue;
                    }

                    if ((visitedNode.X == j) && (visitedNode.Y == i))
                    {
                        Console.Write("|x");
                        continue;
                    }

                    foreach (grid g in wall)
                    {
                        if ((g.IsWall == true) && (g.Pos.X == j) && (g.Pos.Y == i))
                        {
                            Console.Write("|w");
                            wallDrawn = true;
                            break;
                        }
                        wallDrawn = false;
                    }

                    if (wallDrawn == false)
                    {
                        Console.Write("| ");
                    }
                }
                Console.WriteLine("|");
            }

            if ((visitedNode.X == goal.X) && (visitedNode.Y == goal.Y))
            {
                Console.WriteLine("\nSolution found at: ({0},{1})", visitedNode.X, visitedNode.Y);
            }
            else
            {
                Console.WriteLine("\nExpanding node: ({0},{1})", visitedNode.X, visitedNode.Y);
            }
        }
Esempio n. 2
0
        //Robot constructor
        public navigator(string initialState, string goalState, worldMap map)
        {
            stringCon ifs = new stringCon(initialState);

            List <int> coordinate = ifs.getIntFromString();

            pos = new posContain(coordinate[0], coordinate[1]);

            ifs = new stringCon(goalState);

            coordinate = ifs.getIntFromString();

            goalPos = new posContain(coordinate[0], coordinate[1]);

            robotMap = map;
        }
Esempio n. 3
0
        //Draw solution
        public void DrawPath(posContain initial, posContain goal, List <grid> wall, int mapWidth, int mapLength, List <posContain> path)
        {
            Console.Clear();
            bool wallDrawn = false;

            for (int i = 0; i < mapWidth; i++)
            {
                for (int j = 0; j < mapLength; j++)
                {
                    if ((initial.X == j) && (initial.Y == i))
                    {
                        Console.Write("|i");
                        continue;
                    }

                    if ((goal.X == j) && (goal.Y == i))
                    {
                        Console.Write("|g");
                        continue;
                    }

                    if (path.Any(x => x.X == j && x.Y == i))
                    {
                        Console.Write("|x");
                        continue;
                    }

                    foreach (grid g in wall)
                    {
                        if ((g.IsWall == true) && (g.Pos.X == j) && (g.Pos.Y == i))
                        {
                            Console.Write("|w");
                            wallDrawn = true;
                            break;
                        }
                        wallDrawn = false;
                    }

                    if (wallDrawn == false)
                    {
                        Console.Write("| ");
                    }
                }
                Console.WriteLine("|");
            }
            Console.WriteLine();
        }
Esempio n. 4
0
 public posContain(posContain parent)
 {
     x = parent.X;
     y = parent.Y;
 }
Esempio n. 5
0
 public grid(posContain ppos, bool wall)
 {
     pos    = ppos;
     isWall = wall;
 }
Esempio n. 6
0
        public string produceSolution(string method, posContain initial, posContain child, List <posContain> expanded, string GUI)
        {
            string            solution = "";
            List <posContain> path     = new List <posContain>();
            List <string>     action   = new List <string>();

            expanded.Reverse();

            foreach (posContain p in expanded)
            {
                if ((p.X == child.X) && (p.Y == child.Y))
                {
                    path.Add(p);
                }

                if (path.Count() != 0)
                {
                    if ((path.Last().ParentNode.X == p.X) && (path.Last().ParentNode.Y == p.Y))
                    {
                        path.Add(p);
                    }
                }
            }

            path.Reverse();

            //Produce action from path
            for (int i = 0; i < path.Count(); i++)
            {
                if (i == path.Count() - 1)
                {
                    break;
                }


                if (path[i + 1].Y == path[i].Y - 1)
                {
                    action.Add(MoveUp());
                }

                if (path[i + 1].X == path[i].X - 1)
                {
                    action.Add(MoveLeft());
                }

                if (path[i + 1].Y == path[i].Y + 1)
                {
                    action.Add(MoveDown());
                }

                if (path[i + 1].X == path[i].X + 1)
                {
                    action.Add(MoveRight());
                }
            }

            foreach (string a in action)
            {
                solution = solution + a + "; ";
            }
            if (GUI == "Y")
            {
                ui.DrawPath(pos, goalPos, robotMap.WallList, robotMap.Width, robotMap.Length, path);
            }
            return(method + " " + expanded.Count() + " " + solution);
        }