<commit_before>(function(angular){
  /*
   * Grid module
   * Contains playing field state and logic
   */
  angular
    .module('game.board', ['game.config'])
    .service('BoardManager', BoardManager)
    .factory('BoardNullTile', BoardNullTile)
    .factory('BoardTile', BoardTile)
  ;


  BoardManager.$inject = ['GameConfig', 'BoardNullTile',];
  function BoardManager(config, NullTile) {
    var ctrl = this;

    ctrl.placeholders = {
      indoor: new NullTile({placeable: true, outdoor: false}),
      ourdoor: new NullTile({placeable: true, outdoor: true}),
    };

    ctrl.defaults = {
      tiles: {},
      actor: '0:0',
      events: 0,
    };

    ctrl.tiles = {};
    ctrl.actor = '0:0';

    ctrl.initalize = function () {
      // ugly ugly ugly horrible initalization but everything assumes
      // the board doesn't have a state object but I want to keep defaults
      // externally configurable.
      // todo: build proper initalization or actually use a state object. fml.
      var defaults = angular.copy(ctrl.defaults);
      ctrl.tiles = defaults.tiles;
      ctrl.actor = defaults.actor;
      ctrl.events = defaults.events;
    };

    ctrl.move_actor = function (point) {
      var actor_point = ctrl.point(ctrl.actor)
          , coord = ctrl.coord[point]
          , tile = ctrl.tiles[coord]
          ;

      if (ctrl.walkable(actor_point, point))
        ctrl.actor = ctrl.coord(point);
    };

    ctrl.place_tile = function (point, tile) {
      // todo: add overwrite checks
      var coord = ctrl.coord(point)
          , enter_tile = ctrl.tiles[coord]
          , exit_coord
          , exit_tile
          ;

      // if there are no tiles then enter_tile will always be false-y
      // we want to let the first tile pass unquestioned
      if (Object.keys(ctrl.tiles).length > 0 && !(enter_tile && enter_tile.placeable))
        return false;

      ctrl.tiles[coord] = tile;
      for (var i = 0; i < tile.exits.length; i++) {
        var vector = tile.get_vector(tile.exits[i])
            , exit_point = [
              point[0] + vector[0],
              point[1] + vector[1],
            ]
            ;
        exit_coord = ctrl.coord(exit_point);
        exit_tile = ctrl.tiles[exit_coord];
        if (!exit_tile)
          ctrl.tiles[exit_coord] = ctrl.placeholders.indoor;
      }

      ctrl.events += 1;
      return true;
    };

    ctrl.coord = function(point) {
      return point[0] +":"+ point[1];
    };

    ctrl.point = function(coord) {
      var matches = coord.match(/([-\d]+)?:([-\d]+)?/);<commit_msg>game (board): use array.forEach for cleaner array iteration<commit_after>(function(angular){
  /*
   * Grid module
   * Contains playing field state and logic
   */
  angular
    .module('game.board', ['game.config'])
    .service('BoardManager', BoardManager)
    .factory('BoardNullTile', BoardNullTile)
    .factory('BoardTile', BoardTile)
  ;


  BoardManager.$inject = ['GameConfig', 'BoardNullTile',];
  function BoardManager(config, NullTile) {
    var ctrl = this;

    ctrl.placeholders = {
      indoor: new NullTile({placeable: true, outdoor: false}),
      ourdoor: new NullTile({placeable: true, outdoor: true}),
    };

    ctrl.defaults = {
      tiles: {},
      actor: '0:0',
      events: 0,
    };

    ctrl.tiles = {};
    ctrl.actor = '0:0';

    ctrl.initalize = function () {
      // ugly ugly ugly horrible initalization but everything assumes
      // the board doesn't have a state object but I want to keep defaults
      // externally configurable.
      // todo: build proper initalization or actually use a state object. fml.
      var defaults = angular.copy(ctrl.defaults);
      ctrl.tiles = defaults.tiles;
      ctrl.actor = defaults.actor;
      ctrl.events = defaults.events;
    };

    ctrl.move_actor = function (point) {
      var actor_point = ctrl.point(ctrl.actor)
          , coord = ctrl.coord[point]
          , tile = ctrl.tiles[coord]
          ;

      if (ctrl.walkable(actor_point, point))
        ctrl.actor = ctrl.coord(point);
    };

    ctrl.place_tile = function (point, tile) {
      // todo: add overwrite checks
      var coord = ctrl.coord(point)
          , enter_tile = ctrl.tiles[coord]
          , exit_coord
          , exit_tile
          ;

      // if there are no tiles then enter_tile will always be false-y
      // we want to let the first tile pass unquestioned
      if (Object.keys(ctrl.tiles).length > 0 && !(enter_tile && enter_tile.placeable))
        return false;

      ctrl.tiles[coord] = tile;
      tile.exits.forEach(function(exit){
        var vector = tile.get_vector(exit)
            , exit_point = [
              point[0] + vector[0],
              point[1] + vector[1],
            ]
            ;
        exit_coord = ctrl.coord(exit_point);
        exit_tile = ctrl.tiles[exit_coord];
        if (!exit_tile)
          ctrl.tiles[exit_coord] = ctrl.placeholders.indoor;
      }, this);

      ctrl.events += 1;
      return true;
    };

    ctrl.coord = function(point) {
      return point[0] +":"+ point[1];
    };

    ctrl.point = function(coord) {
      var matches = coord.match(/([-\d]+)?:([-\d]+)?/);
{'fraction_non_alphanumeric': 0.13190421011973735, 'fraction_numerical': 0.005214368482039398, 'mean_word_length': 2.1969135802469135, 'pattern_counts': {'":': 2, '<': 4, '<?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': '1508797', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1552, 'n_words': 381}