Exemple #1
0
        //public override void play()
        //      {
        //	//////////// Goal Keeper //////////////
        //	// GoToPosition( (float)-52.5, (float) 0.0);
        //	///////////////////////////////////////

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

        //	while (!m_timeOver)
        //          {
        //		var currentPosition = m_coach.GetMyPos(PlayerNumber);
        //		if (currentPosition != null)
        //		{
        //			// check if we are in borders
        //			if (!m_borders.IsInBorders(currentPosition.Pos.Value))
        //			{
        //				GoToPosition(m_startPosition.X, m_startPosition.Y);
        //			}
        //		}
        //		//else
        //		//{
        //		//	continue;
        //		//}

        //		//var ballPosition = m_coach.GetBall();
        //		//if (ballPosition != null)
        //		//{
        //		//	// check if ball is in borders
        //		//	if (m_borders.IsInBorders(ballPosition.Pos.Value))
        //		//	{
        //		//		var bodyInfo = GetBodyInfo();

        //		//		obj = m_memory.GetSeenObject("ball");
        //		//		if (obj == null)
        //		//		{
        //		//			// If you don't know where is ball then find it
        //		//			m_robot.Turn(40);
        //		//			m_memory.waitForNewInfo();
        //		//		}
        //		//		//else if (obj.Distance.Value > 1.5)
        //		//		else if (obj.Distance.Value > 1.0)
        //		//		{
        //		//			// If ball is too far then
        //		//			// turn to ball or
        //		//			// if we have correct direction then go to ball
        //		//			if (obj.Direction.Value != 0)
        //		//				m_robot.Turn(obj.Direction.Value);
        //		//			else
        //		//				m_robot.Dash(10 * obj.Distance.Value);
        //		//		}
        //		//		else
        //		//		{
        //		//			// We know where is ball and we can kick it
        //		//			// so look for goal
        //		//			if (m_side == 'l')
        //		//				obj = m_memory.GetSeenObject("goal r");
        //		//			else
        //		//				obj = m_memory.GetSeenObject("goal l");

        //		//			if (obj == null)
        //		//			{
        //		//				m_robot.Turn(40);
        //		//				m_memory.waitForNewInfo();
        //		//			}
        //		//			else
        //		//				m_robot.Kick(200, obj.Direction.Value);
        //		//		}

        //		//		// 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)
        //		//		{

        //		//		}

        //		//		//if (LogicCalc.GetDistance(currentPosition.Pos.Value.X, currentPosition.Pos.Value.Y, ballPosition.Pos.Value.X, ballPosition.Pos.Value.Y) < 1.5)
        //		//		//{
        //		//		//	var obj = m_memory.GetSeenObject("goal r");
        //		//		//	if (obj == null)
        //		//		//	{
        //		//		//		m_robot.Turn(40);
        //		//		//		m_memory.waitForNewInfo();
        //		//		//	}
        //		//		//	else
        //		//		//		m_robot.Kick(200, obj.Direction.Value);
        //		//		//}
        //		//		//else
        //		//		//{
        //		//		//	GoToPosition(ballPosition.Pos.Value.X, ballPosition.Pos.Value.Y);
        //		//		//}
        //		//	}
        //		//}

        //		//// m_robot.Dash(PlayerNumber);
        //		//m_robot.Turn(30);
        //  //        }
        //  //    }


        public override void play()
        {
            SeenObject obj;

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

            while (!m_timeOver)
            {
                // Get ball position from coach
                var ballPosition = m_coach.GetBall();
                if (ballPosition == null)                 // No ball position
                {
                    continue;
                }
                else
                {
                    if (!m_borders.IsInBorders(ballPosition.Pos.Value))
                    {
                        continue;                         // Ball is not in borders
                    }
                }

                var bodyInfo = GetBodyInfo();

                obj = m_memory.GetSeenObject("ball");
                if (obj == null)
                {
                    // If you don't know where is ball then find it
                    if (stuckCounter > 8)
                    {
                        stuckCounter = 0;
                        if (obj != null)
                        {
                            m_robot.Turn(180 - obj.Direction.Value);
                        }
                        m_robot.Dash(200);
                    }
                    else
                    {
                        stuckCounter++;
                        m_robot.Turn(45);
                        m_memory.waitForNewInfo();
                    }
                }
                //else if (obj.Distance.Value > 1.5)
                else if (obj.Distance.Value > 1.0)
                {
                    // If ball is too far then
                    // turn to ball or
                    // if we have correct direction then go to ball
                    if (obj.Direction.Value != 0)
                    {
                        m_robot.Turn(obj.Direction.Value);
                    }
                    else
                    {
                        m_robot.Dash(10 * obj.Distance.Value);
                    }
                }
                else
                {
                    // We know where is ball and we can kick it
                    // so look for goal
                    if (m_side == 'l')
                    {
                        obj = m_memory.GetSeenObject("goal r");
                    }
                    else
                    {
                        obj = m_memory.GetSeenObject("goal l");
                    }

                    if (obj == null)
                    {
                        m_robot.Turn(41);
                        m_memory.waitForNewInfo();
                    }
                    else
                    {
                        m_robot.Kick(200, obj.Direction.Value);
                    }
                }

                var currentPosition = m_coach.GetMyPos(PlayerNumber);
                if (currentPosition != null)
                {
                    // check if we are in borders
                    if (!m_borders.IsInBorders(currentPosition.Pos.Value))
                    {
                        GoToPosition(m_startPosition.X, m_startPosition.Y);
                    }
                }
                else
                {
                    continue;
                }
                // 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)
                {
                }
            }
        }
Exemple #2
0
        public override void play()
        {
            if (m_side == 'r')
            {
                m_borders.chageSide((float)-1);        //fix borders acording to side
                m_startPosition.X = m_startPosition.X * -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);
                        }
                        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
                            {
                                // We know where is ball and we can kick it
                                // so look for goal
                                if (m_side == 'l')
                                {
                                    var goalR = m_memory.GetSeenObject("goal r");
                                    if (goalR != null && goalR.Distance.Value > 20)
                                    {
                                        Kick(FieldLocations.RightLine, 0, 30);                                 // TODO: kick forward
                                    }
                                    else
                                    {
                                        Kick(FieldLocations.RightLine, 0, 100);                              // TODO: kick to angel
                                    }
                                }

                                else
                                {
                                    var goalL = m_memory.GetSeenObject("goal l");
                                    if (goalL != null && goalL.Distance.Value > 20)
                                    {
                                        Kick(FieldLocations.LeftLine, 0, 30);                                 // TODO: kick forward
                                    }
                                    else
                                    {
                                        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)
                {
                }
            }
        }