protected float GetDistanceFrom(PointF point) { SeenCoachObject myObj = GetCurrPlayer(); var distance = Utils.Distance(point, myObj.Pos.Value); return(distance); }
public SeenCoachObject GetSeenCoachObject(string name) { SeenCoachObject result = null; var obj = m_seenCoachObjects.TryGetValue(name, out result); return(result); }
public PlayersData GetPlayersFullData(SeenCoachObject me) { var status = GetPlayersData(); PlayersData ret = new PlayersData() { MyPlayers = new Dictionary <SeenCoachObject, PlayerData>(), OpponentPlayers = new Dictionary <SeenCoachObject, PlayerData>() }; foreach (var player in status.MyPlayers) { ret.MyPlayers.Add(player, new PlayerData() { Angle = GetAngle(me, player), Distance = GetDistance(me, player), DistanceFromBall = GetDistanceFromBall(player) }); } foreach (var player in status.OpponentPlayers) { ret.OpponentPlayers.Add(player, new PlayerData() { Angle = GetAngle(me, player), Distance = GetDistance(me, player), DistanceFromBall = GetDistanceFromBall(player) }); } return(ret); }
private void KickOrMoveWithBall(SeenCoachObject player, double power, double distanceToBall, double directiontoGoal, SeenCoachObject ball) { if (Math.Abs(distanceToBall) < 10 && Math.Abs(player.BodyAngle.Value) > 95) { PointF point = new PointF() { X = ball.Pos.Value.X, Y = ball.Pos.Value.Y + 10 }; goToCoordinate(point, 0); } else if (NearBoal(distanceToBall)) { if (Math.Abs(player.BodyAngle.Value) > 95) { m_robot.Kick(-30, directiontoGoal); } else { m_robot.Kick(power, directiontoGoal); } } else { goToCoordinate(ball.Pos.Value, DistFromBallToKick); } }
private void SetGaol() { string goalStr = (m_side == 'l') ? "goal r" : "goal l"; while (goal == null) { goal = m_coach.GetSeenCoachObject(goalStr); } }
public double GetAngleToPoint(PointF targetPoint, SeenCoachObject myPosByCoach) { var angleToTarget = Calc2PointsAngleByXAxis(myPosByCoach.Pos.Value, targetPoint); var myAbsAngle = myPosByCoach.BodyAngle; var turnAngle = -1 * (Convert.ToDouble(myAbsAngle) + angleToTarget); var fixedAngle = NormalizeTo180(turnAngle); return(turnAngle); }
private bool CheckBallInMyHalf(SeenCoachObject ball) { if (m_side == 'r') { return(ball.Pos.Value.X >= 0); } else { return(ball.Pos.Value.X <= 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); }
public virtual int FindAtackerClosestToTheBall() { 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 = 0; i < 2; 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 == 0) { Distance = CurrentDistance; ClosestPlayerToTheBall = 1; } else if (CurrentDistance < Distance) { Distance = CurrentDistance; ClosestPlayerToTheBall = i + 1; } } } return(ClosestPlayerToTheBall); }
public double GetAngle(SeenCoachObject me, SeenCoachObject player) { var angle = Math.Atan2(me.Pos.Value.Y - player.Pos.Value.Y, me.Pos.Value.X - player.Pos.Value.X) * 180 / Math.PI - me.BodyAngle.Value; if (angle > 180) { angle -= 360; } if (angle < -180) { angle += 360; } return(angle); }
private void Kick(SeenCoachObject player, SeenCoachObject ball, double distanceToBall) { SetGaol(); var distanceToGate = GetDistanceToPoint(goal.Pos.Value); var directiontoGoal = GetAngleToPoint(goal.Pos.Value); var angleToGoal = GetAngleToPoint(ball.Pos.Value); if (distanceToGate < 18) { KickOrMoveWithBall(player, 100, distanceToBall, directiontoGoal, ball); } else { KickOrMoveWithBall(player, 30, distanceToBall, directiontoGoal, ball); } }
public SeenCoachObject GetNearestPlayerAvialible(SeenCoachObject me) { PlayersData dic = GetPlayersFullData(me); PlayerData best_player_data = new PlayerData(); best_player_data.Angle = 0; best_player_data.Distance = 100; SeenCoachObject best_player_obj = me; foreach (var p in dic.MyPlayers) { if (p.Value.Distance > 0.5 && p.Value.Distance < best_player_data.Distance && PlayerAvialible(p.Value.Angle, dic.OpponentPlayers)) { best_player_data = p.Value; best_player_obj = p.Key; } } return(best_player_obj); }
public bool CheckQuerter(Quarter quarter, SeenCoachObject obj) { int XBOUNDRY = -20; bool result = false; switch (quarter) { case Quarter.LeftUp: if ((obj.Pos.Value.X) <= XBOUNDRY && (obj.Pos.Value.X) >= -50 && (obj.Pos.Value.Y) <= 0 && (obj.Pos.Value.Y) >= -30) { result = true; } break; case Quarter.LeftDown: if ((obj.Pos.Value.X) <= XBOUNDRY && (obj.Pos.Value.X) >= -50 && (obj.Pos.Value.Y) >= 0 && (obj.Pos.Value.Y) <= 30) { result = true; } break; case Quarter.RightUp: if ((obj.Pos.Value.X) >= XBOUNDRY && (obj.Pos.Value.X) <= 50 && (obj.Pos.Value.Y) <= 0 && (obj.Pos.Value.Y) >= -30) { result = true; } break; case Quarter.RightDown: if ((obj.Pos.Value.X) >= XBOUNDRY && (obj.Pos.Value.X) <= 50 && (obj.Pos.Value.Y) >= 0 && (obj.Pos.Value.Y) <= 30) { result = true; } break; } return(result); }
private void ParseLookMessage(string message) { if (!message.StartsWith("(ok look")) { return; } var objectsMatch = Regex.Matches(message, MagicPattern); var tmpDictionary = new Dictionary <String, SeenCoachObject>(); for (int i = 0; i < objectsMatch.Count; i++) { var obj = objectsMatch[i]; var innerObjects = obj.Value.Split(')'); var name = innerObjects[0].Substring(2); var parameters = innerObjects[1].Substring(1).Split(' '); var floatParams = parameters.Select(strParam => float.Parse(strParam)).ToArray(); var seenObject = new SeenCoachObject(name, floatParams); tmpDictionary.Add(name, seenObject); } m_seenCoachObjects = tmpDictionary; }
public float CalcAngleToPoint(PointF point) { SeenCoachObject myObj = GetCurrPlayer(); var myAngle = myObj.BodyAngle.Value; var xp = myObj.Pos.Value.X; var yp = myObj.Pos.Value.Y; float deltaY = point.Y - yp; float deltaX = point.X - xp; if (deltaX == 0) // Prevent division by 0 { deltaX += 0.001f; } float alphaPlayerToTargetRad = (float)Math.Atan(deltaY / deltaX); float alphaPlayerToTarget = Utils.RadToDeg(alphaPlayerToTargetRad); float relAngle = 0; if ((deltaY > 0 && deltaX > 0) || (deltaY < 0 && deltaX > 0)) // alpha > 0 { relAngle = -myAngle + alphaPlayerToTarget; } else // alpha < 0 { relAngle = -myAngle - (180 - alphaPlayerToTarget); } relAngle = Utils.NormalizeAngle(relAngle); // Correct the angle (for the case of deltaX ~ 0) var absAngle = Utils.NormalizeAngle(myAngle + relAngle); if ((deltaY > 0 && absAngle < 0) || (deltaY < 0 && absAngle > 0)) { relAngle *= -1; } return(relAngle); }
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); }
public static List <double> GetAllForbiddenAngle(SeenCoachObject myPos, List <System.Drawing.PointF> playetPos, GoalDirection goalDirection) { List <double> angels = new List <double>(); float GBx, GTx; float GTy = FieldLocations.TopGoal; float GBy = FieldLocations.ButtomGoal; if (goalDirection == GoalDirection.Left) { GTx = FieldLocations.LeftLine; GBx = FieldLocations.LeftLine; } else { GTx = FieldLocations.RightLine; GBx = FieldLocations.RightLine; } var angle = GetAngleToPoint(myPos, GBx, GBy); angels.Add(angle); angle = GetAngleToPoint(myPos, GTx, GTy); angels.Add(angle); foreach (var point in playetPos) { if (isPointInTriangle(myPos.Pos.Value.X, myPos.Pos.Value.Y, GTx, GTy, GBx, GBy, point.X, point.Y)) { angle = GetAngleToPoint(myPos, point.X, point.Y); angels.Add(angle); } } angels.Sort(); return(angels); }
public override void play() { // first ,ove to start position m_robot.Move(m_startPosition.X, m_startPosition.Y); while (!m_timeOver) { Quarter quarter = m_side == 'l' ? Quarter.RightDown : Quarter.LeftUp; Quarter q2 = m_side == 'l' ? Quarter.RightUp : Quarter.LeftDown; var ballObj1 = m_coach.GetSeenCoachObject("ball"); if (CheckQuerter(quarter, ballObj1) || CheckQuerter(q2, ballObj1)) { 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) { SeenCoachObject myPlayer = m_coach.GetSeenCoachObject($"player Brazil {m_number}"); //Get field information from god (coach). 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) { // var player2 = m_coach.GetSeenCoachObject($"player Brazil 4"); // var ballobj = m_coach.GetSeenCoachObject("ball"); // if (Math.Abs(myPlayer.AngleTo(ballobj) - myPlayer.AngleTo(player2)) < 3) //{ // var angleToBall = myPlayer.AngleToBallX(ballobj.Pos.Value.X, myPlayer.Pos.Value.Y); // if (Math.Abs(angleToBall) > 0.5) // { // m_robot.Turn(angleToBall); // } // else // { // m_robot.Dash(50); // } //} if (Math.Abs(ball.Direction.Value) > 0.7) { m_robot.Turn(ball.Direction.Value); } else { m_robot.Dash(120 * ball.Distance.Value); } } } // We know where is ball and we can kick it // so look for goal var goalstr = m_side == 'l' ? "goal r" : "goal l"; var angle = 10; while (goal == null) { m_memory.waitForNewInfo(); goal = m_memory.GetSeenObject(goalstr); if (goal == null) { m_robot.Turn(40); } } var myPlayer2 = m_coach.GetSeenCoachObject($"player Brazil {m_number}"); var ballObj = m_coach.GetSeenCoachObject("ball"); var atk = myPlayer2.AngleToKick(ballObj); if (Math.Abs(atk) > 120) { m_robot.Kick(7, 90); } //var player2 = m_coach.GetSeenCoachObject($"player Brazil 4"); //var coachGoalObject = m_coach.GetSeenCoachObject(goalstr); //if (player2.DistanceTo(coachGoalObject) < myPlayer2.DistanceTo(coachGoalObject)) //{ // m_robot.Kick(20, myPlayer2.AngleToKick(player2)); //} else { if (goal.Distance > 25) { m_robot.Kick(20, goal.Direction.Value); } else { m_robot.Kick(150, goal.Direction.Value + 12); } } } // sleep one step to ensure that we will not send // two commands in one cycle. try { Thread.Sleep(SoccerParams.simulator_step); } catch (Exception e) { } } }
public double GetDistanceFromBall(SeenCoachObject player) { var ball = GetSeenCoachObject("ball"); return(GetDistance(player, ball)); }
private void KickOrMoveWithBall(SeenCoachObject player, double power, double distanceToBall, double directiontoGoal, SeenCoachObject ball) { if (GetMyPlayerDetailsByCoach().Pos.Value.Y > 0) { directiontoGoal = GetAngleToOpponentGoalLow(); } else { directiontoGoal = GetAngleToOpponentGoalUp(); } var myBall = m_memory.GetSeenObject("ball"); //if (Math.Abs(distanceToBall) < 10) //{ // if (myBall == null) // { // PointF point; // if (m_side == 'l') // { // point = new PointF() // { // X = ball.Pos.Value.X, // Y = ball.Pos.Value.Y + 10 // }; // } // else // { // point = new PointF() // { // X = ball.Pos.Value.X + 3, // Y = ball.Pos.Value.Y - 10 // }; // } // goToCoordinate(point, 0); // return; // } //} if (NearBoal(distanceToBall)) { bool isAhead = false; if (m_side == 'l' && Math.Abs(player.BodyAngle.Value) > 45) { isAhead = true; } else if (m_side == 'r' && Math.Abs(player.BodyAngle.Value) < 45) { isAhead = true; } if (myBall == null || isAhead) { if (!SpinAroundBall()) { return; } ; m_robot.Kick(power, directiontoGoal); } else { if (!SpinAroundBall()) { return; } ; m_robot.Kick(power, directiontoGoal); } } else { goToCoordinate(ball.Pos.Value, DistFromBallToKick); } }
public override void play() { MyGoal = m_coach.GetSeenCoachObject(m_side == 'l' ? "goal l" : "goal r"); float start_pos_x; if (MyGoal != null) { var goal_x = MyGoal.Pos.Value.X; start_pos_x = goal_x > 0 ? goal_x - GoalDistance : goal_x + GoalDistance; Console.WriteLine("Golie going to " + start_pos_x); } else { start_pos_x = m_side == 'l' ? -51:51; Console.WriteLine("Golie going to " + start_pos_x); } m_startPosition = new PointF(start_pos_x, 0); // first move to start position // m_robot.Move(m_startPosition.X, m_startPosition.Y); SeenObject obj; while (!m_timeOver) { //m_robot.Move(m_startPosition.X, m_startPosition.Y); var myObj = m_coach.GetSeenCoachObject($"player {m_team.m_teamName} {m_number}"); if (myObj != null) { Console.WriteLine(myObj.BodyAngle); m_robot.Turn(45); Console.WriteLine(myObj.BodyAngle); } //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) * { * // 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(100, 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) { } } }
private double GetAngle(SeenCoachObject me, SeenCoachObject attacker) { var angle = Math.Atan2(me.Pos.Value.Y - attacker.Pos.Value.Y, me.Pos.Value.X - attacker.Pos.Value.X) * 180 / Math.PI; return(angle - me.BodyAngle.Value); }
private SeenCoachObject GetMyPossition() { SeenCoachObject seenCoachObject = m_coach.GetSeenCoachObject("player " + m_team.m_teamName + " " + m_number); return(seenCoachObject); }
public override void play() { SeenCoachObject ball; PointF? goal; //after gaol, first move to start position PointF halfPlace = new PointF(0, 0); while (!m_timeOver) { try { //go to initial position only after goal or free kick m_robot.Move(m_startPosition.X, m_startPosition.Y); SeenCoachObject currPlayer = GetCurrPlayer(); bool onAttackHalf = false; ball = GetBall(); if (m_side == 'l') { onAttackHalf = currPlayer.Pos.Value.X >= -5; // -5 } else { onAttackHalf = currPlayer.Pos.Value.X <= 5; // 5 } if (onAttackHalf) { //if (GetDistanceFrom(ball.Pos.Value) <= 9) if (FindAtackerClosestToTheBall() == m_number) { if (GetDistanceFrom(ball.Pos.Value) <= 1.5) { goal = GetGoalPosition(false); KickToGoal(goal); } MoveToPosition(ball.Pos.Value, null); } else { //AdvanceToStartPoint(); GoToOtherWing(); } } else { MoveToPosition(halfPlace, null); } // 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) { } } catch (Exception) { Console.WriteLine("basa"); } } }
public static double GetAngleToPoint(SeenCoachObject myPosByCoach, float x1, float y1) { return(GetAngleToPoint(new PointF(x1, y1), myPosByCoach)); }
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); // //} // } //} }
public double GetDistance(SeenCoachObject me, SeenCoachObject player) { return(Math.Sqrt(Math.Pow(me.Pos.Value.Y - player.Pos.Value.Y, 2) + Math.Pow(me.Pos.Value.X - player.Pos.Value.X, 2))); }
public override void play() { m_robot.Move(m_startPosition.X, m_startPosition.Y); bool isInGoal = false; while (!m_timeOver) { m_memory.waitForNewInfo(); SeenCoachObject ball = FindObjectInView("ball"); while (ball == null) { m_memory.waitForNewInfo(); ball = FindObjectInView("ball"); } var my_data = m_coach.GetSeenCoachObject("player " + m_team.m_teamName + " " + m_number); while (my_data == null) { m_memory.waitForNewInfo(); my_data = m_coach.GetSeenCoachObject("player " + m_team.m_teamName + " " + m_number); } var goalLocation = GetMyGoal(); var distanceGoalBall = CommonTools.GetDistance(goalLocation, ball.Pos); var distanceToBall = CommonTools.GetDistance(my_data.Pos, ball.Pos); if (distanceGoalBall < 17) { if (distanceToBall < 1.5) { // catch var directionToBall = CommonTools.GetRelativeAngle(my_data.BodyAngle, my_data.Pos, ball.Pos.Value.X, ball.Pos.Value.Y); m_robot.Catch(directionToBall); m_memory.waitForNewInfo(); // move m_robot.Move(m_startPosition.X, m_startPosition.Y); m_memory.waitForNewInfo(); // turn PointF opponentsGoal = GetOpponentsGoal(); var directionToOpponentsGoal = CommonTools.GetRelativeAngle(my_data.BodyAngle, my_data.Pos, opponentsGoal.X, opponentsGoal.Y); if (directionToOpponentsGoal > 90 || directionToOpponentsGoal < -90) { directionToOpponentsGoal /= -Math.Abs(directionToOpponentsGoal); directionToOpponentsGoal *= 90; } m_robot.Kick(100, directionToOpponentsGoal); } else { var relativeAngle = CommonTools.GetRelativeAngle(my_data.BodyAngle, my_data.Pos, ball.Pos.Value.X, ball.Pos.Value.Y); if (Math.Abs(relativeAngle) > 2) { m_robot.Turn(relativeAngle); m_memory.waitForNewInfo(); } m_robot.Dash(10 * Math.Pow(distanceToBall, 4)); isInGoal = false; } } else { MoveToMyGoal(); } } }