Esempio n. 1
0
        public static void MainGame()
        {
            // Kamus
            HnS new_game = new HnS();
            int input;

            int[] listinput = new int[3];

            // Algoritma
            Console.WriteLine("1. Input File");
            Console.WriteLine("2. Input User");
            Console.WriteLine("Masukkan pilihan (1/2) : ");
            input = int.Parse(Console.ReadLine());

            if (input == 1)
            {
                new_game.letsPlayFile();
            }
            else
            {
                Console.WriteLine("Masukkan query : ");
                string   temp  = Console.ReadLine();
                string[] temp2 = temp.Split(' ');

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

                listinput[1] = int.Parse(temp2[1]);
                listinput[2] = int.Parse(temp2[2]);
                new_game.letsPlayInput(listinput);
            }
        }
Esempio n. 2
0
        public MainWindow()
        {
            HnS HideAndSeek = new HnS();
            int houseCount  = HideAndSeek.getGraphHnS().getHouseCount();

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

            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);
                        drawSolution(listfix);
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }
            }
        }
Esempio n. 3
0
        private void drawMap(HnS hideAndSeek, int[,] matrixOfEllipse)
        {
            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])
                {
                    matrixOfEllipse[house, 1] = x;
                    matrixOfEllipse[house, 2] = y;

                    //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();

                    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()
                        {
                            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);
            }
        }