<commit_before>World = function(camera) {
  this.cells_ = new Uint8Array(World.TOTAL_SIZE);

  this.root_ = new THREE.Object3D();
  this.root_.position.x = -World.X_SIZE / 2;
  this.root_.position.z = -World.Z_SIZE / 2;
  
  this.camera_ = camera;
};

World.X_SIZE = 50;
World.Y_SIZE = 40;
World.Z_SIZE = 50;

World.TOTAL_SIZE = World.X_SIZE * World.Y_SIZE * World.Z_SIZE;

World.Y_OFFSET = World.X_SIZE;
World.Z_OFFSET = World.X_SIZE * World.Y_SIZE;

World.CELL_TX_SIZE = 1 / 4;
World.CELL_TY_SIZE = 1 / 2;

World.CellType = {
  EMPTY: 0,
  UNKNOWN: 1,
  DIRT: 2,
  ROCK: 3,
  WATER: 4,
  WOOD: 5
};

World.CELL_TX_OFFSET = [
  (World.CELL_TX_SIZE * 3),  // EMPTY
  (World.CELL_TX_SIZE * 1),  // UNKNOWN
  (World.CELL_TX_SIZE * 0),  // DIRT
  (World.CELL_TX_SIZE * 1),  // ROCK
  (World.CELL_TX_SIZE * 2),  // WATER
  (World.CELL_TX_SIZE * 0)   // WOOD
];

World.CELL_TY_OFFSET = [
  (World.CELL_TY_SIZE * 0),  // EMPTY
  (World.CELL_TY_SIZE * 0),  // UNKNOWN
  (World.CELL_TY_SIZE * 1),  // DIRT
  (World.CELL_TY_SIZE * 1),  // ROCK
  (World.CELL_TY_SIZE * 0),  // WATER
  (World.CELL_TY_SIZE * 0)   // WOOD
];

World.FACES = [
  [0, 2, 1, 3],
  [1, 6, 5, 2],
  [5, 7, 4, 6],
  [4, 3, 0, 7],
  [3, 6, 2, 7],
  [1, 4, 0, 5]
];

World.NEXT_OFFSET = [
  [0, 0, -1],
  [1, 0, 0],
  [0, 0, 1],
  [-1, 0, 0],
  [0, 1, 0],
  [0, -1, 0]
];

World.isIn = function(x, y, z) {
  return x >= 0 && y >= 0 && z >= 0 &&
      x < World.X_SIZE && y < World.Y_SIZE && z < World.Z_SIZE;
};


/**
 * @private
 */
World.isTransparent_ = function(cellType) {
  return cellType == World.CellType.EMPTY ||
      cellType == World.CellType.WATER;
};


World.prototype.init = function() {
  this.createRandomWorld_();
  this.buildMesh_();
  this.moveCamera_();
};


World.prototype.getRoot = function() {
  return this.root_;
};


/**
 * @private
 */
