コード例 #1
0
        protected void GoToPosition(float x, float y)
        {
            var seenCoachObject = m_coach.GetMyPos(PlayerNumber);

            if (seenCoachObject == null)
            {
                return;
            }

            var pos = seenCoachObject.Pos;

            var angel = GetAngleToPoint(new PointF(x, y), seenCoachObject);

            if (Math.Abs(angel) > 10)
            {
                m_robot.Turn(angel);
            }
            else
            {
                var   dis   = LogicCalc.GetDistance(x, y, pos.Value.X, pos.Value.Y);
                float power = (float)10 * (float)dis;
                if (power > 70)
                {
                    power = 70;
                }
                m_robot.Dash(power);
            }
        }
コード例 #2
0
        public Dictionary <string, double> GetNymberOfNerestPlayers()
        {
            var myPlayers = m_coach.GetMyPlayers(m_number);
            var ball      = m_coach.GetBall();
            var dic       = new Dictionary <string, double>();

            foreach (var myPlayer in myPlayers)
            {
                var dis = LogicCalc.GetDistance(myPlayer.Pos.Value, ball.Pos.Value);
                dic.Add(myPlayer.Name, dis);
            }
            return(dic);
        }
コード例 #3
0
        private void GoToPositionOneStep(float x, float y)
        {
            var seenCoachObject = m_coach.GetMyPos(PlayerNumber);

            while (seenCoachObject == null)
            {
                m_memory.waitForNewInfo();
                seenCoachObject = m_coach.GetMyPos(PlayerNumber);
            }
            var pos   = seenCoachObject.Pos;
            var angel = LogicCalc.GetAngleBetweenTwoPoints(pos.Value.X, pos.Value.Y, x, y);

            m_robot.Turn((double)(angel + seenCoachObject.BodyAngle) % 360);
            bool   isInPos  = false;
            double?last_dis = null;

            //        while(!isInPos && !m_timeOver)
            //        {
            /////
            Console.WriteLine(pos.Value.X.ToString() + ", " + pos.Value.Y.ToString());
            ///
            seenCoachObject = m_coach.GetMyPos(PlayerNumber);
            pos             = seenCoachObject.Pos;

            var dis = LogicCalc.GetDistance(x, y, pos.Value.X, pos.Value.Y);

            System.Console.WriteLine($"{dis}");
            if (last_dis != null)
            {
                angel = LogicCalc.GetAngleBetweenTwoPoints(pos.Value.X, pos.Value.Y, x, y);
                if (Math.Abs((double)(angel - seenCoachObject.BodyAngle)) > 10)
                {
                    m_robot.Turn((double)(angel - seenCoachObject.BodyAngle));
                }
                else if (dis > last_dis.Value)
                {
                    m_robot.Turn((double)(angel + seenCoachObject.BodyAngle) % 360);
                }
            }
            last_dis = dis;
            if (dis < 1.5)
            {
                return;
            }
            m_robot.Dash(100);
            m_memory.waitForNewInfo();
            //}
        }
コード例 #4
0
        public bool NeedToPass()
        {
            var myPlayer        = m_coach.GetMyPos(m_number);
            var opponentPlayers = m_coach.GetOpponentPlayers();
            int num             = 0;

            int attcker2;

            if (m_number == 1)
            {
                attcker2 = 2;
            }
            else
            {
                attcker2 = 1;
            }

            var attcker2Pos = m_coach.GetMyPos(attcker2);

            if (attcker2Pos != null)
            {
                var dist = LogicCalc.GetDistance(myPlayer.Pos.Value, attcker2Pos.Pos.Value);
                if (dist < 10)
                {
                    return(false);
                }
                if (attcker2Pos.Pos.Value.X < myPlayer.Pos.Value.X)
                {
                    return(false);                                                                      //Pass only Fwd
                }
            }

            foreach (var opponentPlayer in opponentPlayers)
            {
                var dis = LogicCalc.GetDistance(myPlayer.Pos.Value, opponentPlayer.Pos.Value);
                if (dis < 10)
                {
                    num += 1;
                    if (num >= 2)
                    {
                        return(true);
                    }
                }
            }
            return(num >= 2);
        }
