<commit_before>import java.util.ArrayList;

public class SelfAvoidingWalk {
  private boolean[][] grid;
  private int cRow; // current row on grid
  private int cCol; // current column on grid

  public SelfAvoidingWalk(int n) {
    grid = generateGrid(n);
    cRow = n / 2 - 1;
    cCol = n / 2 - 1;
  }

  public int walk() {
    grid[cRow][cCol] = true;

    while (isDoneWalking() == 0) {
      ArrayList<Integer> directions = getValidDirections();
      int r = (int)(Math.random() * directions.size());
      int ranDir = directions.get(r);
      if (ranDir == 0) { cRow--; }
      else if (ranDir == 1) { cCol++; }
      else if (ranDir == 2) { cRow++; }
      else if (ranDir == 3) { cCol--; }
      grid[cRow][cCol] = true;
    }

    // -1 for dead-end path, 1 for non-dead-end path
    return isDoneWalking();
  }

  private int isDoneWalking() {
    if (cRow == 0 || cRow == grid.length - 1 ||
        cCol == 0 || cCol == grid[0].length - 1) {
      // denotes non-dead-end path
      return 1;
    }

    if (grid[cRow - 1][cCol] && grid[cRow + 1][cCol] &&
        grid[cRow][cCol - 1] && grid[cRow][cCol + 1]) {
      // denotes dead-end path
      return -1;<commit_msg>walk method resets the grid every time it's invoked<commit_after>import java.util.ArrayList;

public class SelfAvoidingWalk {
  private int size;
  private boolean[][] grid;
  private int cRow; // current row on grid
  private int cCol; // current column on grid

  public SelfAvoidingWalk(int size) {
    this.size = size;
    setGrid();
  }

  public int walk() {
    setGrid(); // reset the grid in case it has already been walked before
    grid[cRow][cCol] = true;

    while (isDoneWalking() == 0) {
      ArrayList<Integer> directions = getValidDirections();
      int r = (int)(Math.random() * directions.size());
      int ranDir = directions.get(r);
      if (ranDir == 0) { cRow--; }
      else if (ranDir == 1) { cCol++; }
      else if (ranDir == 2) { cRow++; }
      else if (ranDir == 3) { cCol--; }
      grid[cRow][cCol] = true;
    }

    // -1 for dead-end path, 1 for non-dead-end path
    return isDoneWalking();
  }

  private void setGrid() {
    grid = generateGrid(size);
    cRow = size / 2 - 1;
    cCol = size / 2 - 1;
  }

  private int isDoneWalking() {
    if (cRow == 0 || cRow == grid.length - 1 ||
        cCol == 0 || cCol == grid[0].length - 1) {
      // denotes non-dead-end path
      return 1;
    }

    if (grid[cRow - 1][cCol] && grid[cRow + 1][cCol] &&
        grid[cRow][cCol - 1] && grid[cRow][cCol + 1]) {
      // denotes dead-end path
      return -1;
{'fraction_non_alphanumeric': 0.15661252900232017, 'fraction_numerical': 0.017014694508894045, 'mean_word_length': 2.282994923857868, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1760044', 'n_tokens_mistral': 938, 'n_tokens_neox': 882, 'n_words': 262}