<commit_before>// game.js
// ========
"use strict";
module.exports = {
  map: function(size) {
   this.size = size || 70;
   //define tile class
   function tile(properties) {
     //constructor
       if (properties.hasOwnProperty("x") && properties.hasOwnProperty("y")) {
           if(properties.x >= 0 && properties.y >= 0) {
             this.x = properties.x || 0;
             this.y = properties.y || 0;
           }
       }
     if (properties.hasOwnProperty("color")) {
         this.color = properties.color || "#ffffff";
     }
     if (properties.hasOwnProperty("kind")) {
       this.kind = null;
       switch (properties.Type) {
         case "floor":
         //floor
           this.kind = 0;
           break;
         default:
         //wall
         this.kind = 1;

       }
     }
     //Construct the list of items and players on the tile
     if (properties.hasOwnProperty("objects")) {
       this.objects =  new Array();
       if (Array.isArray(properties.objects)) {
           for (var i = 0; i < properties.objects.length; i++) {
             this.objects.push(properties.objects[i]);
           }
       }
     }
   }
   tile.prototype.getTile = function () {
      return {
           
            "color": this.color
      }
   };
   //create map
  this.mapArray = new Array();
  //create list of player locations
  this.playerArray = new Array();
   for (var i = 0; i < size; i++) {
     this.mapArray[i] =  new Array();
     for (var l = 0; l < size; l++) {
       var tileType = 0;
       var colorVal = "#ffffff";
       if ((i === 0) || (l === 0) || (i === this.size-1) || (l === this.size-1) ) {
         tileType = 1;
         colorVal = "#000000";
       }
      this.mapArray[i][l] = new tile({
         "x": i,
         "y": l,
         "color": colorVal,
         "objects": {},
         "kind": tileType
       });
      console.log(tileType);
     }
   }
 }
};
module.exports.map.prototype.getAbove = function (x,y) {
  console.log(this.mapArray.length,x,y)
 /*if (y > this.mapArray.length) {
    return this.mapArray[x][0];
  } 
  if (y < 0) {
    return this.mapArray[x][this.mapArray.length];
  } else {
      
  }*/
  return this.mapArray[x][y-1];
};
module.exports.map.prototype.getBelow = function (x,y) {
       return this.mapArray[x][y+1];
};
module.exports.map.prototype.getRight = function (x,y) {
      return this.mapArray[x+1][y];
};
module.exports.map.prototype.getLeft = function (x,y) {
      return this.mapArray[x-1][y];
};
module.exports.map.prototype.getTile = function (x,y) {
return this.mapArray[x][y];
};
module.exports.map.prototype.setTile = function (x,y,element) {
 this.mapArray[x][y] = element;
};
module.exports.map.prototype.updatePlayer = function (player) {<commit_msg>added bounds checking to map access methods<commit_after>// game.js
// ========
"use strict";
module.exports = {
  map: function(size) {
   this.size = size || 70;
   //define tile class
   function tile(properties) {
     //constructor
       if (properties.hasOwnProperty("x") && properties.hasOwnProperty("y")) {
           if(properties.x >= 0 && properties.y >= 0) {
             this.x = properties.x || 0;
             this.y = properties.y || 0;
           }
       }
     if (properties.hasOwnProperty("color")) {
         this.color = properties.color || "#ffffff";
     }
     if (properties.hasOwnProperty("kind")) {
       this.kind = null;
       switch (properties.Type) {
         case "floor":
         //floor
           this.kind = 0;
           break;
         default:
         //wall
         this.kind = 1;

       }
     }
     //Construct the list of items and players on the tile
     if (properties.hasOwnProperty("objects")) {
       this.objects =  new Array();
       if (Array.isArray(properties.objects)) {
           for (var i = 0; i < properties.objects.length; i++) {
             this.objects.push(properties.objects[i]);
           }
       }
     }
   }
   tile.prototype.getTile = function () {
      return {
           
            "color": this.color
      }
   };
   //create map
  this.mapArray = new Array();
  //create list of player locations
  this.playerArray = new Array();
   for (var i = 0; i < size; i++) {
     this.mapArray[i] =  new Array();
     for (var l = 0; l < size; l++) {
       var tileType = 0;
       var colorVal = "#ffffff";
       if ((i === 0) || (l === 0) || (i === this.size-1) || (l === this.size-1) ) {
         tileType = 1;
         colorVal = "#000000";
       }
      this.mapArray[i][l] = new tile({
         "x": i,
         "y": l,
         "color": colorVal,
         "objects": {},
         "kind": tileType
       });
      console.log(tileType);
     }
   }
 }
};
module.exports.map.prototype.getAbove = function (x,y) {
 if (y > 0) {
       return this.mapArray[x][y-1];
     } else {
      return new tile({
         "x": NaN,
         "y": NaN,
         "color": "#000000",
         "objects": {},
         "kind": 1
       });
     }
  return this.mapArray[x][y-1];
};
module.exports.map.prototype.getBelow = function (x,y) {
  if (y < this.mapArray.length) {
       return this.mapArray[x][y+1];
     } else {
      return new tile({
         "x": NaN,
         "y": NaN,
         "color": "#000000",
         "objects": {},
         "kind": 1
       });
     }
};
module.exports.map.prototype.getRight = function (x,y) {
    if (x < this.mapArray.length) {
       return this.mapArray[x+1][y];
     } else {
      return new tile({
         "x": NaN,
         "y": NaN,
         "color": "#000000",
         "objects": {},
         "kind": 1
       });
     }
};
module.exports.map.prototype.getLeft = function (x,y) {
    if (x > 0) {
       return this.mapArray[x+1][y];
     } else {
      return new tile({
         "x": NaN,
         "y": NaN,
         "color": "#000000",
         "objects": {},
         "kind": 1
       });
     }};
module.exports.map.prototype.getTile = function (x,y) {
return this.mapArray[x][y];
};
module.exports.map.prototype.setTile = function (x,y,element) {
 this.mapArray[x][y] = element;
};
module.exports.map.prototype.updatePlayer = function (player) {
{'fraction_non_alphanumeric': 0.17212713936430318, 'fraction_numerical': 0.014180929095354523, 'mean_word_length': 1.865950490425035, 'pattern_counts': {'":': 34, '<': 12, '<?xml version=': 0, '>': 10, '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': '3352944', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1973, 'n_words': 434}