Beispiel #1
0
        public void Load(GraphicsDeviceManager graphics, ContentManager Content)
        {
            // TODO: use this.Content to load your game content here
            tank          = Content.Load <Texture2D>("Tank");
            position_tank = new Vector2(30 * 20f, 0 * 20f);
            origin        = new Vector2(tank.Width / 2f, tank.Height / 2f);

            pixel_black = Content.Load <Texture2D>("Pixel_2_black");
            pixel_red   = Content.Load <Texture2D>("Pixel_2_red");
            font_wheels = Content.Load <SpriteFont>("Game");

            r_pos        = new List <Vector2>();
            b_pos        = new List <Vector2>();
            lines        = new List <Vector2>();
            line_closest = new List <Vector2>();
            r_pos        = g.RedPositions;
            b_pos        = g.BluePositions;

            vec_closest_r = ClosestDot(DOTS.RED);
            AngleDist(vec_closest_r, out dir_closest_r, out dist_r);
            vec_closest_b = ClosestDot(DOTS.BLUE);
            AngleDist(vec_closest_b, out dir_closest_b, out dist_b);
            net = new BNet(neurons, 1, .25f, .9f);//neurons, slope?, learningrate, momentum
            net.Randomize();
        }
Beispiel #2
0
        public void Update()
        {
            // TODO: Add your update logic here
            r_pos        = new List <Vector2>();
            b_pos        = new List <Vector2>();
            lines        = new List <Vector2>();
            line_closest = new List <Vector2>();
            r_pos        = g.RedPositions;
            b_pos        = g.BluePositions;
            currentState = Keyboard.GetState();
            if (currentState.IsKeyDown(Keys.R))
            {
                position_tank = new Vector2(30 * 20f, 0 * 20f);
                rotation      = 90f;
                wheels[0]     = .5f;
                wheels[1]     = .5f;

                r_pos        = new List <Vector2>();
                lines        = new List <Vector2>();
                line_closest = new List <Vector2>();
                r_pos        = g.RedPositions;

                vec_closest_r = ClosestDot(DOTS.RED);
                AngleDist(vec_closest_r, out dir_closest_r, out dist_r);
                net = new BNet(neurons, 1, .25f, .9f);//neurons, slope?, learningrate, momentum
                net.Randomize();
            }

            if (draw)
            {
                draw = false;
            }
            CalcRotation();
            CalcPosition();
            DrawLines(DOTS.RED);
            g.Collision((int)position_tank.X, (int)position_tank.Y, vec_closest_r);
            if (currentState.IsKeyDown(Keys.N) || g.Reset)
            {
                float dist;
                vec_closest_r = ClosestDot(DOTS.RED);
                g.Reset       = false;
            }
            else
            {
                AngleDot(vec_closest_r, out dir_closest_r);
            }

            Train();
            AdjustWheels();
        }