improve map qually

This commit is contained in:
rofl256 2016-10-20 11:30:31 +02:00
parent 2fbd703d33
commit 9c539f7758
2 changed files with 51 additions and 53 deletions

View File

@ -13,7 +13,7 @@ socket.on('getmap', function (map) {
domMap.empty();
for(var w=0;w<map.length;w++) {
for(var h=0;h<map[w].length;h++) {
var spClass = "ground";
var spClass = "ground_";
if(map[w][h]=="0" || (w<=0 || h<=0 || w>=map.length-1 || h>=map[w].length-1))
spClass = "water";
else if((map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2" && map[w-1][h+1]=="1") || (map[w-1][h-1]=="0" && map[w][h]=="1" && map[w+1][h]=="2" && map[w+1][h-1]=="1") || (map[w+1][h]=="2" && map[w][h]=="1" && map[w][h+1]=="2")) {

View File

@ -17,7 +17,7 @@ module.exports = {
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","4","4","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","4","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","4","0","0","0","0","0"];
map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"];
@ -39,23 +39,18 @@ module.exports = {
}
}
return map;
//return map;
for(var w=0;w<width;w++) {
map[w] = [];
for(var h=0;h<height;h++) {
//make border
if(w<=0 || h<=0 || w>=width-1 || h>=height-1) {
map[w][h] = "0";
} else {
map[w][h] = "0";
p = 0.1;
if(rand(p))
map[w][h] = "#";
}
}
}
//preprocessing
@ -85,40 +80,43 @@ module.exports = {
}
}
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(h<4 || w<4 || w>width-5 || h>height-5) {
map[w][h] = "0"; //border water
}
}
}
for(i=0;i<10;i++) { //fill water holes
for(var w=1;w<width-1;w++) {
for(var h=1;h<height-1;h++) {
for(var i=0;i<10;i++) {
for(var w=7;w<width-7;w++) {
for(var h=7;h<height-7;h++) {
if(map[w][h]=="0") {
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)
if(map[w][h-1]=="#" || map[w][h-2]=="#" || map[w][h-3]=="#" || map[w][h-4]=="#") {
if(map[w][h+1]=="#" || map[w][h+2]=="#" || map[w][h+3]=="#" || map[w][h+4]=="#") {
map[w][h]="#";
}
}
if(map[w-1][h]=="#" || map[w-2][h]=="#" || map[w-3][h]=="#" || map[w-4][h]=="#") {
if(map[w+1][h]=="#" || map[w+2][h]=="#" || map[w+3][h]=="#" || map[w+4][h]=="#") {
map[w][h]="#";
}
}
if(map[w-1][h-1]=="#" || map[w-2][h-2]=="#" || map[w-3][h-3]=="#" || map[w-4][h-4]=="#") {
if(map[w+1][h+1]=="#" || map[w+2][h+2]=="#" || map[w+3][h+3]=="#" || map[w+4][h+4]=="#") {
map[w][h]="#";
}
}
if(map[w+1][h-1]=="#" || map[w+2][h-2]=="#" || map[w+3][h-3]=="#" || map[w+4][h-4]=="#") {
if(map[w-1][h+1]=="#" || map[w-2][h+2]=="#" || map[w-3][h+3]=="#" || map[w-4][h+4]=="#") {
map[w][h]="#";
}
}
}
}
}
}
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(h<=7 || w<=7 || w>width-7 || h>height-7) {
map[w][h] = "0"; //border water
}
}
}
@ -136,17 +134,17 @@ module.exports = {
}
}
// var g = [4,3,2];
// for(var k=0;k<g.length;k++) {
// var i = g[k]+"";
// for(var w=0;w<width;w++) {
// for(var h=0;h<height;h++) {
// if(map[w][h] == "0" && !(w<=0 || h<=0 || w>=width-1 || h>=height-1) && (map[w-1][h]==i || map[w][h-1]==i || map[w][h+1]==i || map[w+1][h]==i || map[w+1][h+1]==i || map[w-1][h-1]==i || map[w+1][h-1]==i || map[w-1][h+1]==i)) {
// map[w][h] = (i-1)+""; //set ground
// }
// }
// }
// }
var g = [4,3,2];
for(var k=0;k<g.length;k++) {
var i = g[k]+"";
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(map[w][h] == "0" && !(w<=0 || h<=0 || w>=width-1 || h>=height-1) && (map[w-1][h]==i || map[w][h-1]==i || map[w][h+1]==i || map[w+1][h]==i || map[w+1][h+1]==i || map[w-1][h-1]==i || map[w+1][h-1]==i || map[w-1][h+1]==i)) {
map[w][h] = (i-1)+""; //set ground
}
}
}
}
return map;