-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapGen.java
More file actions
81 lines (58 loc) · 1.9 KB
/
Copy pathMapGen.java
File metadata and controls
81 lines (58 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// parametized random map gnerator
// *when run, output should be piped into map text file
// *for now, only does rocks and spawn point
import java.util.Random;
public class MapGen {
private static int size; //all maps are square
private static double rockFreq; // [0-1) range
private static Random random;
private static boolean[][] grid;
//--->baddie difficulty
//--->resource frequency
public static void main(String[] args) {
if(args.length!=2 && args.length!=3) {
System.err.println("USAGE: <size> <rock freq> <optional: seed>");
System.exit(0);
}
size=Integer.parseInt(args[0]);
rockFreq=Double.parseDouble(args[1])%1;
long seed=(long)(Math.random()*100000);
if(args.length==3) seed=Long.parseLong(args[2]);
random=new Random(seed);
//print size,spawn
System.out.println(size+" "+size);
System.out.println(size/2+" "+(size/2));
grid=new boolean[size][size];
// value = "is rocks here"
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
grid[i][j]=false;
//create and expand rocks:
int rockSeeds=(int)((size/10.0)*(rockFreq*(0.9+random.nextDouble()*0.2)));
/* ** */System.err.println(rockSeeds);
for(int i=0;i<rockSeeds;i++) {
int rx=(int)(random.nextDouble()*size);
int ry=(int)(random.nextDouble()*size);
makeRock(rx,ry,0);
}
//clear area around spawn:
int diff=size/2-10;
for(int i=-10;i<=20;i++)
for(int j=-10;j<=20;j++)
grid[i+diff][j+diff]=false;
//print grid spaces:
for(int i=0;i<size;i++)
for(int j=0;j<size;j++) {
if(grid[i][j]) System.out.print("w ");
else System.out.print("e ");
}
} //main
private static void makeRock(int x,int y,int depth) {
if(depth>10 || random.nextDouble()*(depth/1.5)>0.8) return;
grid[x][y]=true;
if(x>0) makeRock(x-1,y,depth+1);
if(x<size-1) makeRock(x+1,y,depth+1);
if(y>0) makeRock(x,y-1,depth+1);
if(y<size-1) makeRock(x,y+1,depth+1);
} //makeRock
} //class