<commit_before>var Cell = require('./cell');
var Grid = require('./grid');

function rand(limit) {
  return Math.floor(Math.random() * limit);
}

function maze(algorithm) {
  switch(algorithm) {
  case 'binaryTree' :
    return function (rows, cols) {
      var grid = new Grid(rows, cols);
      grid.eachCell().forEach(function (cell) {
        var neighbors = [];

        var north = grid.northOf(cell);
        if (north) neighbors.push(north);

        var east = grid.eastOf(cell);
        if (east) neighbors.push(east);

        if (neighbors.length > 0) {
          var index = rand(neighbors.length);
          cell.link(neighbors[index]);
        }
      });
      return grid;
    };
  default:
    throw new 'not supported algorithm';
  }
}

var mz = maze('binaryTree')(10,10);

console.log(mz.toString());

window.onload = function (e) {
  mz.draw('canvas1', 30);
};
<commit_msg>미로 생성 알고리즘 함수를 독립 함수로...<commit_after>var Cell = require('./cell');
var Grid = require('./grid');

function rand(limit) {
  return Math.floor(Math.random() * limit);
}

function binaryTree (rows, cols) {
  var grid = new Grid(rows, cols);
  grid.eachCell().forEach(function (cell) {
    var neighbors = [];

    var north = grid.northOf(cell);
    if (north) neighbors.push(north);

    var east = grid.eastOf(cell);
    if (east) neighbors.push(east);

    if (neighbors.length > 0) {
      var index = rand(neighbors.length);
      cell.link(neighbors[index]);
    }
  });
  return grid;
}

function maze(algorithm) {
  switch(algorithm) {
  case 'binaryTree': return binaryTree;
  default:
    throw new 'not supported algorithm';
  }
}

var mz = maze('binaryTree')(10,10);

console.log(mz.toString());

window.onload = function (e) {
  mz.draw('canvas1', 30);
};

{'fraction_non_alphanumeric': 0.1629755820556502, 'fraction_numerical': 0.009085746734809767, 'mean_word_length': 3.0320366132723113, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6734162', 'n_tokens_mistral': 631, 'n_tokens_neox': 608, 'n_words': 137}