-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.js
More file actions
70 lines (49 loc) · 1.85 KB
/
Copy pathrules.js
File metadata and controls
70 lines (49 loc) · 1.85 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
function applyRule(lookupMap, settings, row, col) {
switch (settings.rule) {
case "fixed":
return fixedRule(lookupMap, settings, row, col)
case "random":
return randomRule(lookupMap, settings, row, col)
case "latitude":
return latitudeRule(lookupMap, settings, row, col)
case "randomLatitude":
return randomLatitudeRule(lookupMap, settings, row, col)
default:
return lookupMap[row][col]
}
}
function fixedRule(lookupMap, settings, row, col) {
var neighbourWalls = getNeighborhood(lookupMap, settings, row, col)
var threshold = parseInt(settings.ruleValue)
if (neighbourWalls > threshold) {
return 1
} else if (neighbourWalls < threshold) {
return 0
}
return lookupMap[row][col]
}
function randomRule(lookupMap, settings, row, col) {
var neighbourWalls = getNeighborhood(lookupMap, settings, row, col)
var threshold = Math.min(settings.ruleValue, 100)
threshold = neighbourWalls/10 * settings.ruleValue
var choice = Math.round((Math.random() * 100)) + 1
return choice >= threshold ? 1 : 0
}
function latitudeRule(lookupMap, settings, row, col) {
if (settings.currentPass > 0) {
settings.rule = "fixed"
settings.ruleValue = settings.range * 3.5 + 1
return randomRule(lookupMap, settings, row, col)
}
var neighbourWalls = getNeighborhood(lookupMap, settings, row, col)
var thresholdRow = Math.floor(_mapHeight * settings.ruleValue/100)
var distance = Math.abs(thresholdRow - row)
var distancePercentage = distance/_mapHeight * 100
var steppedThreshold = stepValue(distancePercentage, 1, 0, 100, 8)
var randomValue = Math.round((Math.random() * 100)) + 1
return randomValue >= steppedThreshold + (100/3)
}
function randomLatitudeRule(lookupMap, settings, row, col) {
settings.ruleValue = Math.round((Math.random() * 100)) + 1
return latitudeRule(lookupMap, settings, row, col)
}