コード例 #5
0
        public Dictionary <string, double> GetNymberOfNerestPlayers(float r)
        {
            var myPlayers       = m_coach.GetMyPlayers(m_number);
            var opponentPlayers = m_coach.GetOpponentPlayers();
            var dic             = new Dictionary <string, double>();

            foreach (var myPlayer in myPlayers)
            {
                dic.Add(myPlayer.Name, 0);
                foreach (var opponentPlayer in opponentPlayers)
                {
                    var dis = LogicCalc.GetDistance(myPlayer.Pos.Value, opponentPlayer.Pos.Value);
                    if (dis < r)
                    {
                        dic[myPlayer.Name] += 1;
                    }
                }
            }
            return(dic);
        }
コード例 #6
0
        public PointF GetNerestPlayerInMyBoarder()
        {
            var    myPlayers = m_coach.GetOpponentPlayers();
            var    me        = m_coach.GetMyPos(m_number);
            PointF minPos    = m_startPosition;
            double dis       = double.MinValue;

            foreach (var player in myPlayers)
            {
                if (m_borders.IsInBorders(player.Pos.Value))
                {
                    var disTemp = LogicCalc.GetDistance(player.Pos.Value, me.Pos.Value);
                    if (disTemp < dis)
                    {
                        dis    = disTemp;
                        minPos = player.Pos.Value;
                    }
                }
            }
            return(minPos);
        }
コード例 #7
0
        public override PointF GetNextPlayerToPass(out double distance)
        {
            //

            int attcker2;

            if (m_number == 1)
            {
                attcker2 = 2;
            }
            else
            {
                attcker2 = 1;
            }

            var myPlayer    = m_coach.GetMyPos(m_number);
            var attcker2Pos = m_coach.GetMyPos(attcker2);

            if (attcker2Pos != null)
            {
                distance = LogicCalc.GetDistance(myPlayer.Pos.Value, attcker2Pos.Pos.Value);
                return(attcker2Pos.Pos.Value);
            }
            else
            {
                var nib = GetNymberOfNerestPlayers(20);
                var dis = GetNymberOfNerestPlayers();

                var name1 = dis.FirstOrDefault(x => x.Value == dis.Values.Min()).Key;
                var dis1  = dis[name1];
                dis.Remove(name1);
                var name2 = dis.FirstOrDefault(x => x.Value == dis.Values.Min()).Key;
                var dis2  = dis[name2];
                var pos   = m_coach.GetPlayer(nib[name1] < nib[name2] ? name1 : name2);

                distance = nib[name1] < nib[name2] ? dis1 : dis2;
                return(pos.Pos.Value);
            }
        }
