Пример #1
0
        //------------------------------Public util functions---------------------

        public SeenCoachObject GetMyPlayerDetailsByCoach()
        {
            var res = m_coach.GetSeenCoachObject($"player {m_team.m_teamName} {m_number}");

            if (res == null)
            {
                throw new Exception("Couldn't find my player");
            }
            return(res);
        }
Пример #2
0
        /// <summary>
        /// Returns absolute target position and angle
        /// </summary>
        /// <returns></returns>
        private Position WhereToGo()
        {
            // get ball position
            var    ball    = m_coach.GetSeenCoachObject("ball");
            PointF ballPos = new PointF();

            if (ball == null)
            {
            }
            else
            {
                ballPos = ball.Pos.Value;
            }
            // calculate target position
            float alpha     = (float)Math.Atan((ballPos.Y - OpponentGoal.Y) / (ballPos.X - OpponentGoal.X));
            var   targetX   = (float)(ballPos.X - Math.Cos(alpha));
            var   targetY   = (float)(ballPos.Y + Math.Sin(alpha));
            var   targetPos = new PointF(targetX, targetY);

            float alphaDegrees = Utils.RadToDeg(alpha);
            float targetAngle  = alphaDegrees;

            if (ball.Pos.Value.X >= 0 && ball.Pos.Value.X < 90 &&
                ball.Pos.Value.Y >= 0 && ball.Pos.Value.Y < 90)
            {
            }
            else if (ball.Pos.Value.X >= 90 && ball.Pos.Value.X < 0 &&
                     ball.Pos.Value.Y >= 0 && ball.Pos.Value.Y < 90)
            {
            }

            return(new Position(targetPos, targetAngle));
        }
Пример #3
0
        public virtual int FindPlayerClosestToTheBall()
        {
            SeenCoachObject ballPosByCoach         = null;
            SeenCoachObject objPlayer              = null;
            double          Distance               = -1;
            double          CurrentDistance        = -1;
            string          player                 = "player ";
            int             playerListNum          = 0;
            int             ClosestPlayerToTheBall = -1;


            var PlayersList = m_coach.GetSeenCoachObjects().Where(kvp => kvp.Value.Name.Contains(m_team.m_teamName)).ToList();

            if (PlayersList.Count > 2)
            {
                return(0);
            }

            Object thisLock = new Object();

            lock (thisLock)
            {
                for (int i = 0; i < PlayersList.Count; i++)
                {
                    playerListNum  = i + 1;
                    ballPosByCoach = m_coach.GetSeenCoachObject("ball");


                    Double BallX = ballPosByCoach.Pos.Value.X;
                    Double BallY = ballPosByCoach.Pos.Value.Y;

                    objPlayer = m_coach.GetSeenCoachObject(player + m_team.m_teamName + " " + playerListNum.ToString());
                    Double PlayerX = objPlayer.Pos.Value.X;
                    Double PlayerY = objPlayer.Pos.Value.Y;
                    CurrentDistance = Math.Sqrt(Math.Pow(PlayerX - BallX, 2) + Math.Pow(PlayerY - BallY, 2));
                    if (i == 1)
                    {
                        Distance = CurrentDistance;
                        ClosestPlayerToTheBall = i;
                    }
                    else if (CurrentDistance < Distance)
                    {
                        Distance = CurrentDistance;
                        ClosestPlayerToTheBall = i;
                    }
                }
            }

            return(ClosestPlayerToTheBall);
        }