예제 #1
0
 public void Replace(TrajectoryQueue queue)
 {
     lock (this)
     {
         this.positionQueue = new List <double[]>(queue.GetList(QueueType.Position));
         this.velocityQueue = new List <double[]>(queue.GetList(QueueType.Velocity));
     }
 }
예제 #2
0
 public void UpdatePuckTrajectory(TrajectoryQueue puckT)
 {
     lock (puckTrajectoryLock)
     {
         puckEstimatedTrajectory.Clear();
         puckEstimatedTrajectory.Replace(puckT);
     }
 }
예제 #3
0
        public static TrajectoryQueue EstimatePuckTrajectory(Point puckP, Point puckV, double puckR, int tableW, int tableH, double timeStep, double timeScale)
        {
            TrajectoryQueue traj = new TrajectoryQueue(2, puckP.GetAsArray());
            double          Tmax = 1;
            double          t    = 0;
            double          Ts   = timeStep;

            while (t < Tmax)
            {
                #region X
                puckP.X = puckP.X + Ts * puckV.X;
                if (puckP.X > tableW / 2.0)
                {
                    puckP.X = puckP.X - puckP.X % (tableW / 2.0);
                    puckV.X = -puckV.X;
                }
                else if (puckP.X < -tableW / 2.0)
                {
                    puckP.X = puckP.X + (Math.Abs(puckP.X) % (tableW / 2.0));
                    puckV.X = -puckV.X;
                }
                #endregion X

                #region Y
                puckP.Y = puckP.Y + Ts * puckV.Y;
                if (puckP.Y > tableH / 2.0)
                {
                    puckP.Y = puckP.Y - (puckP.Y % (tableH / 2.0));
                    puckV.Y = -puckV.Y;
                }
                else if (puckP.Y < -tableH / 2.0)
                {
                    puckP.Y = puckP.Y + (Math.Abs(puckP.Y) % (tableH / 2.0));
                    puckV.Y = -puckV.Y;
                }
                #endregion y

                traj.AddBack(QueueType.Position, puckP.GetAsArray());
                traj.AddBack(QueueType.Velocity, puckV.GetAsArray());

                t = t + Ts;
            }
            return(traj);
        }
예제 #4
0
        public WorldModel()
        {
            #region Locks Init
            physicalStateLock  = new Object();
            globalLock         = new Object();
            strategyLock       = new Object();
            constantsLock      = new Object();
            puckTrajectoryLock = new Object();
            delaysLock         = new Object();
            #endregion Locks Init

            #region puck trajectory
            // puck always have only 2 degrees of freedom (x,y) since its only an endeffector.
            puckEstimatedTrajectory = new TrajectoryQueue(2, new double[2] {
                0, 0
            });
            #endregion puck trajectory

            #region physical state
            physicalState = new Dictionary <string, double>()
            {
                { "AgentX", -1000.0 },
                { "AgentY", 0.0 },
                { "AgentVx", 0.0 },
                { "AgentVy", 0.0 },
                { "PuckX", 0.0 },
                { "PuckY", 0.0 },
                { "PuckVx", 0.0 },
                { "PuckVy", 0.0 },
                { "PuckR", 0.0 },
                { "OpponentX", 1000.0 },
                { "OpponentY", 0.0 },
                { "OpponentVx", 0.0 },
                { "OpponentVy", 0.0 }
            };
            #endregion physical state

            #region global data
            global = new Dictionary <string, int>()
            {
                { "AgentScore", 0 },
                { "OpponentScore", 0 },
            };
            #endregion global data

            #region strategy
            strategy = new Dictionary <string, double>()
            {
                { "GameStyle", 0 },
                { "PLeft", (double)1 / 3 },
                { "PMiddle", (double)1 / 3 },
                { "PRight", (double)1 / 3 },
            };
            #endregion strategy

            #region game constants
            //constants = new Dictionary<string,int>()
            constants = new Hashtable()
            {
                { "MaxScore", 20 },
                { "Tablewidth", 2000 },
                { "Tableheight", 1000 },
                { "FrameRate", 50 },
                { "TimeStep", 0.01 },
                { "TimeScale", 1 },
                { "PuckRadius", 32 },
                { "MalletRadius", 47.5 },
                { "PlanPeriod", 0.2 },
                { "MoveInterval", 0.8 }
            };
            #endregion game constants

            #region Delays
            delays = new Dictionary <string, int>()
            {
                { "Measurement", 0 },
                { "Control", 0 }
            };
            #endregion Delays
        }