コード例 #8
0
        public override void play()
        {
            float sideFactor = 1;

            if (m_side == 'r')
            {
                m_borders.chageSide((float)-1);                        //fix borders acording to side
                m_startPosition.X = m_startPosition.X * -1;
                sideFactor        = -1;
            }

            // First go to start position
            GoToPosition(m_startPosition.X, m_startPosition.Y);

            while (!m_timeOver)
            {
                try
                {
                    //var memory = m_memory.getBodyInfo();
                    //if (memory != null)
                    //	Console.WriteLine("PLayer: " + m_number + ", " + memory.StaminaValue);

                    // Get ball position from coach
                    var coachBall = m_coach.GetBall();
                    if (coachBall == null)
                    {
                        // No ball position
                    }
                    else
                    {
                        if (!m_borders.IsInBorders(coachBall.Pos.Value))
                        {
                            // Ball is not in borders
                            // Go To start position TODO: something else

                            //GoToPosition(m_startPosition.X, m_startPosition.Y);

                            if (m_side == 'l' && coachBall.Pos.Value.X > 10)
                            {
                                GoToPosition(m_startPosition.X + 15, m_startPosition.Y);
                            }
                            else if (m_side == 'r' && coachBall.Pos.Value.X < -10)
                            {
                                GoToPosition(m_startPosition.X - 15, m_startPosition.Y);
                            }
                            else
                            {
                                GoToPosition(m_startPosition.X, m_startPosition.Y);
                            }
                        }
                        else
                        {
                            var bodyInfo = GetBodyInfo();

                            var myBall = m_memory.GetSeenObject("ball");
                            if (myBall == null)
                            {
                                // If you don't know where is ball then find it
                                var angel = GetAngleToPoint(coachBall.Pos.Value);
                                m_robot.Turn(angel);
                            }
                            else if (myBall.Distance.Value > 1.3)
                            {
                                // If ball is too far then
                                // turn to ball or
                                // if we have correct direction then go to ball
                                //if (obj.Direction.Value != 0)
                                if (myBall.Direction.Value > 20)
                                {
                                    m_robot.Turn(myBall.Direction.Value);
                                }
                                else
                                {
                                    m_robot.Dash(10 * myBall.Distance.Value);
                                }
                            }
                            else
                            {
                                float Gx;
                                float Gy = 0;
                                if (m_side == 'l')
                                {
                                    Gx = FieldLocations.LeftLine;
                                }
                                else
                                {
                                    Gx = FieldLocations.RightLine;
                                }
                                var myPos = m_coach.GetMyPos(m_number);
                                var dis   = LogicCalc.GetDistance(Gx, Gy, myPos.Pos.Value.X, myPos.Pos.Value.Y);
                                // We know where is ball and we can kick it
                                // so look for goal
                                if (m_side == 'l')
                                {
                                    if (dis > 25)
                                    {
                                        if (NeedToPass())
                                        {
                                            var   p         = GetNextPlayerToPass(out double distance);
                                            float powerPass = 100;
                                            if (distance >= 20)
                                            {
                                                powerPass = 100;
                                            }
                                            else
                                            {
                                                powerPass = ((float)distance / 20) * 100;
                                            }
                                            Kick(p.X, p.Y, powerPass);
                                        }
                                        else
                                        {
                                            Kick(FieldLocations.RightLine, 0, 20);                                             // TODO: kick forward
                                        }
                                    }
                                    else
                                    {
                                        double angel = ShotToGoal();
                                        m_robot.Kick(100, angel);
                                        //Kick(FieldLocations.LeftLine, 0, 100); // TODO: kick to angel
                                    }
                                }
                                else
                                {
                                    if (dis > 25)
                                    {
                                        if (NeedToPass())
                                        {
                                            var p = GetNextPlayerToPass(out double distance);

                                            float powerPass = 100;
                                            if (distance >= 20)
                                            {
                                                powerPass = 100;
                                            }
                                            else
                                            {
                                                powerPass = ((float)distance / 20) * 100;
                                            }
                                            Kick(p.X, p.Y, powerPass);
                                        }
                                        else
                                        {
                                            Kick(FieldLocations.LeftLine, 0, 20);                                             // TODO: kick forward
                                        }
                                    }
                                    else
                                    {
                                        double angel = ShotToGoal();
                                        m_robot.Kick(100, angel);
                                        //Kick(FieldLocations.LeftLine, 0, 100); // TODO: kick to angel
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                }

                // sleep one step to ensure that we will not send
                // two commands in one cycle.
                try
                {
                    Thread.Sleep(2 * SoccerParams.simulator_step);
                }
                catch (Exception e)
                {
                }
            }             // play()
        }
コード例 #9
0
        public override void play()
        {
            SeenCoachObject last_ball_pos = null;
            float           goalLine;

            if (m_side == 'l')
            {
                goalLine = FieldLocations.LeftLine;
            }
            else
            {
                goalLine = FieldLocations.RightLine;
            }

            SeenObject obj;


            while (!m_timeOver)
            {
                try
                {
                    // Get ball position from coach
                    var coachBall = m_coach.GetBall();



                    if (coachBall == null)
                    {
                        // No ball position
                        GoToPosition(goalLine, (float)0);
                    }
                    else
                    {
                        last_ball_pos = coachBall;

                        if (!m_borders.IsInBorders(coachBall.Pos.Value))
                        {
                            // Ball is not in borders

                            var disAB   = LogicCalc.GetDistance(last_ball_pos.Pos.Value.X, last_ball_pos.Pos.Value.Y, goalLine, (float)7);
                            var disAC   = LogicCalc.GetDistance(last_ball_pos.Pos.Value.X, last_ball_pos.Pos.Value.Y, goalLine, (float)-7);
                            var yGK_Pos = 7 - ((14 * (disAB / disAC)) / (1 + (disAB / disAC)));
                            GoToPosition(goalLine, (float)yGK_Pos);
                        }
                        else
                        {
                            obj = m_memory.GetSeenObject("ball");
                            if (obj == null)
                            {
                                // If you don't know where is ball then find it
                                var ball = m_coach.GetBall();
                                if (ball != null)
                                {
                                    var angel = GetAngleToPoint(ball.Pos.Value);
                                    m_robot.Turn(angel);
                                }
                                else
                                {
                                    m_robot.Turn(40);
                                }
                                m_memory.waitForNewInfo();
                            }

                            else if (obj.Distance.Value > 1.3)
                            {
                                // If ball is too far then
                                // turn to ball or
                                // if we have correct direction then go to ball
                                //if (obj.Direction.Value != 0)
                                if (obj.Direction.Value > 20)
                                {
                                    m_robot.Turn(obj.Direction.Value);
                                }
                                else
                                {
                                    m_robot.Dash(20 * obj.Distance.Value);
                                }
                            }
                            else
                            {
                                // We know where is ball and we can kick it
                                // so look for goal
                                var   p         = GetNextPlayerToPass(out double distance);
                                float powerPass = 100;
                                if (distance >= 20)
                                {
                                    powerPass = 100;
                                }
                                else
                                {
                                    powerPass = ((float)distance / 20) * 100;
                                }
                                Kick(p.X, p.Y, powerPass);

                                //if (m_side == 'l')
                                //{
                                //	obj = m_memory.GetSeenObject("goal r");
                                //	var pos = GetNextPlayerToPass();
                                //	Kick(pos.X, pos.Y, 100);
                                //}

                                //else
                                //{
                                //	obj = m_memory.GetSeenObject("goal l");
                                //	var pos = GetNextPlayerToPass();
                                //	Kick(pos.X, pos.Y, 100);
                                //}
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                }

                // sleep one step to ensure that we will not send
                // two commands in one cycle.
                try
                {
                    Thread.Sleep(2 * SoccerParams.simulator_step);
                }
                catch (Exception e)
                {
                }
            }



            //		//////////////////////////////////////////////////////////
            //		var ball_info = m_coach.GetBall();
            //if (ball_info != null)
            //{
            //	last_ball_pos = ball_info;
            //	m_memory.waitForNewInfo();
            //}

            ////triangle ABC: A is the ball, BC is goal
            //if (!m_borders.IsInBorders(last_ball_pos.Pos.Value))
            //{
            //	var disAB = LogicCalc.GetDistance(last_ball_pos.Pos.Value.X, last_ball_pos.Pos.Value.Y, goalLine, (float)7);
            //	var disAC = LogicCalc.GetDistance(last_ball_pos.Pos.Value.X, last_ball_pos.Pos.Value.Y, goalLine, (float)-7);
            //	var yGK_Pos = 7 - ((14 * (disAB / disAC)) / (1 + (disAB / disAC)));
            //	GoToPosition(FieldLocations.LeftLine, (float)yGK_Pos);
            //}

            //if (ball_info != null)
            //{
            //	//var dis = LogicCalc.GetDistance(ball_info.Pos.Value.X, ball_info.Pos.Value.Y, FieldLocations.LeftLine, (float)yGK_Pos);
            //	//if (dis < 1.5)
            //	//{
            //	//	//Kick(0,0,100);
            //	//	m_robot.Kick(100, 45);
            //	//}

            //	obj = m_memory.GetSeenObject("ball");
            //	if (obj == null)
            //	{
            //		// If you don't know where is ball then find it
            //		var ball = m_coach.GetBall();
            //		if (ball != null)
            //		{
            //			var angel = GetAngleToPoint(ball.Pos.Value);
            //			m_robot.Turn(angel);
            //		}
            //		else
            //		{
            //			m_robot.Turn(40);
            //		}
            //		m_memory.waitForNewInfo();
            //	}

            //	else if (obj.Distance.Value > 1.3)
            //	{
            //		// If ball is too far then
            //		// turn to ball or
            //		// if we have correct direction then go to ball
            //		//if (obj.Direction.Value != 0)
            //		if (obj.Direction.Value > 20)
            //			m_robot.Turn(obj.Direction.Value);
            //		else
            //			m_robot.Dash(20 * obj.Distance.Value);
            //	}
            //	else
            //	{
            //		// We know where is ball and we can kick it
            //		// so look for goal
            //		var p = GetNextPlayerToPass(out double distance);
            //		float powerPass = 100;
            //		if (distance >= 20) powerPass = 100;
            //		else powerPass = ((float)distance / 20) * 100;
            //		Kick(p.X, p.Y, powerPass);

            //		//if (m_side == 'l')
            //		//{
            //		//	obj = m_memory.GetSeenObject("goal r");
            //		//	var pos = GetNextPlayerToPass();
            //		//	Kick(pos.X, pos.Y, 100);
            //		//}

            //		//else
            //		//{
            //		//	obj = m_memory.GetSeenObject("goal l");
            //		//	var pos = GetNextPlayerToPass();
            //		//	Kick(pos.X, pos.Y, 100);
            //		//}

            //	}

            //}
        }