Beispiel #1
0
  @Override
  public Direction getMove() {
    Direction d = getNewDirection();

    if (firstRevolutionCompleted == false)
      timeToCompleteNthRevolution = timeToCompleteFirstRevolution;
    else {

      timeToCompleteNthRevolution = timeToCompleteSecondRevolution;
    }

    distanceFromBoat = whereIAm.distance(positionOfBoat);

    if (timeElapsed >= timeToStartSpiral) {

      if (timeElapsed > timeToCompleteNthRevolution
          && whereIAm.getX() < spiralBoundary
          && whereIAm.getY() < spiralBoundary) {
        if (firstRevolutionCompleted == false) firstRevolutionCompleted = true;
        else {
          GameEngine.println("second revolution completed");
          secondRevolutionCompleted = true;
        }

        spiralRadius = spiralRadius + changeToSpiralRadius;
      }

      /* else if (timeElapsed > timeToCompleteNthRevolution && (whereIAm.getX() >= spiralBoundary || whereIAm.getY() >= spiralBoundary)) {
      	//GameEngine.println("end of outward spiral");
      	timeToStartDownwardSpiral = true;

      	if (changeToSpiralRadius > 0) { //downward spiral not begun yet
      		changeToSpiralRadius = changeToSpiralRadius * -1;
      	}
      	spiralRadius = spiralRadius + changeToSpiralRadius;

      }*/

      if (secondRevolutionCompleted == false) d = getDirectionInSpiralPath();
      else d = null;
    }

    try {
      Point2D p = new Point2D.Double(whereIAm.getX() + d.dx, whereIAm.getY() + d.dy);
      while (Math.abs(p.getX()) > GameConfig.d || Math.abs(p.getY()) > GameConfig.d) {
        d = getNewDirection();
        p = new Point2D.Double(whereIAm.getX() + d.dx, whereIAm.getY() + d.dy);
      }
    } catch (Exception e) {
      d = null;
    }

    return d;
  }
Beispiel #2
0
 public Creature getCreatureFromObservation(ObservedCreature myObservedCreature) {
   Iterator<Creature> iter = setOfCreatureObjects.iterator();
   while (iter.hasNext()) {
     Creature myCreature = iter.next();
     String name = myCreature.getName();
     if (name.equals(myObservedCreature.slp.getName())) {
       return myCreature;
     }
   }
   GameEngine.println(
       "ERROR: SHOULD NOT REACH HERE. IN getCreatureFromObservation() in Communication class");
   return null;
 }
Beispiel #3
0
  public Direction getDirectionInSpiralPath() {

    Direction directionInSpiral = null;

    double spiralRadiusLowBound = -1 * spiralRadius;
    double spiralRadiusHighBound = spiralRadius;

    /*
    boolean b1 = whereIAm.getX() == spiralRadiusHighBound;
    boolean b2 = whereIAm.getY() < spiralRadiusHighBound;
    boolean b3 = whereIAm.getY() >= spiralRadiusLowBound;


    GameEngine.println("snork " + this.getId() + " in position " + whereIAm);
    GameEngine.println("spiralRadiusHighBound " + spiralRadiusHighBound);
    GameEngine.println("whereIAm.getX() == spiralRadiusHighBound " + b1 + " for snork " + this.getId());
    GameEngine.println("whereIAm.getY() < spiralRadiusHighBound;" + b2 + " for snork " + this.getId());
    GameEngine.println("whereIAm.getY() >= spiralRadiusLowBound" + b3 + " for snork " + this.getId());
    */

    // GameEngine.println("spiralRadiusHighBound " + spiralRadiusHighBound + " snork " +
    // this.getId());

    if (whereIAm.getX() == spiralRadiusLowBound
        && whereIAm.getY() <= spiralRadiusHighBound
        && whereIAm.getY() > spiralRadiusLowBound) directionInSpiral = Direction.N;
    else if (whereIAm.getX() == spiralRadiusHighBound
        && whereIAm.getY() < spiralRadiusHighBound
        && whereIAm.getY() >= spiralRadiusLowBound) directionInSpiral = Direction.S;
    else if (whereIAm.getY() == spiralRadiusLowBound
        && whereIAm.getX() < spiralRadiusHighBound
        && whereIAm.getX() >= spiralRadiusLowBound) directionInSpiral = Direction.E;
    else if (whereIAm.getY() == spiralRadiusHighBound
        && whereIAm.getX() <= spiralRadiusHighBound
        && whereIAm.getX() > spiralRadiusLowBound) directionInSpiral = Direction.W;
    else if (whereIAm.getY() == 0
        && whereIAm.getX() > spiralRadiusLowBound
        && whereIAm.getX() < spiralRadiusHighBound) directionInSpiral = Direction.E;
    else if (whereIAm.getX() == 0
        && whereIAm.getY() > spiralRadiusLowBound
        && whereIAm.getY() < spiralRadiusHighBound) directionInSpiral = Direction.N;
    else if (whereIAm.getX() > spiralRadiusHighBound) directionInSpiral = Direction.W;
    else if (whereIAm.getX() < spiralRadiusLowBound) directionInSpiral = Direction.E;
    else if (whereIAm.getY() > spiralRadiusHighBound) directionInSpiral = Direction.N;
    else if (whereIAm.getY() < spiralRadiusLowBound) directionInSpiral = Direction.S;
    else if (whereIAm.getX() > 0) {
      GameEngine.println("snork " + this.getId() + " moving east from " + whereIAm);
      directionInSpiral = Direction.E;
    } else if (whereIAm.getX() < 0) {
      GameEngine.println("snork " + this.getId() + " moving west from " + whereIAm);
      directionInSpiral = Direction.W;
    } else {
      directionInSpiral = null;

      // HERE'S WHERE YOU WILL CALL TOWARDSBOAT TO RETURN SNORKS TO BOAT
      // I HAVE SET DIRECTIONINSPIRAL TO NULL FOR NOW
      // GameEngine.println("direction in spiral is null for snork " + this.getId());
    }

    return directionInSpiral;
  }