module.exports = { generateMap: function(width, height) { var map = []; for(var w=0;w=width-1 || h>=height-1) { map[w][h] = "0"; } else { map[w][h] = "0"; p = 1; if(map[w-1][h]=="#") p+=43; if(map[w][h-1]=="#") p+=43; if(rand(p)) map[w][h] = "#"; } } } //preprocessing for(i=0;i<2;i++) { //Reduce little ilands for(var w=0;w 4) map[w][h] = "0"; } } } } for(i=0;i<4;i++) { //expand all islands var orgMap = []; for(var w=0;w=width-1 || h>=height-1)) { map[w-1][h]="#" map[w+1][h]="#" map[w][h-1]="#" map[w][h+1]="#" map[w-1][h-1]="#" map[w-1][h+1]="#" map[w+1][h-1]="#" map[w+1][h+1]="#" } } } } for(i=0;i<4;i++) { //fill water holes for(var w=0;w=width-1 || h>=height-1)) { var groundCtn = 0; if(map[w-1][h]=="#") groundCtn++; if(map[w+1][h]=="#") groundCtn++; if(map[w][h-1]=="#") groundCtn++; if(map[w][h+1]=="#") groundCtn++; if(map[w-1][h-1]=="#") groundCtn++; if(map[w-1][h+1]=="#") groundCtn++; if(map[w+1][h-1]=="#") groundCtn++; if(map[w+1][h+1]=="#") groundCtn++; if(groundCtn > 5) map[w][h] = "#"; } } } } /* groundtypes g = ground w = water */ //Set ground type for(var w=0;w=width-1 || h>=height-1)) { if(map[w+1][h]=="#") { map[w][h] = "1"; } if(map[w-1][h]=="#") { map[w][h] = "2"; } if(map[w][h-1]=="#") { map[w][h] = "3"; } if(map[w][h+1]=="#") { map[w][h] = "4"; } if(map[w][h+1]=="#" && map[w+1][h]=="#") { map[w][h] = "5"; } if(map[w][h-1]=="#" && map[w+1][h]=="#") { map[w][h] = "6"; } if(map[w][h+1]=="#" && map[w-1][h]=="#") { map[w][h] = "7"; } if(map[w][h-1]=="#" && map[w-1][h]=="#") { map[w][h] = "8"; } if(map[w-1][h-1]=="#") { map[w][h] = "9"; } } } } return map; } }; function rand(p) { if(p > Math.random()*100) return true; return false; }