Exemplo n.º 1
0
        public double GetAngleToOpponentGoal()
        {
            PointF opponentGoalPos;

            if (m_side == 'l')
            {
                opponentGoalPos = (PointF)FlagNameToPointF.Convert("goal r");
            }
            else
            {
                opponentGoalPos = (PointF)FlagNameToPointF.Convert("goal l");
            }
            return(GetAngleToPoint(opponentGoalPos));
        }
Exemplo n.º 2
0
        public double GetDistanceToOpponentGoal()
        {
            PointF OpponentGoal;

            if (m_side == 'l')
            {
                OpponentGoal = (PointF)FlagNameToPointF.Convert("goal r");
            }
            else
            {
                OpponentGoal = (PointF)FlagNameToPointF.Convert("goal l");
            }
            return(GetDistanceToPoint(OpponentGoal));
        }
Exemplo n.º 3
0
        private PointF GetBottomLimitPoint()
        {
            PointF bottomLimitPoint;

            if (m_side == 'l')
            {
                bottomLimitPoint = (PointF)FlagNameToPointF.Convert("flag p l b");
            }
            else
            {
                bottomLimitPoint = (PointF)FlagNameToPointF.Convert("flag p r b");
            }
            return(bottomLimitPoint);
        }
Exemplo n.º 4
0
        private PointF GetTopLimitPoint()
        {
            PointF topLimitPoint;

            if (m_side == 'l')
            {
                topLimitPoint = (PointF)FlagNameToPointF.Convert("flag p l t");
            }
            else
            {
                topLimitPoint = (PointF)FlagNameToPointF.Convert("flag p r t");
            }
            return(topLimitPoint);
        }
Exemplo n.º 5
0
        private PointF CalcRelativePossition(PointF ballPoint)
        {
            SeenCoachObject playerPossition = m_coach.GetSeenCoachObject("player " + m_team.m_teamName + " " + m_number);

            if (m_side == 'l')
            {
                if (playerPossition.Pos.Value.X > ballPoint.X)
                {
                    if (ballPoint.X - 2 < -57)
                    {
                        PointF opponentGoalPos = (PointF)FlagNameToPointF.Convert("flag l t");
                        ballPoint.X = -57;
                    }
                    else
                    {
                        ballPoint.X -= 2;
                    }
                    ballPoint.Y -= 5;
                }
            }
            else
            {
                if (playerPossition.Pos.Value.X < ballPoint.X)
                {
                    if (ballPoint.X + 2 > 57)
                    {
                        ballPoint.X = 57;
                    }
                    else
                    {
                        ballPoint.X += 2;
                    }
                    ballPoint.Y += 5;
                }
            }
            return(ballPoint);
        }
Exemplo n.º 6
0
        public override void play()
        {
            // first ,ove to start position
            m_robot.Move(m_startPosition.X, m_startPosition.Y);
            // Move to start possition.
            PointF startPoint;

            if (m_side == 'l')
            {
                startPoint    = (PointF)FlagNameToPointF.Convert("goal l");
                startPoint.X += 1;
            }
            else
            {
                startPoint    = (PointF)FlagNameToPointF.Convert("goal r");
                startPoint.X -= 1;
            }
            while (!goToCoordinate(startPoint, 1))
            {
            }
            TurnToAngle0();  // Turn to the opponent's goal.

            while (!m_timeOver)
            {
                try
                {
                    SeenObject ball = null;
                    SeenObject goal = null;

                    while (ball == null || ball.Distance > 1.5)
                    {
                        //Get field information from god (coach).
                        var ballPosByCoach = m_coach.GetSeenCoachObject("ball");
                        if (ballPosByCoach != null && ballPosByCoach.Pos != null)
                        {
                            //Console.WriteLine($"Ball Position {ballPosByCoach.Pos.Value.X}, {ballPosByCoach.Pos.Value.Y}");
                        }

                        //GetDistanceToBall();

                        //m_memory.waitForNewInfo();
                        //ball = m_memory.GetSeenObject("ball");
                        //if (ball == null)
                        //{
                        //    // If you don't know where is ball then find it
                        //    m_robot.Turn(40);
                        //    m_memory.waitForNewInfo();
                        //}
                        //else if (ball.Distance > 1.5)
                        if (GetDistanceToBall() > 1.5)
                        {
                            if (ballPosByCoach != null && ballPosByCoach.Pos != null)
                            {
                                // Check goal keeper is within field limit.
                                PointF topLimitPoint    = GetTopLimitPoint();
                                PointF bottomLimitPoint = GetBottomLimitPoint();
                                // Run to ball coordibates.
                                bool reachedCoordinate = goToCoordinate(new PointF(ballPosByCoach.Pos.Value.X, ballPosByCoach.Pos.Value.Y), 1, topLimitPoint, bottomLimitPoint);
                                //bool reachedCoordinate = goToCoordinate(CalcRelativePossition(new PointF(ballPosByCoach.Pos.Value.X, ballPosByCoach.Pos.Value.Y)),1, topLimitPoint, bottomLimitPoint);
                            }
                            else
                            {
                                // If ball is too far then
                                // turn to ball or
                                // if we have correct direction then go to ball
                                if (Math.Abs((double)ball.Direction) < 0)
                                {
                                    m_robot.Turn(ball.Direction.Value);
                                    WaitSimulatorStep();
                                }
                                else
                                {
                                    //m_robot.Dash(10 * ball.Distance.Value);
                                    //WaitSimulatorStep();
                                    //WaitSimulatorStep();
                                    DashToPoint(GetBallDetailsByCoach().Pos.Value, 1);
                                }
                            }
                        }
                        else  // ball.Distance <= 1.5, so we can catch the ball.
                        {
                            ball = m_memory.GetSeenObject("ball");
                            while (ball == null)
                            {
                                // If you don't know where is ball then find it
                                m_robot.Turn(40);
                                WaitSimulatorStep();

                                //m_memory.waitForNewInfo();
                                //Thread.Sleep(SoccerParams.simulator_step);
                                ball = m_memory.GetSeenObject("ball");
                            }
                            m_robot.Catch(ball.Direction.Value);
                            WaitSimulatorStep();
                            TurnToAngle0();

                            m_robot.Move(-40, 15);
                            WaitSimulatorStep();
                            double angleTo0    = GetAngleTo0();
                            double angleToBall = GetAngleToPoint(new PointF(ballPosByCoach.Pos.Value.X, ballPosByCoach.Pos.Value.Y));

                            //Console.WriteLine($"BEFORE angleToBall: {angleToBall}");
                            if ((angleToBall > 160) && (angleToBall < 200))
                            {
                                angleTo0 += 90;
                            }
                            else if ((angleToBall < -160) && (angleToBall > -200))
                            {
                                angleTo0 += 90;
                            }


                            m_robot.Kick(100, angleTo0);
                            WaitSimulatorStep();
                            //Console.WriteLine($"Kick angleTo0: {angleTo0}");
                            //Console.WriteLine($"angleToBall: {angleToBall}");
                        }
                    }
                }
                catch (Exception e) { }

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

                //}
            }  // DROR
        }
