boolean BetweenGoal(Vec2 Opp, Vec2 Goal) { Vec2 OpptoGoal = new Vec2(Goal.x, Goal.y); OpptoGoal.sub(Opp); Vec2 OpptoMe = new Vec2(CurMyPos.x, CurMyPos.y); OpptoMe.sub(Opp); if (Math.abs(OpptoGoal.t - OpptoMe.t) < BETWEEN_GOAL_ANGLE) { return (true); } return (false); }
boolean ClosestTo(Vec2 Me, Vec2 SpotAbs) { // Stolen from Kechze Vec2 temp = new Vec2(Me.x, Me.y); temp.sub(SpotAbs); double MyDist = temp.r; for (int i = 0; i < CurTeammates.length; i++) { temp = new Vec2(CurTeammates[i].x, CurTeammates[i].y); temp.add(Me); temp.sub(SpotAbs); double TheirDist = temp.r; if (TheirDist <= MyDist) return false; } return true; }
Vec2 AttackMode() { abstract_robot.setDisplayString("Attack"); Vec2 TargetSpot = new Vec2(CurBallPosEgo.x, CurBallPosEgo.y); Vec2 GoalSpot = new Vec2(CurOpponentsGoal.x, CurOpponentsGoal.y); if (CurMyPos.y > 0) GoalSpot.y += 0.9 * (GOAL_WIDTH / 2.0); if (CurMyPos.y < 0) GoalSpot.y -= 0.9 * (GOAL_WIDTH / 2.0); TargetSpot.sub(GoalSpot); TargetSpot.setr(ROBOT_RADIUS); TargetSpot.add(CurBallPosEgo); if (Math.abs(CurOpponentsGoal.r) < KICK_DISTANCE) KickIt = true; else KickIt = false; return (TargetSpot); }
Vec2 GoalieMode() { abstract_robot.setDisplayString("Goalie"); Vec2 ReturnCmd = new Vec2(CurOurGoal.x, CurOurGoal.y); // If we're too far out of goal in x dir, get back in! Vec2 OurGoalAbs = new Vec2(CurOurGoal.x, CurOurGoal.y); OurGoalAbs.add(CurMyPos); if (Math.abs(CurMyPos.x) < Math.abs(OurGoalAbs.x * 0.9)) { return (CurOurGoal); } // Otherwise, calculate projected ball trajectory Vec2 BallDir = new Vec2(CurBallPos.x, CurBallPos.y); BallDir.sub(PrevBallPos); // If ball is headed into goal, block it! ReturnCmd.setx(0); boolean MoveUp = false; boolean MoveDown = false; if (CurMyPos.y < CurBallPos.y) MoveUp = true; if (CurMyPos.y > CurBallPos.y) MoveDown = true; if (CurMyPos.y > GOAL_WIDTH / 2.0) MoveUp = false; if (CurMyPos.y < -GOAL_WIDTH / 2.0) MoveDown = false; if (MoveDown && MoveUp) { ReturnCmd.sety(0); // System.out.println("Both " + CurMyPos.y + " " + CurBallPos.y); } else if (MoveDown) { ReturnCmd.sety(-1); // System.out.println("Down"); } else if (MoveUp) { ReturnCmd.sety(1); // System.out.println("Up"); } else { ReturnCmd.sety(0); } return (ReturnCmd); }