Ejemplo n.º 1
0
        public Page3()
        {
            HnS HideAndSeek = new HnS();
            int houseCount  = HideAndSeek.getGraphHnS().getHouseCount();

            int[,] matrixOfEllipse = new int[houseCount + 1, 3];
            float awaitTime = 0;

            InitializeComponent();
            drawMap(HideAndSeek, matrixOfEllipse);

            //List<int> temporary = new List<int>(){ 1, 2, 3 };
            //drawDFS(temporary);
            using (TextReader new_reader = File.OpenText("question.txt"))
            {
                int sumQuestion = int.Parse(new_reader.ReadLine());
                for (int i = 0; i < sumQuestion; i++)
                {
                    string   temp  = new_reader.ReadLine();
                    string[] temp2 = temp.Split(' ');

                    int userChoice = int.Parse(temp2[0]);

                    int hideHouse  = int.Parse(temp2[1]);
                    int startHouse = int.Parse(temp2[2]);

                    List <int> listVisited = new List <int>();
                    List <int> listfix     = new List <int>();
                    listfix.Add(hideHouse);

                    List <int>[] list_prec = new List <int> [HideAndSeek.getCountHouse() + 1];
                    for (int j = 0; j <= HideAndSeek.getCountHouse(); j++)
                    {
                        list_prec[j] = new List <int>();
                    }

                    HideAndSeek.solve(HideAndSeek.getGraphHnS(), startHouse, hideHouse, listVisited, userChoice, list_prec);

                    if (HideAndSeek.getIsFound())
                    {
                        HideAndSeek.makeSolution(hideHouse, list_prec, listfix);
                        listfix.Sort();
                        drawDFS(listVisited);

                        awaitTime = (listVisited.Count + 1) * 1000;
                        drawSolution(listfix, awaitTime);
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void drawMap(HnS hideAndSeek)
        {
            Graph h          = hideAndSeek.getGraphHnS();
            int   houseCount = h.getHouseCount();

            //Making a List of house per Weight
            int maxWeight = h.getMaxWeight();

            List <int>[] listPerWeight = new List <int> [maxWeight + 1];
            for (int i = 0; i <= maxWeight; i++)
            {
                listPerWeight[i] = new List <int>();
            }
            for (int house = 1; house <= houseCount; house++)
            {
                int idx = h.getWeight(house);
                listPerWeight[idx].Add(house);
            }

            //2D Array of point
            //use   : storing left and right point of ellipse(s) horizontal radius
            int[,] matrixOfPoints = new int[houseCount + 1, 5];

            //colors
            Brush ellipseCol = (Brush)(new BrushConverter().ConvertFrom("#C70039"));
            Brush lineCol    = (Brush)(new BrushConverter().ConvertFrom("#787878"));

            //Relative position of grid (circle and label)
            int x   = 50;
            int y   = 50;
            int rad = 50;

            //drawing houses
            for (int weight = 0; weight <= maxWeight; weight++)
            {
                y = 50;
                foreach (int house in listPerWeight[weight])
                {
                    //x1,y1,x2,y2
                    matrixOfPoints[house, 1] = x;
                    matrixOfPoints[house, 2] = y + (rad / 2);
                    matrixOfPoints[house, 3] = x + rad;
                    matrixOfPoints[house, 4] = y + (rad / 2);

                    string label       = house.ToString();
                    Grid   ellipseGrid = new Grid();

                    //Create ellipse and textboxt as house representation
                    ellipseGrid.Children.Add(new Ellipse()
                    {
                        Name   = "ellipse" + house,
                        Width  = rad,
                        Height = rad,
                        Fill   = ellipseCol
                    });

                    ellipseGrid.Children.Add(new TextBlock()
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Text       = label,
                        Foreground = Brushes.White
                    });


                    mainCanvas.Children.Add(ellipseGrid);
                    //Grid Location
                    Canvas.SetTop(ellipseGrid, y);
                    Canvas.SetLeft(ellipseGrid, x);
                    Canvas.SetZIndex(ellipseGrid, 2);

                    y += 100;
                }
                x += 100;
            }

            //drawing lines
            for (int house = 1; house <= houseCount; house++)
            {
                //get adjacency list
                List <int> listHouse = h.getListHouse(house);
                int        xgap      = 20;

                Grid lineGrid = new Grid();

                foreach (int neighbor in listHouse)
                {
                    if (house < neighbor)
                    {
                        lineGrid.Children.Add(new Line()
                        {
                            //create line with starting point in house and end point in neighbor
                            StrokeThickness = 4,
                            Stroke          = lineCol,
                            X1 = matrixOfPoints[house, 3] - xgap,
                            Y1 = matrixOfPoints[house, 4],
                            X2 = matrixOfPoints[neighbor, 1] + xgap,
                            Y2 = matrixOfPoints[neighbor, 2]
                        });
                    }
                }

                //Bring to back
                Canvas.SetZIndex(lineGrid, 1);
                mainCanvas.Children.Add(lineGrid);
            }
        }