コード例 #1
0
ファイル: Result.cs プロジェクト: isan0786/Knight-Tour
        static void Main(string[] args)
        {
            Choices c = new Choices();
            int     j = 0;
            int     i = 0;

            while (i < 10)
            {
                //  c.intelligent(5, 5); get full score
                c.intelligent(5, 5);
                i++;
            }
            Console.WriteLine("------------------------------------");
            while (j < 10)
            {
                //  c.intelligent(5, 5); get full score
                c.nonIntelligent(5, 5);
                j++;
            }
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Choices.cs プロジェクト: isan0786/Knight-Tour
        public static int nonIntelligent(int a, int b)
        {
            int numOfMoves = 1;

            int[,] nonIntelliBoard = new int[8, 8]; //Making a game board of  8x8 of int


            Knight nonIntelliKnight = new Knight(a, b); //change the parameters of the intelligent method and non intelli so that theyit will go as the user said

            nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves;



            int move = 0;

            do
            {
                Choices choice = new Choices();

                string[] knightMoves = choice.goodMovesNonIntelli(choice.convertListToString(nonIntelliKnight.a, nonIntelliKnight.b), nonIntelliBoard);

                move = knightMoves.Length;


                if (knightMoves[0] == "")
                {
                    move = 0;
                    break;
                }


                if (move == 1)
                {
                    int first  = (int)Char.GetNumericValue(knightMoves[0][0]);
                    int second = (int)Char.GetNumericValue(knightMoves[0][1]);

                    nonIntelliKnight.a = first;
                    nonIntelliKnight.b = second;

                    numOfMoves++;

                    nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves;
                }
                else
                {
                    Random rnd = new Random();

                    int     random = rnd.Next(0, knightMoves.Length); //random number is generated
                    Choices cRan   = new Choices();
                    while (cRan.randomers == random)
                    {
                        random = rnd.Next(0, knightMoves.Length);
                    }

                    cRan.randomers = random;



                    int first  = (int)Char.GetNumericValue(knightMoves[random][0]);
                    int second = (int)Char.GetNumericValue(knightMoves[random][1]);

                    nonIntelliKnight.a = first;
                    nonIntelliKnight.b = second;

                    numOfMoves++;

                    nonIntelliBoard[nonIntelliKnight.a, nonIntelliKnight.b] = numOfMoves;
                }
            } while (move > 0);

            //  Console.WriteLine(numOfMoves + "these are the moves");
            saver += "\n";
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    //    Console.Write("{0:D2} ", nonIntelliBoard[i, j]);

                    if (nonIntelliBoard[i, j].ToString().Length == 1)
                    {
                        saver += string.Format("  {0}   ", nonIntelliBoard[i, j]);
                    }
                    else
                    {
                        saver += string.Format(" {0}  ", nonIntelliBoard[i, j]);
                    }
                }
                //    Console.WriteLine("");
                saver += "\n";
            }
            saver += "\n";
            saver += "\n";



            return(numOfMoves);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: isan0786/Knight-Tour
        private void button1_Click(object sender, EventArgs e)
        {
            //   Console.WriteLine("column is " + column + " row is" + row + " method is" + method + " times is" + noOfTimes + " name is" + name);
            if (row != "" && column != "" && noOfTimes != "" && name != "")
            {
                if ((Convert.ToInt32(row) >= 0 && Convert.ToInt32(row) <= 7) && (Convert.ToInt32(column) >= 0 && Convert.ToInt32(column) <= 7) && (Convert.ToInt32(noOfTimes) > 0))
                {
                    //  textBox3.Text = "1 to " + noOfTimes.ToString();
                    counter = Convert.ToInt32(noOfTimes);

                    if (method == "HeuristicsMethod")
                    {
                        result = "";
                        while (counter > times)
                        {
                            Choices c = new Choices();

                            Choices.saver += "Chess Board " + (times + 1).ToString();
                            //  c.intelligent(5, 5); get full score
                            moves = c.intelligent(Convert.ToInt32(row), Convert.ToInt32(column));

                            numbers.Add(moves);

                            averageMoves += moves;

                            //   Console.WriteLine("------------------------------------ intelli");

                            //  c.intelligent(5, 5); get full score

                            times++;

                            result += "Trial " + times.ToString() + ":   The knight was able to successfully touch " + moves + " squares\r\n\r\n";
                        }
                        times = 0;
                    }
                    else
                    {
                        result = "";

                        while (counter > times)
                        {
                            Choices c = new Choices();

                            Choices.saver += "Chess Board " + (times + 1).ToString();
                            //  c.intelligent(5, 5); get full score
                            moves = Choices.nonIntelligent(Convert.ToInt32(row), Convert.ToInt32(column));
                            numbers.Add(moves);
                            averageMoves += moves;
                            //   Console.WriteLine("------------------------------------ non intelli");

                            //  c.intelligent(5, 5); get full score

                            times++;


                            result += "Trial " + times.ToString() + ":   The knight was able to successfully touch " + moves + " squares\r\n\r\n";
                        }

                        times = 0;
                    }
                    //   Console.WriteLine(result);
                    using (StreamWriter Writer = new StreamWriter(name + method + ".txt"))
                    {
                        Writer.WriteLine(result);
                    }
                }
                else
                {
                    Console.WriteLine("The values that you gave are not good enough , Please provide the right input");
                }
            }
            else
            {
                Console.WriteLine("You didn't fill one of the text feild, Please provide the right input");
            }

            averageMoves      = averageMoves / Convert.ToInt32(noOfTimes);
            richTextBox1.Text = Choices.saver;
            label8.Text       = name;

            if (Convert.ToInt32(noOfTimes) == 2)
            {
                MessageBox.Show("The average is " + averageMoves);
            }
            if (Convert.ToInt32(noOfTimes) > 2)
            {
                MessageBox.Show("The average is " + averageMoves);
                MessageBox.Show("The standard deviation is " + getStandardDeviation(numbers));
            }
            Choices.saver = "";
            averageMoves  = 0;
            numbers.Clear();
        }