Untitled

 avatar
unknown
java
a year ago
1.6 kB
6
Indexable
public class PlantFlowersAroundWater {
    public static void main(String[] args) {
        Jeroo jeroo = new Jeroo();
        
        // Iterate over each cell of the 23x23 board
        for (int row = 0; row < 23; row++) {
            for (int col = 0; col < 23; col++) {
                // Check if current cell is water
                if (jeroo.isWater(row, col)) {
                    // Plant flowers around the water spot
                    plantFlowersAroundWater(jeroo, row, col);
                }
            }
        }
        
        // Move Jeroo to the bottom right corner of the board
        moveToBottomRight(jeroo);
    }
    
    // Method to plant flowers around water spot
    private static void plantFlowersAroundWater(Jeroo jeroo, int row, int col) {
        // Plant a flower in each adjacent cell (up, down, left, right)
        for (int i = row - 1; i <= row + 1; i++) {
            for (int j = col - 1; j <= col + 1; j++) {
                if (i != row || j != col) { // Skip the current water spot
                    if (!jeroo.isWater(i, j)) { // Check if the cell is not water
                        jeroo.plant();
                    }
                }
            }
        }
    }
    
    // Method to move Jeroo to the bottom right corner of the board
    private static void moveToBottomRight(Jeroo jeroo) {
        while (!jeroo.isClear(RelativeDirection.EAST)) {
            jeroo.hop(RelativeDirection.EAST);
        }
        while (!jeroo.isClear(RelativeDirection.SOUTH)) {
            jeroo.hop(RelativeDirection.SOUTH);
        }
    }
}
Editor is loading...
Leave a Comment