private void UpdateVisibility(VisionState nvs) { if (VisionState != nvs) { VisionState = nvs; if (VisibleObject) { VisibleObject.SetActive(nvs == VisionState.VISIBLE); } if (HiddenObject) { HiddenObject.SetActive(nvs == VisionState.HIDDEN); } if (SeenObject) { SeenObject.SetActive(nvs == VisionState.SEEN); } UpdateParticleSystems(nvs); //foreach (var r in GetComponentsInChildren<Renderer>()) r.enabled = (nvs != VisionState.HIDDEN); foreach (var obj in mapObjects.Values) { ApplyVisibilityToObject(obj); } } }
private bool IsPointingAt(string objName, double offset) { m_memory.waitForNewInfo(); SeenObject myObj = null; myObj = m_memory.GetSeenObject(objName); if (myObj == null) { return(false); } return(Math.Abs(myObj.Direction.Value) < offset); }
public SeenObject GetSeenObject(String name) { SeenObject result = null; if (m_info == null) { waitForNewInfo(); } lock (m_info?.m_seenObjects) { result = m_info?.m_seenObjects.FirstOrDefault(player => player.Name == name); } return(result); }
public void ParseSeeMessage() { if (!m_message.StartsWith("(see")) { return; } var objectsMatch = Regex.Matches(m_message, MagicPattern); 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 SeenObject(name, floatParams); lock (m_seenObjects) { m_seenObjects.Add(seenObject); } } }
void GotoGoal() { var myGoalStr = m_side == 'l' ? "goal l" : "goal r"; SeenObject myGoal = FindGoal(myGoalStr); var ballObj = FindMovingObj("ball"); var tolerance = ballObj.Distance.Value > 1.5 ? 0.8 : 5.0; while (myGoal.Distance.Value > tolerance) { m_robot.Dash(50 * myGoal.Distance.Value); myGoal = FindGoal(myGoalStr); } if (ballObj.Distance.Value < 1.0) { var otherGoalStr = m_side == 'l' ? "goal r" : "goal l"; var goalObj = FindMovingObj(otherGoalStr); Thread.Sleep(2 * SoccerParams.simulator_step); m_robot.Kick(100, goalObj.Direction.Value); Thread.Sleep(2000); } }
public override void play() { // first ,ove to start position m_robot.Move(m_startPosition.X, m_startPosition.Y); while (!m_timeOver) { 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. try { Thread.Sleep(SoccerParams.simulator_step); } catch (Exception e) { } }
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 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 }
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(); }