Exemple #1
0
 public bool intersectsRect(Rect r)
 {
     if ((r.Pos.X >= Pos.X && r.Pos.X <= Pos.X + Size.X && r.Pos.Y >= Pos.Y && r.Pos.Y <= Pos.Y + Size.Y) || (r.Pos.X + r.Size.X >= Pos.X && r.Pos.X + r.Size.X <= Pos.X + Size.X && r.Pos.Y >= Pos.Y && r.Pos.Y <= Pos.Y + Size.Y) || (r.Pos.X + r.Size.X >= Pos.X && r.Pos.X + r.Size.X <= Pos.X + Size.X && r.Pos.Y + r.Size.Y >= Pos.Y && r.Pos.Y + r.Size.Y <= Pos.Y + Size.Y) || (r.Pos.X >= Pos.X && r.Pos.X <= Pos.X + Size.X && r.Pos.Y + r.Size.Y >= Pos.Y && r.Pos.Y + r.Size.Y <= Pos.Y + Size.Y))
     {
         return true;
     }
     return false;
 }
Exemple #2
0
 public static bool drawRect(Rect rect, ConsoleColor color)
 {
     return drawRect(rect.Pos, rect.Size, color);
 }
Exemple #3
0
        public void start()
        {
            Console.Title = "SmartAI";
            //Console.WriteLine("ProjectAI Starting...");       //disabling for now, in way of drawing
            rand = new Random(DateTime.Now.Millisecond+DateTime.Now.Second);
            Rect rec = new Rect(new Vec2(3, 4), new Vec2(25, 5));
               /* paintutils.setDrawingChar('\\');
            paintutils.drawLine(rec.Pos.X, rec.Pos.Y, rec.Pos.X + rec.Size.X, rec.Pos.Y + rec.Size.Y, ConsoleColor.Blue);
            paintutils.setDrawingChar('/');
            paintutils.drawLine(rec.Pos.X + rec.Size.X, rec.Pos.Y, rec.Pos.X, rec.Pos.Y + rec.Size.Y, ConsoleColor.Blue);*/
            PaintUtils.resetDrawingChar();
            /*PaintUtils.drawRect(rec, ConsoleColor.Blue);
            PaintUtils.setDrawingChar('o');

            for (int i = 0; i < 60; i++)
            {
                Vec2 point = new Vec2(rand.Next(1, 30), rand.Next(1, 20));
                if (rec.containsPoint(point))
                {
                    PaintUtils.drawPixel(point, ConsoleColor.Green);
                }
                else
                {
                    PaintUtils.drawPixel(point, ConsoleColor.Red);
                }
            }
            Console.SetCursorPosition(1, 18);
            Console.WriteLine(" -- Green  =   in rect");
            Console.WriteLine(" -- Red    =   outside rect");
            */
            Notification.Notify("Start.", "Starting Program.");
            PaintUtils.Clear();

            double[][] trainData = new double[4][];
            trainData[0] = new double[] { 1, 1, 0, 1 }; //lol, xor for testing! :D
            trainData[1] = new double[] { 1, 0, 1, 0 };
            trainData[2] = new double[] { 0, 1, 1, 0 };
            trainData[3] = new double[] { 0, 0, 0, 1 };

            Console.WriteLine("Starting..");
            const int numInput = 2;
            const int numHidden = 8;
            const int numOutput = 2;
            NeuralNetwork nn = new NeuralNetwork(numInput, numHidden, numOutput);

            int popSize = 50;
            int maxGeneration = 900;
            double exitError = 0.0;
            double mutateRate = 0.20;
            double mutateChange = 0.01;
            double tau = 0.40;

            Console.WriteLine("\nBeginning training");
            double[] bestWeights = nn.Train(trainData, popSize, maxGeneration, exitError,
              mutateRate, mutateChange, tau);
            Console.WriteLine("Training complete");

            nn.SetWeights(bestWeights);
            double trainAcc = nn.Accuracy(trainData);
            Console.Write("\nAccuracy on training data = ");
            Console.WriteLine(trainAcc.ToString("F4"));

            Console.WriteLine("__________TESTING STAGE__________");
            while (true)
            {
                Console.WriteLine("Enter values for testing (XOR): ");
                Console.WriteLine("A?");
                string A = Console.ReadLine();
                if (A.Length < 1)
                {
                    break;
                }
                Console.WriteLine("B?");
                string B = Console.ReadLine();
                if (B.Length < 1)
                {
                    break;
                }
                Console.WriteLine("ANSWER: " + (nn.ComputeOutputs(new double[] { double.Parse(A), double.Parse(B) })[0]>0.5));
                Console.WriteLine("----------------------------------");
            }
            PaintUtils.Clear();
            Notification.Notify("Program Ended.", "The program will now exit.");
        }