private int[] readBoard(int rows, int cols) throws IOException {
    int[] board = new int[rows * cols];
    for (int i = 0; i < rows; i++) {
      String line = nextLine();
      for (int j = 0; j < cols; j++) {
        board[i * cols + j] = (line.charAt(j) == 'X') ? 1 : 0;
      }
    }
    return board;
  }