/** * Implements Dragon moving/attack model. * * @param board * @param drg * @return */ public List<Vector2D> powerMovementSystemFlight(Board board, Dragon drg) { List<Vector2D> drgMovements = new ArrayList<Vector2D>(); // move in each direction skipping first obstacle: int x = drg.getCol(); int y = drg.getRow(); boolean mustLand = false; boolean obstacle = false; List<Vector2D> safeLanding = new ArrayList<Vector2D>(); List<Vector2D> riskyLanding = new ArrayList<Vector2D>(); List<Vector2D> attackAfterLanding = new ArrayList<Vector2D>(); // Negative Y: int ny = y; while (!mustLand) { ny--; if (isInsideBoard(new Vector2D(ny, x))) { Token bt = board.getToken(ny, x); /*if(!isInsideBoard(new Vector2D(ny,x))){ mustLand = true; }else */ if (hitsRock(new Vector2D(ny, x))) { riskyLanding.add(new Vector2D(ny, x)); obstacle = true; } else if (bt instanceof PlayerToken) { riskyLanding.add(new Vector2D(ny, x)); obstacle = true; } else if (obstacle) { riskyLanding.add(new Vector2D(ny, x)); safeLanding.addAll(riskyLanding); mustLand = true; } else { // If no better position is found, glide down with pride (like a true dragon): safeLanding.add(new Vector2D(ny, x)); } } else { // Hit the end of the board: mustLand = true; } } mustLand = false; obstacle = false; riskyLanding = new ArrayList<Vector2D>(); // Positive Y: ny = y; while (!mustLand) { ny++; if (isInsideBoard(new Vector2D(ny, x))) { Token bt = board.getToken(ny, x); if (hitsRock(new Vector2D(ny, x))) { riskyLanding.add(new Vector2D(ny, x)); obstacle = true; } else if (bt instanceof PlayerToken) { riskyLanding.add(new Vector2D(ny, x)); obstacle = true; } else if (obstacle) { riskyLanding.add(new Vector2D(ny, x)); safeLanding.addAll(riskyLanding); mustLand = true; } else { safeLanding.add(new Vector2D(ny, x)); } } else { // Hit the end of the board: mustLand = true; } } mustLand = false; obstacle = false; riskyLanding = new ArrayList<Vector2D>(); // Negative X: int nx = x; while (!mustLand) { nx--; if (isInsideBoard(new Vector2D(y, nx))) { Token bt = board.getToken(y, nx); if (hitsRock(new Vector2D(y, nx))) { riskyLanding.add(new Vector2D(y, nx)); obstacle = true; } else if (bt instanceof PlayerToken) { riskyLanding.add(new Vector2D(y, nx)); obstacle = true; } else if (obstacle) { riskyLanding.add(new Vector2D(y, nx)); safeLanding.addAll(riskyLanding); mustLand = true; } else { safeLanding.add(new Vector2D(y, nx)); } } else { // Hit the end of the board: mustLand = true; } } mustLand = false; obstacle = false; riskyLanding = new ArrayList<Vector2D>(); // Positive X: nx = x; while (!mustLand) { nx++; if (isInsideBoard(new Vector2D(y, nx))) { Token bt = board.getToken(y, nx); if (hitsRock(new Vector2D(y, nx))) { riskyLanding.add(new Vector2D(y, nx)); obstacle = true; } else if (bt instanceof PlayerToken) { riskyLanding.add(new Vector2D(y, nx)); obstacle = true; } else if (obstacle) { riskyLanding.add(new Vector2D(y, nx)); safeLanding.addAll(riskyLanding); mustLand = true; } else { safeLanding.add(new Vector2D(y, nx)); } } else { // Hit the end of the board: mustLand = true; } } // Define additional attack options for each landing position: for (int k = 0; k < safeLanding.size(); k++) { attackAfterLanding.addAll( positionsAttackOptions(board, new Vector2D(safeLanding.get(k).y, safeLanding.get(k).x))); } drgMovements.addAll(safeLanding); drgMovements.addAll(attackAfterLanding); return drgMovements; }