import java.util.Random;

public class RandomStrategy implements Strategy {

    private final Random rnd;

    RandomStrategy(Random rnd) {
        this.rnd = rnd;
    }

    @Override
    public int[] turn(GameState state) {
        int freeCells = 0;
        for (GameState.Cell[] xc : state.field) {
            for (GameState.Cell c : xc) {
                freeCells += c == GameState.Cell.FREE ? 1 : 0;
            }
        }
        int pos = rnd.nextInt(freeCells);
        int cell = 0;
        for (int x = 0; x < state.n; x++) {
            for (int y = 0; y < state.m; y++) {
                if (state.field[x][y] == GameState.Cell.FREE) {
                    if (cell++ == pos) {
                        return new int[] {x, y};
                    }
                }
            }
        }
        return null;
    }
}
