Exemplo n.º 1
0
        public virtual int FindDefenderClosestToTheBall()
        {
            SeenCoachObject ballPosByCoach         = null;
            SeenCoachObject Player                 = null;
            double          Distance               = -1;
            double          CurrentDistance        = -1;
            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 = 2; i < 4; i++)
                {
                    playerListNum  = i + 1;
                    Player         = m_coach.GetSeenCoachObject($"player {m_team.m_teamName} {playerListNum}");
                    ballPosByCoach = m_coach.GetSeenCoachObject("ball");


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


                    Double PlayerX = Player.Pos.Value.X;
                    Double PlayerY = Player.Pos.Value.Y;
                    CurrentDistance = Math.Sqrt(Math.Pow(PlayerX - BallX, 2) + Math.Pow(PlayerY - BallY, 2));
                    if (i == 2)
                    {
                        Distance = CurrentDistance;
                        ClosestPlayerToTheBall = 3;
                    }
                    else if (CurrentDistance < Distance)
                    {
                        Distance = CurrentDistance;
                        ClosestPlayerToTheBall = i + 1;
                    }
                }
            }

            return(ClosestPlayerToTheBall);
        }
Exemplo n.º 2
0
        public PointF?GetMostForwardPlayerPossition()
        {
            PointF?mostForwardPos = null;
            var    seenObjects    = m_coach.GetSeenCoachObjects();

            foreach (var seenObject in seenObjects)
            {
                if (seenObject.Key.StartsWith($"player {m_team.m_teamName}"))
                {
                    if (seenObject.Key.StartsWith($"player {m_team.m_teamName} 1"))
                    {
                        //It's Goalie, not relevant.
                        continue;
                    }
                    if (mostForwardPos == null)
                    {
                        mostForwardPos = seenObject.Value.Pos.Value;
                    }
                    else
                    {
                        if (m_side == 'l')
                        {
                            if (seenObject.Value.Pos.Value.X > mostForwardPos.Value.X)
                            {
                                mostForwardPos = seenObject.Value.Pos.Value;
                            }
                        }
                        else
                        {
                            if (seenObject.Value.Pos.Value.X < mostForwardPos.Value.X)
                            {
                                mostForwardPos = seenObject.Value.Pos.Value;
                            }
                        }
                    }
                }
            }
            return(mostForwardPos);
        }
Exemplo n.º 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);
        }