Ejemplo n.º 1
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (PongGame game = new PongGame())
     {
         game.Run();
     }
 }
Ejemplo n.º 2
0
        void Start()
        {
            StartPosistion = transform.position;
            _game          = FindObjectOfType <PongGame>();
            _ball          = FindObjectOfType <PongBall>();
            if (Side == Player.Player1)
            {
                _grid = new QGrid(16, transform,
                                  new GridSettings {
                    Offset = new Vector3(9.8f, 0, 0), ResolutionX = 1.28f, ResolutionY = 1.28f
                });
                _vect = Vector <float> .Build.Dense(new[] { 1f });

                QAIManager.InitAgent(this, new QOption {
                    LearningRate = 0.005f,
                    NetworkArgs  = new [] { new CNNArgs {
                                                FilterSize = 4, FilterCount = 1, PoolLayerSize = 2, Stride = 2
                                            } },
                    MaxPoolSize      = 2000,
                    BatchSize        = 2000,
                    EpsilonStart     = 0.5f,
                    EpsilonEnd       = 0.1f,
                    Discount         = 0.95f,
                    TrainingInterval = 20,
                    TrainingCycle    = 10,
                });

                if (QAIManager.CurrentMode == QAIMode.Learning || QAIManager.CurrentMode == QAIMode.Testing)
                {
                    Time.timeScale = 5f;
                }
            }
            StartCoroutine(Movement());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (PongGame game = new PongGame())
     {
         game.Run();
     }
 }
Ejemplo n.º 4
0
 public Ball(PongGame game, Texture2D texture, Rectangle screenBounds)
 {
     bounds = new Rectangle(0, 0, texture.Width, texture.Height);
     this.game = game;
     this.texture = texture;
     this.screenBounds = screenBounds;
     gameStart = false;
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var game = new PongGame();

            game.Start(new ApplicationConfig()
            {
                WindowSize = new Vector2i(1920, 1080),
            });
        }
