<commit_before>'use strict';

const BLACK = -1;
const EMPTY = 0;
const WHITE = 1;

class Board {
  constructor(size) {
    this.size = size;
    this.board = [];
    for (var i = 0; i < size; i++) {
      let row = [];
      for (var j = 0; j < size; j++) {
        row.push(EMPTY);
      }
      this.board.push(row);
    }
  }

  log() {
    for (var row of this.board) {
      console.log(row);
    }
  }

  // Returns whether the move was valid.
  makeMove(i, j, color) {
    if (!this.isValidSpot(i, j)) {
      throw `invalid move because of invalid spot: ${i}, ${j}`
    }
    if (this.board[i][j] != EMPTY) {
      return false;
    }

    // TODO: prevent ko

    this.board[i][j] = color;

    // Check for captures
    let captures = false;
    for (let [a, b] of this.neighbors(i, j)) {
      if (this.board[a][b] == -color) {
        let {spots, alive} = this.findGroup(a, b);
        if (!alive) {
          captures = true;
          for (let [c, d] of spots) {
            this.board[c][d] = EMPTY;
          }
        }
      }
    }

    return true;
  }

  // Returns whether [i, j] is a valid spot on the board.
  isValidSpot(i, j) {
    return (i >= 0 &&
            i < this.size &&
            j >= 0 &&
            j < this.size);
  }

  // Returns a list of [i, j] pairs for all valid neighbors to the
  // provided spot.
  neighbors(i, j) {
    let answer = [];
    for (let [a, b] of [[i + 1, j],
                        [i - 1, j],<commit_msg>prevent suicide<commit_after>'use strict';

const BLACK = -1;
const EMPTY = 0;
const WHITE = 1;

class Board {
  constructor(size) {
    this.size = size;
    this.board = [];
    for (var i = 0; i < size; i++) {
      let row = [];
      for (var j = 0; j < size; j++) {
        row.push(EMPTY);
      }
      this.board.push(row);
    }
  }

  log() {
    for (var row of this.board) {
      console.log(row);
    }
  }

  // Returns whether the move was valid.
  makeMove(i, j, color) {
    if (!this.isValidSpot(i, j)) {
      throw `invalid move because of invalid spot: ${i}, ${j}`
    }
    if (this.board[i][j] != EMPTY) {
      return false;
    }

    // TODO: prevent ko

    this.board[i][j] = color;

    // Check for captures
    let captures = false;
    for (let [a, b] of this.neighbors(i, j)) {
      if (this.board[a][b] == -color) {
        let {spots, alive} = this.findGroup(a, b);
        if (!alive) {
          captures = true;
          for (let [c, d] of spots) {
            this.board[c][d] = EMPTY;
          }
        }
      }
    }

    // Prevent suicide
    if (!captures) {
      let {spots, alive} = this.findGroup(i, j);
      if (!alive) {
        this.board[i][j] = EMPTY;
        return false;
      }
    }

    return true;
  }

  // Returns whether [i, j] is a valid spot on the board.
  isValidSpot(i, j) {
    return (i >= 0 &&
            i < this.size &&
            j >= 0 &&
            j < this.size);
  }

  // Returns a list of [i, j] pairs for all valid neighbors to the
  // provided spot.
  neighbors(i, j) {
    let answer = [];
    for (let [a, b] of [[i + 1, j],
                        [i - 1, j],
{'fraction_non_alphanumeric': 0.1620843989769821, 'fraction_numerical': 0.005754475703324808, 'mean_word_length': 1.6140350877192982, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '1899195', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1122, 'n_words': 335}