示例#1
0
  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);
  }
示例#2
0
 Vec2 TocchetMode() {
   abstract_robot.setDisplayString("Tocchet");
   Vec2 Goalie = new Vec2(99999, 0);
   Vec2 GoalDistance = new Vec2(99999, 0);
   Vec2 CmdReturn;
   for (int i = 0; i < CurOpponents.length; i++) {
     if (ClosestTo(CurOpponents[i], EgoToAbs(CurOpponentsGoal))) {
       Goalie.setx(CurOpponents[i].x);
       Goalie.sety(CurOpponents[i].y);
     }
   }
   return (Goalie);
 }
示例#3
0
  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;
  }
示例#4
0
  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);
  }
示例#5
0
  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);
  }
示例#6
0
  /** Called every timestep to allow the control system to run. */
  public int TakeStep() {
    double RandomHeading = 0;
    // This var will hold final steering command at end.
    Vec2 Cmd = new Vec2(0, DEFAULT_SPEED);

    // My number, for debugging purposes only!
    MyNum = abstract_robot.getPlayerNumber(CurTime);

    // Read current time
    CurTime = abstract_robot.getTime();
    // Get current position
    CurMyPos = abstract_robot.getPosition(CurTime);
    // Get egocentric ball position, then convert to absolute position
    CurBallPosEgo = abstract_robot.getBall(CurTime);
    CurBallPos = new Vec2(CurBallPosEgo.x, CurBallPosEgo.y);
    CurBallPos.add(CurMyPos);
    // Get goal positions
    CurOurGoal = abstract_robot.getOurGoal(CurTime);
    CurOpponentsGoal = abstract_robot.getOpponentsGoal(CurTime);
    // Get team positions
    CurTeammates = abstract_robot.getTeammates(CurTime);
    CurOpponents = abstract_robot.getOpponents(CurTime);

    // Determine my current mode
    //      if(MyNum == 0) CurMode = MODE_GOALIE;
    //      if(MyNum == 1) CurMode = MODE_GOON;
    //      if(MyNum == 2) CurMode = MODE_GOON;
    //      if(MyNum == 3) CurMode = MODE_ATTACK;
    if (MyNum == 4) CurMode = MODE_TOCCHET;
    else if (ShouldAttack()) CurMode = MODE_ATTACK;
    else if (ShouldBeGoalie()) CurMode = MODE_GOALIE;
    else CurMode = MODE_GOON;

    // Act based on current mode
    switch (CurMode) {
      case (MODE_ATTACK):
        // Go for the glory!
        Cmd = AttackMode();
        break;

      case (MODE_GOON):
        // System.out.println("In goon mode.");
        // Find the nearest undefended opponent, and kick his ass!
        Cmd = GoonMode();

        break;
      case (MODE_GOALIE):
        // For now, use stolen goalie function from Kechze.
        Cmd = GoalieMode();
        break;

      case (MODE_TOCCHET):
        // Crash the cage
        Cmd = TocchetMode();
        break;

      default:
        System.out.println("Unknown Mode!");
        break;
    }

    // Use Cmd!
    if ((Math.abs(CurMyPos.x - PrevMyPos.x) == 0.0)
        && (Math.abs(CurMyPos.y - PrevMyPos.y) == 0.0)) {
      StuckCount++;
    } else {
      StuckCount = 0;
    }

    if (StuckCount > STUCK_LIMIT) {
      RandomHeading = Math.random() * 2 * PI;
      abstract_robot.setSteerHeading(CurTime, RandomHeading);
      if (StuckCount > 2 * STUCK_LIMIT) StuckCount = 0;
    } else abstract_robot.setSteerHeading(CurTime, Cmd.t);
    abstract_robot.setSpeed(CurTime, 1.0);

    // Save old values of everything
    PrevTime = CurTime;
    PrevMyPos = new Vec2(CurMyPos.x, CurMyPos.y);
    PrevBallPos = new Vec2(CurBallPos.x, CurBallPos.y);

    // Kick, if we can and wish to
    if (abstract_robot.canKick(CurTime) && KickIt) {
      abstract_robot.kick(CurTime);
    }

    // tell the parent we're OK
    return (CSSTAT_OK);
  }
示例#7
0
 Vec2 EgoToAbs(Vec2 EgoPos) {
   Vec2 AbsPosition = new Vec2(EgoPos.x, EgoPos.y);
   AbsPosition.add(CurMyPos);
   return (AbsPosition);
 }