Ejemplo n.º 6
0
        public override void Entry(IModHelper helper)
        {
            game = new PongGame(helper);

            InputEvents.ButtonPressed        += this.ButtonPressed;
            GraphicsEvents.OnPostRenderEvent += this.OnPostRender;
            GraphicsEvents.Resize            += this.Resize;
            ControlEvents.MouseChanged       += this.MouseChanged;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Form constructor, init the form and the game
        /// </summary>
        public PongForm()
        {
            InitializeComponent();
            game = new PongGame(gameRenderer.ClientSize);
            gameRenderer.Game = game; // Set game object to renderer
            game.speed        = (int)speedPicker.Value;

            //Resize Event, changes game Sizes
            gameRenderer.Resize += new EventHandler((s, e) => { game.gameRenderSize = gameRenderer.ClientSize; game.rightRacket.Position.X = gameRenderer.ClientSize.Width - Racket.xDistance; });
        }
Ejemplo n.º 8
0
        public PongForm()
        {
            InitializeComponent();
            g = new PongGame((Size)this.ClientSize);

            // Create a timer with a two second interval.
            aTimer          = new System.Timers.Timer();
            aTimer.Interval = 10;

            aTimer.Elapsed += OnTimedEvent; // Add event handler
            aTimer.Enabled  = true;         // Start the timer
        }
Ejemplo n.º 9
0
        void FixedUpdate()
        {
            var ball = PongGame.BoundsFromTransform(transform);
            var p    = transform.position + _velocity * Time.fixedDeltaTime;

            p.x -= ball.size.x / 2;
            p.y -= ball.size.y / 2;

            //Check vs game borders
            if (ball.max.y > _game.Border.max.y)          //Top
            {
                _velocity = Vector3.Reflect(_velocity, Vector3.down);
                SetTransformY(_game.Border.max.y - ball.size.y / 2);
            }
            else if (ball.min.y < _game.Border.min.y)     //Bot
            {
                _velocity = Vector3.Reflect(_velocity, Vector3.up);
                SetTransformY(_game.Border.min.y + ball.size.y / 2);
            }

            var p1 = PongGame.BoundsFromTransform(Player1.transform);
            var p2 = PongGame.BoundsFromTransform(Player2.transform);

            if (ball.Intersects(p1))   //Player 1 controller
            {
                _velocity = Vector3.Reflect(_velocity, Vector3.right).normalized * ++_speed;
                SetTransformX(p1.max.x + ball.size.x / 2);
                Player1.Hits++;
                Debug.Log(Player1.Hits);
            }
            else if (ball.min.x < _game.Border.min.x)    //Player 1 Goal
            {
                _game.Score(Player.Player2);
                //Reset(1);
            }

            if (ball.Intersects(p2))   //Player 2 controller
            {
                _velocity = Vector3.Reflect(_velocity, Vector3.left).normalized * ++_speed;
                SetTransformX(p2.min.x - ball.size.x / 2);
                Player2.Hits++;
            }
            else if (ball.max.x > _game.Border.max.x)    //Player 2 Goal
            {
                _game.Score(Player.Player1);
                //Reset(-1);
            }

            //Update position
            transform.position += _velocity * Time.fixedDeltaTime;
            PongGame.DebugDrawBounds(PongGame.BoundsFromTransform(transform), Color.red);
        }
Ejemplo n.º 10
0
        void Awake()
        {
            _game  = FindObjectOfType <PongGame>();
            _speed = 5f;
            //_velocity = new Vector3(-1, Random.Range(-1f, 1f)).normalized * _speed; //random angle
            _velocity           = new Vector3(-1, angles.Random().First()).normalized *_speed; //random angle from set
            transform.position += new Vector3(9, Random.Range(-6f, 6f));                       //random posistion
            //transform.position += new Vector3(9, 0);  //fixed posistion - use when using fixed angles sequence?
            var pcs = FindObjectsOfType <PongController>();

            Player1 = pcs.First(pc => pc.Side == Player.Player1);
            Player2 = pcs.First(pc => pc.Side == Player.Player2);
        }
Ejemplo n.º 11
0
        //Returns the winner if there is one
        public Player?IsTerminal()
        {
            var ball = PongGame.BoundsFromTransform(transform);

            if (ball.min.x < _game.Border.min.x)
            {
                return(Player.Player2);
            }
            if (ball.max.x > _game.Border.max.x)
            {
                return(Player.Player1);
            }
            return(null);
        }
Ejemplo n.º 12
0
 static void Main()
 {
     try
     {
         using (var game = new PongGame())
             game.Run();
     }
     catch (Exception ex)
     {
         using (TextWriter fichero = new StreamWriter(new FileStream("Error log.txt", FileMode.Create)))
         {
             fichero.WriteLine("ERROR: " + Environment.NewLine + ex.Message);
         }
     }
 }
Ejemplo n.º 13
0
        private static void Main(string[] args)
        {
            var game = new PongGame();

            game.Start(new ApplicationConfig()
            {
                WindowSize          = new Vector2i(1920, 1080),
                WindowTitle         = "Aximo Pong",
                IdleRenderFrequency = 0,
                IdleUpdateFrequency = 0,
                RenderFrequency     = 0,
                UpdateFrequency     = 0,
                VSync = VSyncMode.Off,
                //IsMultiThreaded = false,
            });
        }
Ejemplo n.º 14
0
        public QState GetState()
        {
            var   winner = _ball.IsTerminal();
            float reward;
            bool  terminal;
            //var terminal = winner.HasValue;
            //var reward = terminal ? (winner.Value == Side ? 1 : 0) : 0;
            var b          = PongGame.BoundsFromTransform(_ball.transform);
            var controller = PongGame.BoundsFromTransform(transform);

            controller.size += new Vector3(0.2f, 0, 0);
            PongGame.DebugDrawBounds(controller, Color.blue);
            if (b.Intersects(controller))
            {
                reward   = 1;
                terminal = true;
                if (PongBenchmark.Running)
                {
                    terminal = winner.HasValue;
                }
            }
            else
            {
                terminal = winner.HasValue;
                reward   = terminal ? (winner.Value == Side ? 1 : 0) : 0;
            }

            var bp  = _ball.transform.position;
            var rbp = bp - transform.position;

            var gbp = _grid.Locate(bp);
            var bpy = gbp.HasValue ? gbp.Value.y : -1;

            _grid.Populate((bo, c) => {
                //var x = bo.center.x;
                //var v = bo.Contains(new Vector3(x, _game.Border.min.y)) || bo.Contains(new Vector3(x, _game.Border.max.y)) ? 0.3f : 0; // walls
                var ham = gbp.HasValue ? HammingDistance(gbp.Value, c) : int.MaxValue; // Hamming distance
                var v   = ham <= 0 ? 1f : ham <= 1 ? 0.5f : 0;                         // ball
                //v = bo.Contains(bp + _ball.Velocity.normalized * 2) ? 150f : v;
                //v = bo.Intersects(controller) ? 100 : v;
                return(v);
            });

            var state = _grid.Matrix;

            return(new QState(new[] { state }, _vect.Clone(), reward, terminal));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initialize anything that needs it
        /// Runs once as the window starts
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            FPSUpdate.Enabled = true;

            //Print OpenGL Information to the Console, for referance
            Console.WriteLine("OpenGL Version: " + GL.GetString(StringName.Version));
            Console.WriteLine("GLSL Version: " + GL.GetString(StringName.ShadingLanguageVersion));
            Console.WriteLine(GL.GetString(StringName.Vendor) + " - " + GL.GetString(StringName.Renderer));

            GL.Enable(EnableCap.CullFace);

            //Initialize the Game
            Game = new PongGame(this.ClientSize);
            GameCamera = new Camera(this.Width, this.Height, 0.1f, 100.0f, new Camera.CameraInfo(new Vector3(0.0f, 0.0f, 19.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Calc the next Racket colliding position and move the Racket to this pos
        /// </summary>
        /// <param name="g">GameObject</param>
        /// <param name="b">Ball to check</param>
        /// <param name="r">Racket to check</param>
        /// <param name="dir">Racket direction</param>
        public static void calc(PongGame g, Ball b, Racket r, Racket.Direction dir)
        {
            Ball imag = new Ball(new Point(b.Position.X, b.Position.Y), new Size(50, 50));

            imag.dx = int.Parse(b.dx.ToString());
            imag.dy = int.Parse(b.dy.ToString());


            while (imag.isCollidingWallEX(g.gameRenderSize) != dir)
            {
                imag.Move(0.2d, 1);
            }

            // Console.WriteLine("while ended colliding: " + imag.Position.ToString());
            _ii.Add(imag.Position.Y);
            int i = imag.Position.Y - (int)(imag.Size.Height);  ///0.5f

            // Console.WriteLine("moving to: " + i);
            r.MoveTo(i, g.gameRenderSize, g.speed);
        }
Ejemplo n.º 17
0
 static void Main()
 {
     using (var game = new PongGame())
         game.Run();
 }
Ejemplo n.º 18
0
 public ConnectToServer(PongGame form)
 {
     InitializeComponent();
     this.pongForm = form;
 }
Ejemplo n.º 19
0
 static void Main()
 {
     using (var game = new PongGame())
         game.Run();
 }
Ejemplo n.º 20
0
 static void Main()
 {
     PongGame game = new PongGame();
     game.Run();
 }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            PongGame pong = new PongGame();

            pong.Run(2);
        }