Пример #1
0
        public void matrixReady()
        {
            H = new Hide_n_Seek(X.getinc());
            for (int i = 1; i < X.getinc() + 1; i++)
            {
                for (int j = 1; j < X.getinc() + 1; j++)
                {
                    if (X.getJembatan(i, j) == 1)
                    {
                        H.map.makeNeighbors(i - 1, j - 1);
                    }
                }
            }
            Check c = new Check();

            for (int i = 1; i <= X.getinc(); i++)
            {
                H.findLevel(1, i, 1, c);
                c.setFound(false);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.Write("Jumlah Rumah : ");
            int         n = Convert.ToInt32(Console.ReadLine());
            Hide_n_Seek H = new Hide_n_Seek(n);

            for (int i = 0; i < n - 1; i++)
            {
                string   line  = Console.ReadLine();
                string[] s     = line.Split(new char[] { ' ' });
                int[]    input = new int [2];
                for (int j = 0; j < 2; j++)
                {
                    input[j] = Convert.ToInt32(s[j]);
                }
                H.map.makeNeighbors(input[0] - 1, input[1] - 1);
            }
            for (int i = 1; i <= n; i++)
            {
                H.findLevel(1, i, 1);
            }
            Console.WriteLine("Level Tiap Rumah : ");
            for (int i = 0; i < n - 1; i++)
            {
                Console.Write(H.map.getLevel(i) + " ");
            }
            Console.WriteLine("Matriks Ketetanggaan : ");
            Console.WriteLine(H.map.getLevel(n - 1));
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n - 1; j++)
                {
                    Console.Write(H.map.getNeighbors(i, j) + " ");
                }
                Console.WriteLine(H.map.getNeighbors(i, n - 1));
            }
            Console.Write("Jumlah Pertanyaan : ");
            int p = Convert.ToInt32(Console.ReadLine());

            int[,] question = new int [p, 4];
            Console.WriteLine("Masukkan Pertanyaan : ");
            for (int i = 0; i < p; i++)
            {
                string   line = Console.ReadLine();
                string[] s    = line.Split(new char[] { ' ' });
                for (int j = 0; j < 3; j++)
                {
                    question[i, j] = Convert.ToInt32(s[j]);
                }
            }
            for (int i = 0; i < p; i++)
            {
                Check c = new Check();
                H.Trace(question[i, 0], question[i, 1], question[i, 2], c);
                if (c.getFound())
                {
                    question[i, 3] = 1;
                }
                else
                {
                    question[i, 3] = 0;
                }
            }
            Console.WriteLine("Jawaban Pertanyaan : ");
            for (int i = 0; i < p; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Console.Write(question[i, j] + " ");
                }
                Console.WriteLine(question[i, 3]);
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("START");
            Console.Write("Enter file name with extention (bridge):");
            string file1 = Console.ReadLine();

            Console.Write("Question from : (1. File/2. Input) :");
            string choice = Console.ReadLine();

            if (choice == "1")
            {
                Console.WriteLine("Enter file name with extention (question):");
                string file2 = Console.ReadLine();

                Masukan inputt = new Masukan();
                inputt.inputFromFileJembatan(file1);
                inputt.inputFromFileQuestion(file2);

                Hide_n_Seek H = new Hide_n_Seek(inputt.getinc());

                // copy matrix mjembatan ke H.map
                for (int i = 1; i < inputt.getinc() + 1; i++)
                {
                    for (int j = 1; j < inputt.getinc() + 1; j++)
                    {
                        if (inputt.getJembatan(i, j) == 1)
                        {
                            H.map.makeNeighbors(i - 1, j - 1);
                        }
                    }
                }
                for (int i = 1; i <= inputt.getinc(); i++)
                {
                    H.findLevel(1, i, 1);
                }

                Console.WriteLine("Level Tiap Rumah : ");
                for (int i = 0; i < inputt.getinc() - 1; i++)
                {
                    Console.Write(H.map.getLevel(i) + " ");
                }
                Console.WriteLine("");

                Console.WriteLine("Matriks Ketetanggaan : ");
                //Console.WriteLine(H.map.getLevel(inputt.getinc()-1));
                for (int i = 0; i < inputt.getinc(); i++)
                {
                    for (int j = 0; j < inputt.getinc() - 1; j++)
                    {
                        Console.Write(H.map.getNeighbors(i, j) + " ");
                    }
                    Console.WriteLine(H.map.getNeighbors(i, inputt.getinc() - 1));
                }


                for (int i = 0; i < inputt.getinc2(); i++)
                {
                    Check c = new Check();
                    H.Trace(inputt.getquestion(i, 0), inputt.getquestion(i, 1), inputt.getquestion(i, 2), c);
                    if (c.getFound())
                    {
                        inputt.setQuestion(i, 3, 1);
                    }
                    else
                    {
                        inputt.setQuestion(i, 3, 0);
                    }
                }
                Console.WriteLine("Answer : ");
                for (int i = 0; i < inputt.getinc2(); i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        Console.Write(inputt.getquestion(i, j) + " ");
                    }
                    Console.Write(" : ");
                    if (inputt.getquestion(i, 3) == 1)
                    {
                        Console.WriteLine("TRUE");
                    }
                    else
                    {
                        Console.WriteLine("FALSE");
                    }
                }
            }
            else if (choice == "2")
            {
                Masukan inputt = new Masukan();
                inputt.inputFromFileJembatan(file1);

                Hide_n_Seek H = new Hide_n_Seek(inputt.getinc());

                // copy matrix mjembatan ke H.map
                for (int i = 1; i < inputt.getinc() + 1; i++)
                {
                    for (int j = 1; j < inputt.getinc() + 1; j++)
                    {
                        if (inputt.getJembatan(i, j) == 1)
                        {
                            H.map.makeNeighbors(i - 1, j - 1);
                        }
                    }
                }
                for (int i = 1; i <= inputt.getinc(); i++)
                {
                    H.findLevel(1, i, 1);
                }

                Console.WriteLine("Level Tiap Rumah : ");
                for (int i = 0; i < inputt.getinc() - 1; i++)
                {
                    Console.Write(H.map.getLevel(i) + " ");
                }

                Console.WriteLine("");

                Console.WriteLine("Matriks Ketetanggaan : ");
                //Console.WriteLine(H.map.getLevel(inputt.getinc()-1));
                for (int i = 0; i < inputt.getinc(); i++)
                {
                    for (int j = 0; j < inputt.getinc() - 1; j++)
                    {
                        Console.Write(H.map.getNeighbors(i, j) + " ");
                    }
                    Console.WriteLine(H.map.getNeighbors(i, inputt.getinc() - 1));
                }

                Console.Write("Input how many question you want to ask : ");
                int p = Convert.ToInt32(Console.ReadLine());
                int[,] ques = new int [p, 4];
                Console.WriteLine("Input your question : ");
                for (int i = 0; i < p; i++)
                {
                    string   line = Console.ReadLine();
                    string[] s    = line.Split(new char[] { ' ' });
                    for (int j = 0; j < 3; j++)
                    {
                        ques[i, j] = Convert.ToInt32(s[j]);
                    }
                }

                for (int i = 0; i < p; i++)
                {
                    Check c = new Check();
                    H.Trace(ques[i, 0], ques[i, 1], ques[i, 2], c);
                    if (c.getFound())
                    {
                        ques[i, 3] = 1;
                    }
                    else
                    {
                        ques[i, 3] = 0;
                    }
                }
                Console.WriteLine("Answer : ");
                for (int i = 0; i < p; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        Console.Write(ques[i, j] + " ");
                    }
                    Console.Write(" : ");
                    if (ques[i, 3] == 1)
                    {
                        Console.WriteLine("TRUE");
                    }
                    else
                    {
                        Console.WriteLine("FALSE");
                    }
                }
            }
            else
            {
                Console.WriteLine("Salah cuy");
            }
        }