Ejemplo n.º 1
0
  /**
   * Implements Scout moving model.
   *
   * @param board
   * @param sct
   * @return
   */
  public List<Vector2D> movementSystemScout(Board board, Scout sct) {
    List<Vector2D> sctMovements = new ArrayList<Vector2D>();
    // move in each direction until hitting something:
    int x = sct.getCol();
    int y = sct.getRow();
    // Blocked by:
    // 1.rock (non-inclusive)
    // 2.same player token (non-inclusive)
    // 3.other player token (inclusive)
    // 4.Board boundaries (non-inclusive)
    boolean blocked = false;
    // Negative Y:
    int ny = y;
    while (!blocked) {
      ny--;
      if (isInsideBoard(new Vector2D(ny, x))) {
        Token bt = board.getToken(ny, x);
        if (hitsRock(new Vector2D(ny, x))) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().side()) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().otherSide()) {
          sctMovements.add(new Vector2D(ny, x));
          blocked = true;
        } else {
          sctMovements.add(new Vector2D(ny, x));
        }
      } else {
        blocked = true;
      }
    }
    blocked = false;
    // Positive Y:
    ny = y;
    while (!blocked) {
      ny++;
      if (isInsideBoard(new Vector2D(ny, x))) {
        Token bt = board.getToken(ny, x);
        if (hitsRock(new Vector2D(ny, x))) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().side()) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().otherSide()) {
          sctMovements.add(new Vector2D(ny, x));
          blocked = true;
        } else {
          sctMovements.add(new Vector2D(ny, x));
        }
      } else {
        blocked = true;
      }
    }
    blocked = false;
    // Negative X:
    int nx = x;
    while (!blocked) {
      nx--;
      if (isInsideBoard(new Vector2D(y, nx))) {
        Token bt = board.getToken(y, nx);
        if (hitsRock(new Vector2D(y, nx))) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().side()) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().otherSide()) {
          sctMovements.add(new Vector2D(y, nx));
          blocked = true;
        } else {
          sctMovements.add(new Vector2D(y, nx));
        }
      } else {
        blocked = true;
      }
    }
    blocked = false;
    // Positive X:
    nx = x;
    while (!blocked) {
      nx++;
      if (isInsideBoard(new Vector2D(y, nx))) {
        Token bt = board.getToken(y, nx);
        if (hitsRock(new Vector2D(y, nx))) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().side()) {
          blocked = true;
        } else if (bt.getOwn() == this.getTurn().otherSide()) {
          sctMovements.add(new Vector2D(y, nx));
          blocked = true;
        } else {
          sctMovements.add(new Vector2D(y, nx));
        }
      } else {
        blocked = true;
      }
    }

    return sctMovements;
  }