Exemplo n.º 7
0
        public override void play()
        {
            // first ,ove to start position
            m_robot.Move(m_startPosition.X, m_startPosition.Y);

            while (!m_timeOver)
            {
                while (true)
                {
                    while (true)
                    {
                        try
                        {
                            if (goToBallCoordinates(1))
                            {
                                break;
                            }
                            WaitSimulatorStep();
                        }
                        catch (Exception e) { }
                    }
                    var targetPos = (PointF)FlagNameToPointF.Convert("flag c b");
                    targetPos.Y -= 1;

                    PassToPossition(targetPos);
                    WaitSimulatorStep();
                    var dist = GetDistanceBetween2Points(
                        (PointF)FlagNameToPointF.Convert("flag c b"),
                        GetBallDetailsByCoach().Pos.Value);
                    if (dist < 1)
                    {
                        break;
                    }
                }

                while (true)
                {
                    try
                    {
                        if (goToBallCoordinates(1))
                        {
                            break;
                        }
                        WaitSimulatorStep();
                    }
                    catch (Exception e) { }
                }
                PassToPossition(((PointF)FlagNameToPointF.Convert("flag c")));


                SeenObject ball = null;
                SeenObject goal = null;

                //Get current player's info:
                var bodyInfo = GetBodyInfo();
                Console.WriteLine($"Kicks so far : {bodyInfo.Kick}");

                while (ball == null || ball.Distance > 1.5)
                {
                    //Get field information from god (coach).
                    var ballPosByCoach = m_coach.GetSeenCoachObject("ball");
                    if (ballPosByCoach != null && ballPosByCoach.Pos != null)
                    {
                        Console.WriteLine($"Ball Position {ballPosByCoach.Pos.Value.X}, {ballPosByCoach.Pos.Value.Y}");
                    }

                    m_memory.waitForNewInfo();
                    ball = m_memory.GetSeenObject("ball");
                    if (ball == null)
                    {
                        // If you don't know where is ball then find it
                        m_robot.Turn(40);
                        m_memory.waitForNewInfo();
                    }
                    else if (ball.Distance > 1.5)
                    {
                        // If ball is too far then
                        // turn to ball or
                        // if we have correct direction then go to ball
                        if (Math.Abs((double)ball.Direction) < 0)
                        {
                            m_robot.Turn(ball.Direction.Value);
                        }
                        else
                        {
                            m_robot.Dash(10 * ball.Distance.Value);
                        }
                    }
                }

                // We know where is ball and we can kick it
                // so look for goal

                while (goal == null)
                {
                    m_memory.waitForNewInfo();
                    if (m_side == 'l')
                    {
                        goal = m_memory.GetSeenObject("goal r");
                    }
                    else
                    {
                        goal = m_memory.GetSeenObject("goal l");
                    }

                    if (goal == null)
                    {
                        m_robot.Turn(40);
                    }
                }

                m_robot.Kick(100, goal.Direction.Value);
            }

            // sleep one step to ensure that we will not send
            // two commands in one cycle.
            WaitSimulatorStep();
        }