Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Get random board
            board = PrisonBreakTools.GetNewMaze(BOARD_SIZE);
            PrintMaze();

            // Get random staring point
            Random rand = new Random();
            int    startX, startY;

            do
            {
                startX = rand.Next(0, BOARD_SIZE);
                startY = rand.Next(0, BOARD_SIZE);
            }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);

            Console.WriteLine("Start: {0} {1}", startX, startY);

            // Your output goes here

            var stack = new Stack <Point>();

            FindPath(stack, startX, startY); //if there is a path the coordinates are stored in List<Point> points

            if (!points.Any())               //no path
            {
                Console.WriteLine("No path.");
            }
            else// there is a path
            {
                //Console.WriteLine("Exit: " + string.Join(", ", points));
                Console.WriteLine("Exit: " + points.Last().ToString());

                var doors = GetDoorsFromPath();

                if (!doors.Any())
                {
                    Console.WriteLine("No blocking doors.");
                }
                else
                {
                    GetBlockingDoors(doors, startX, startY);

                    if (!blockingDoors.Any())
                    {
                        Console.WriteLine("No blocking doors!");
                    }
                    else
                    {
                        Console.WriteLine("Blocking doors: ");
                        Console.WriteLine(string.Join(Environment.NewLine, blockingDoors));
                    }
                }
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // Get random board
            board = PrisonBreakTools.getNewMaze(BOARD_SIZE);
            printMaze();

            // Get random staring point
            Random rand = new Random();
            int    startX, startY;

            do
            {
                startX = rand.Next(0, BOARD_SIZE);
                startY = rand.Next(0, BOARD_SIZE);
            }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);

            Console.WriteLine("Start: {0} {1}", startX, startY);

            // Your output goes here

            var stack = new Stack <Placement>();

            PathFinder(stack, startX, startY); // ако има изход, то точките ще се съберат в стека

            if (!points.Any())                 // ако няма изход
            {
                Console.WriteLine("No path.");
            }
            else
            {
                Console.WriteLine("Exit: " + points.Last().ToString()); // изходни координати

                var doors = GetDoorsFromPath();                         // взимаме вратите от изходния път

                if (!doors.Any())                                       // ако няма врати, извеждаме съобщение, че няма
                {
                    Console.WriteLine("No blocking doors.");
                }
                else
                {
                    BlockDoors(doors, startX, startY); // ако има ги извеждаме със стек

                    if (!blockingDoors.Any())
                    {
                        Console.WriteLine("No blocking doors!");
                    }
                    else
                    {
                        Console.WriteLine("Blocking doors: ");
                        Console.WriteLine(string.Join(Environment.NewLine, blockingDoors));
                    }
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // Get random board
            board = PrisonBreakTools.getNewMaze(BOARD_SIZE);

            printMaze();

            // Get random staring point
            Random rand = new Random();
            int    startX, startY;

            do
            {
                startX = rand.Next(0, BOARD_SIZE);
                startY = rand.Next(0, BOARD_SIZE);
            }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);

            Console.WriteLine("Start: {0} {1}", startX, startY);

            // Your output goes here
            int[,] newBoard = (int[, ])board.Clone();
            int endX;
            int endY;

            if (IsExitAvailable(startX, startY, NO_VALUE, NO_VALUE, newBoard, out endX, out endY))
            {
                Console.WriteLine($"End X:{endX}\t End Y:{endY}");

                //filter the doors
                findBlockingDoors(startX, startY, endX, endY);
                //print blocking doors Cordinates
                if (doorPositions.Any())
                {
                    Console.WriteLine("Blocking Doors :");
                    foreach (var doorCordinates in doorPositions)
                    {
                        Console.WriteLine($"X cordinate:{doorCordinates.Key}\t\tY cordinate:{doorCordinates.Value}");
                    }
                }
                else
                {
                    Console.WriteLine("No blocking Doors");
                }
            }
            else
            {
                Console.WriteLine("No Path");
            }

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            // Get random board
            board = /*new int[,]
                     * {
                     * {1,0,0,1,0},
                     * {1,2,2,1,0},
                     * {0,0,1,0,1},
                     * {1,0,1,2,1},
                     * {1,1,0,0,1}
                     * };*/
                    PrisonBreakTools.getNewMaze(BOARD_SIZE);
            //printMaze();

            // Get random staring point
            Random rand = new Random();
            int    startX, startY;

            do
            {
                startX = rand.Next(0, BOARD_SIZE);
                startY = rand.Next(0, BOARD_SIZE);
            }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);

            // startX = 3;
            //startY = 1;

            Console.WriteLine("Start: {0} {1}", startX, startY);

            // Your output goes here

            Solution(startX, startY);
            if (hasPath)
            {
                Console.WriteLine("Has path");
                if (doors.Count > 0)
                {
                    CloseDoors(startX, startY);
                }
            }
            else
            {
                Console.WriteLine("No path");
            }
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Get random board
            Console.WriteLine("Unsolved labirinth: ");
            do
            {
                Random rnd = new Random();
                BOARD_SIZE = rnd.Next(5, 21);
            }while (BOARD_SIZE < 5 && BOARD_SIZE > 20);
            board = PrisonBreakTools.getNewMaze(BOARD_SIZE);
            PrintSolvedBoard();

            // Get random staring point
            Random rand = new Random();
            int    startX, startY;

            do
            {
                startX = rand.Next(0, BOARD_SIZE);
                startY = rand.Next(0, BOARD_SIZE);
            }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);

            Console.WriteLine("Start: {0} {1}", startX, startY);
            Console.Write("\n");

            //print results
            if (FindExit(startX, startY))
            {
                Console.WriteLine("This is the solved labirinth. Path found: ");
                PrintSolvedBoard();
                Console.WriteLine("Exit: {0} {1}", newX, newY);
                if (BlockingDoors(startX, startY) == 0)
                {
                    Console.WriteLine("No blocking doors!");
                }
            }
            else
            {
                Console.WriteLine("No path found!");
            }
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            // Get random board
            board = PrisonBreakTools.getNewMaze(BOARD_SIZE);
            printMaze();

            // Get random staring point
            Random rand = new Random();
            int    startX, startY;

            do
            {
                startX = rand.Next(0, BOARD_SIZE);
                startY = rand.Next(0, BOARD_SIZE);
            }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);

            Console.WriteLine("Start: {0} {1}", startX, startY);

            // Your output goes here



            Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("Do you want to create and pass a labyrinth ? (Yes / No)");
                Console.ResetColor();
                string check1 = Console.ReadLine();
                if (check1 == "Yes" || check1 == "yes")
                {
                    // Get random board
                    board = PrisonBreakTools.getNewMaze(BOARD_SIZE, rand);
                    do
                    {
                        startX = rand.Next(0, BOARD_SIZE);
                        startY = rand.Next(0, BOARD_SIZE);
                    }while (board[startX, startY] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);
                    Console.WriteLine("\nStart: " + startX + " " + startY + "\n");

                    // Your output goes here

                    int x = startX; int y = startY;
                    int X; int Y;
                    board[y, x] = TileTypes.MOVE;
                    Stack lastXY = new Stack();
                    printMaze();
                    while (x > 0 || y > 0 || x < BOARD_SIZE - 1 || y < BOARD_SIZE - 1)
                    {
                        if (Around.CheckAround(board, x, y))
                        {
                            lastXY.Push(x); lastXY.Push(y);
                            X = x; Y = y;
                            Step.OneStep(board, x, y, out X, out Y);
                            x = X; y = Y;
                        }
                        else if (!Around.CheckAround(board, x, y))
                        {
                            if (!Around.CheckAround(board, x, y) && (x == 0 || y == 0 || x == BOARD_SIZE - 1 || y == BOARD_SIZE - 1))
                            {
                                Console.WriteLine();
                                printMaze();
                                Console.WriteLine("Labyrinth is overcome\n");
                                Console.ForegroundColor = ConsoleColor.DarkGray;
                                Console.WriteLine("Start: " + startX + " " + startY);
                                Console.WriteLine("Exit: " + x + " " + y + "\n");
                                Console.ResetColor();
                                System.Threading.Thread.Sleep(2000);
                                break;
                            }
                            try
                            {
                                y = Convert.ToInt32(lastXY.Peek());
                                lastXY.Pop();
                                x = Convert.ToInt32(lastXY.Peek());
                                lastXY.Pop();
                            }
                            catch (Exception)
                            {
                                Console.WriteLine();
                                printMaze();
                                Console.WriteLine("Labyrinth is overcome\n");
                                Console.ForegroundColor = ConsoleColor.DarkGray;
                                Console.WriteLine("Start: " + startX + " " + startY);
                                Console.WriteLine("No exit(\n");
                                Console.ResetColor();
                                System.Threading.Thread.Sleep(2000);
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("No exit\n");
                            System.Threading.Thread.Sleep(2000);
                            break;
                        }
                    }
                }
                else if (check1 == "No" || check1 == "no")
                {
                    Console.WriteLine();
                    Console.WriteLine("The program does not work at 100%, but I tried very hard)");
                    Console.WriteLine();
                    System.Threading.Thread.Sleep(3000);
                    Console.WriteLine("Bye..");
                    System.Threading.Thread.Sleep(2000);
                    Environment.Exit(0);
                    break;
                }
                else
                {
                    continue;
                }
            }
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            bool noPath = false;
            bool back   = false;

            do
            {
                Console.Clear();

                // Get random board
                board = PrisonBreakTools.getNewMaze(BOARD_SIZE, rand);

                // Get random starting point
                int startX, startY;

                do
                {
                    startX = rand.Next(0, BOARD_SIZE);
                    startY = rand.Next(0, BOARD_SIZE);
                }while (board[startY, startX] != TileTypes.EMPTY || startX == 0 || startY == 0 || startX == BOARD_SIZE - 1 || startY == BOARD_SIZE - 1);
                Console.WriteLine("Start: {0} {1}", startY, startX);
                //////////////////////////// Your output goes here/////////////////////////////////
                ///////////////////////////////////////////////////////////////////////////////////

                int x = startX; int y = startY;
                int X; int Y;
                board[y, x] = TileTypes.MOVE;
                Stack <int> lastXY = new Stack <int>(); // for backtracking

                Doors.setFirstClose(board);
                printMaze();

                while (x != 0 && y != 0 && x != BOARD_SIZE - 1 && y != BOARD_SIZE - 1)
                {
                    if (Neighbor.CheckNeighbor(board, x, y))
                    {
                        // remembered last x,y in stack
                        lastXY.Push(x); lastXY.Push(y);
                        X = x; Y = y;
                        if (Step.mustClose)
                        {
                            Doors.Close(board);
                        }

                        Step.MakeStep(board, x, y, out X, out Y);

                        x = X; y = Y; // out X,Y after chenges
                    }
                    else if (lastXY.Count != 0)
                    {
                        y = Convert.ToInt32(lastXY.Pop());
                        x = Convert.ToInt32(lastXY.Pop());
                        Console.WriteLine("BackTreking...");
                    }
                    else
                    {
                        Console.WriteLine("No Path!");
                        noPath = true;
                        break;
                    }
                }
                if (noPath == false)
                {
                    Console.WriteLine($"Exit: {y}, {x}");
                }
                back = Convert.ToBoolean(Convert.ToInt16(Console.ReadLine()));
            } while (back);
            Environment.Exit(0);
        }