-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgenerator_v1.js
158 lines (136 loc) · 3.56 KB
/
generator_v1.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// This file should not be edited anymore since a stable version refers to it
var generator_v1 = function(layout, difficulty, bingoList)
{
var amountOfVeryHard;
var amountOfHard;
var amountOfMedium;
var currentSheet = [];
var sheetLayout = [];
if (layout == "set")
{
sheetLayout = [ 1, 2, 0, 2, 1,
2, 0, 1, 0, 2,
0, 1, 3, 1, 0,
2, 0, 1, 0, 2,
1, 2, 0, 2, 1];
}
else if (layout == "random")
{
sheetLayout = [ 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0];
switch(difficulty)
{
case 2:
amountOfVeryHard = 0;
amountOfHard = 2;
amountOfMedium = 5;
break;
case 3:
amountOfVeryHard = Math.floor((Math.random() * 1.5));
amountOfHard = Math.floor(Math.random() * (4-2) + 2);
amountOfMedium = Math.floor(Math.random() * (8-6) + 6);
break;
case 4:
amountOfVeryHard = Math.floor((Math.random() * 2));
amountOfHard = Math.floor(Math.random() * (5-3) + 3);
amountOfMedium = Math.floor(Math.random() * (10-8) + 8);
break;
case 5:
amountOfVeryHard = 3;
amountOfHard = 6;
amountOfMedium = 13;
break;
default:
amountOfVeryHard = 0;
amountOfHard = 0;
amountOfMedium = 0;
}
if (amountOfVeryHard > bingoList[3].length)
{
amountOfVeryHard = bingoList[3].length;
}
if (amountOfHard > bingoList[2].length)
{
amountOfHard = bingoList[2].length;
}
if (amountOfMedium > bingoList[1].length)
{
amountOfMedium = bingoList[1].length;
}
function distributeDifficulty(amountOfDifficulty, difficulty)
{
for (var i = 0; i < amountOfDifficulty; i++)
{
var cont = true;
do
{
cont = true;
var rng = Math.floor((Math.random() * 25));
if (sheetLayout[rng] == 0)
{
sheetLayout[rng] = difficulty;
}
else
{
cont = false;
}
}
while (cont == false);
}
}
distributeDifficulty(amountOfVeryHard, 3);
distributeDifficulty(amountOfHard, 2);
distributeDifficulty(amountOfMedium, 1);
}
for (var i=0; i<=24; i++)
{
do
{
var cont = true;
var rng = Math.floor((Math.random() * bingoList[sheetLayout[i]].length - 1) + 1);
var goalCandidate = bingoList[sheetLayout[i]][rng];
// Check if the goal has an infrequency modifier
if (typeof goalCandidate.infrequency !== 'undefined')
{
// If it does, make it less likely to appear based on the value of infrequency
if (Math.floor((Math.random() * goalCandidate.infrequency) + 1) < goalCandidate.infrequency)
{
cont = false;
}
}
for (var z=0; z <= 24; z++)
{
if (typeof currentSheet[z] !== 'undefined')
{
// Check if the goal generated is already on the sheet
if (currentSheet[z].name == goalCandidate.name)
{
// If it is get a new goal
cont = false;
}
// Check if the goal generated has any anti synergy with anything already on the sheet
else if (currentSheet[z].antisynergy == goalCandidate.antisynergy && typeof currentSheet[z].antisynergy !== 'undefined')
{
// If it is get a new goal
cont = false;
}
}
}
}
while (!cont);
var goal = JSON.parse(JSON.stringify(goalCandidate)); // Clone object
// Replace random ranges in goal name
goal.generatedName = goal.name.replace(/\((\d+)-(\d+)\)/g, function(match, n1, n2, offset, input)
{
n1 = parseInt(n1);
n2 = parseInt(n2);
return Math.floor(Math.random() * (n2-n1+1) + n1);
});
currentSheet[i] = goal;
//goal.difficulty = sheetLayout[i];
}
return currentSheet;
}