World.prototype.createRandomWorld_ = function() {
  for (var i = 0; i < World.TOTAL_SIZE; ++i) {
    this.cells_[i] = World.EMPTY;
  }
  var w = this;
  var drop = function(x, z, cellType, radius) {
    for (var i = -radius; i <= radius; ++i) {
      for (var j = -radius; j <= radius; ++j) {
        if (!World.isIn(x + i, 0, z + j)) {
          continue;
        }
        var h = Math.round(Math.sqrt(radius * radius - i * i - j * j));
        var k;
        for (k = World.Y_SIZE; k > 0; --k) {
          if (w.getCell(x + i, k - 1, z + j) != World.CellType.EMPTY) {
            break;
          }
        }
        for (; h > 0 && k < World.Y_SIZE; --h,++k) {
          w.setCell(x + i, k, z + j, cellType);
        }
      }
    }
  };

  for (var i = 0; i < World.X_SIZE; ++i) {
    for (var j = 0; j < World.Z_SIZE; ++j) {
      this.setCell(i, 0, j, World.CellType.DIRT);
    }
  }
  var cts = [World.CellType.DIRT, World.CellType.WOOD, World.CellType.ROCK];
  var sts = [2, 4, 6];
  var rs = [3, 4, 5]
  for (var ct = 0; ct < cts.length; ++ct) {
    var cellType = cts[ct];
    var st = sts[ct];
    for (var i = 0; i < World.X_SIZE; i += st) {
      for (var j = 0; j < World.Z_SIZE; j += st) {
        var x = i + Math.floor(Math.random() * (st * 2 + 1)) - st;
        var z = j + Math.floor(Math.random() * (st * 2 + 1)) - st;
        var r = Math.floor(Math.random() * rs[ct]);
        drop(x, z, cellType, r);
      }
    }
  }<commit_msg>Adding water flow<commit_after>World = function(camera) {
  this.cells_ = new Uint8Array(World.TOTAL_SIZE);

  this.root_ = new THREE.Object3D();
  this.root_.position.x = -World.X_SIZE / 2;
  this.root_.position.z = -World.Z_SIZE / 2;
  
  this.camera_ = camera;
};

World.X_SIZE = 50;
World.Y_SIZE = 40;
World.Z_SIZE = 50;

World.TOTAL_SIZE = World.X_SIZE * World.Y_SIZE * World.Z_SIZE;

World.Y_OFFSET = World.X_SIZE;
World.Z_OFFSET = World.X_SIZE * World.Y_SIZE;

World.CELL_TX_SIZE = 1 / 4;
World.CELL_TY_SIZE = 1 / 2;

World.CellType = {
  EMPTY: 0,
  UNKNOWN: 1,
  DIRT: 2,
  ROCK: 3,
  WATER: 4,
  WOOD: 5
};

World.CELL_TX_OFFSET = [
  (World.CELL_TX_SIZE * 3),  // EMPTY
  (World.CELL_TX_SIZE * 1),  // UNKNOWN
  (World.CELL_TX_SIZE * 0),  // DIRT
  (World.CELL_TX_SIZE * 1),  // ROCK
  (World.CELL_TX_SIZE * 2),  // WATER
  (World.CELL_TX_SIZE * 0)   // WOOD
];

World.CELL_TY_OFFSET = [
  (World.CELL_TY_SIZE * 0),  // EMPTY
  (World.CELL_TY_SIZE * 0),  // UNKNOWN
  (World.CELL_TY_SIZE * 1),  // DIRT
  (World.CELL_TY_SIZE * 1),  // ROCK
  (World.CELL_TY_SIZE * 0),  // WATER
  (World.CELL_TY_SIZE * 0)   // WOOD
];

World.FACES = [
  [0, 2, 1, 3],
  [1, 6, 5, 2],
  [5, 7, 4, 6],
  [4, 3, 0, 7],
  [3, 6, 2, 7],
  [1, 4, 0, 5]
];

World.NEXT_OFFSET = [
  [0, 0, -1],
  [1, 0, 0],
  [0, 0, 1],
  [-1, 0, 0],
  [0, 1, 0],
  [0, -1, 0]
];

World.MAX_WATER_ITER = World.Y_SIZE * 3;

World.WATER_MOVES = [
  [0, 0, -1],
  [1, 0, 0],
  [0, 0, 1],
  [-1, 0, 0]
];

World.isIn = function(x, y, z) {
  return x >= 0 && y >= 0 && z >= 0 &&
      x < World.X_SIZE && y < World.Y_SIZE && z < World.Z_SIZE;
};


/**
 * @private
 */
World.isTransparent_ = function(cellType) {
  return cellType == World.CellType.EMPTY ||
      cellType == World.CellType.WATER;
};


World.prototype.init = function() {
  this.createRandomWorld_();
  this.buildMesh_();
  this.moveCamera_();
};


World.prototype.getRoot = function() {
  return this.root_;
};


/**
 * @private
 */
World.prototype.createRandomWorld_ = function() {
  for (var i = 0; i < World.TOTAL_SIZE; ++i) {
    this.cells_[i] = World.EMPTY;
  }
  var w = this;

  var drop = function(x, z, cellType, radius) {
    for (var i = -radius; i <= radius; ++i) {
      for (var j = -radius; j <= radius; ++j) {
        if (!World.isIn(x + i, 0, z + j)) {
          continue;
        }
        var h = Math.round(Math.sqrt(radius * radius - i * i - j * j));
        var k;
        for (k = World.Y_SIZE; k > 0; --k) {
          if (w.getCell(x + i, k - 1, z + j) != World.CellType.EMPTY) {
            break;
          }
        }
        for (; h > 0 && k < World.Y_SIZE; --h,++k) {
          w.setCell(x + i, k, z + j, cellType);
        }
      }
    }
  };

  for (var i = 0; i < World.X_SIZE; ++i) {
    for (var j = 0; j < World.Z_SIZE; ++j) {
      this.setCell(i, 0, j, World.CellType.DIRT);
    }
  }
  var cts = [World.CellType.DIRT, World.CellType.WOOD, World.CellType.ROCK];
  var sts = [2, 4, 6];
  var rs = [3, 4, 5]
  for (var ct = 0; ct < cts.length; ++ct) {
    var cellType = cts[ct];
    var st = sts[ct];
    for (var i = 0; i < World.X_SIZE; i += st) {
      for (var j = 0; j < World.Z_SIZE; j += st) {
        var x = i + Math.floor(Math.random() * (st * 2 + 1)) - st;
        var z = j + Math.floor(Math.random() * (st * 2 + 1)) - st;
        var r = Math.floor(Math.random() * rs[ct]);
        drop(x, z, cellType, r);
      }
    }
  }

  // Spawn water
  var wcs = [];
  for (var i = 0; i < World.X_SIZE; ++i) {
    for (var j = 0; j < World.Z_SIZE; ++j) {
      if (this.getCell(i, World.Y_SIZE - 1, j) == World.CellType.EMPTY) {
        wcs.push([i, World.Y_SIZE - 1, j, 0]);
        this.setCell(i, World.Y_SIZE - 1, j, World.CellType.WATER);
      }
    }
  }
  var n = wcs.length;
  for (var iter = 0; iter < World.MAX_WATER_ITER; ++iter) {
    for (var i = 0; i < n; ++i) {
      if (World.isIn(wcs[i][0], wcs[i][1] - 1, wcs[i][2]) &&
          this.getCell(wcs[i][0], wcs[i][1] - 1, wcs[i][2]) == World.CellType.EMPTY) {
        this.setCell(wcs[i][0], wcs[i][1] - 1, wcs[i][2], World.CellType.WATER);
        this.setCell(wcs[i][0], wcs[i][1], wcs[i][2], World.CellType.EMPTY);
        --wcs[i][1];
      } else {
        for (var j = 0; j < 4; ++j) {
          var nx = wcs[i][0] + World.WATER_MOVES[wcs[i][3]][0];
          var ny = wcs[i][1] + World.WATER_MOVES[wcs[i][3]][1];
          var nz = wcs[i][2] + World.WATER_MOVES[wcs[i][3]][2];
          if (World.isIn(nx, ny, nz) &&
              this.getCell(nx, ny, nz) == World.CellType.EMPTY) {
            this.setCell(nx, ny, nz, World.CellType.WATER);
            this.setCell(wcs[i][0], wcs[i][1], wcs[i][2], World.CellType.EMPTY);
            wcs[i][0] = nx;
            wcs[i][1] = ny;
            wcs[i][2] = nz;
            break;
          }
          wcs[i][3] = (wcs[i][3] + 1) & 3;
        }
      }
    }
  }
{'fraction_non_alphanumeric': 0.19987714987714988, 'fraction_numerical': 0.031203931203931203, 'mean_word_length': 2.1444573194283505, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 13, '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': '1006260', 'n_tokens_mistral': 3817, 'n_tokens_neox': 3569, 'n_words': 798}