-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgenerator_v2.js
196 lines (170 loc) · 4.59 KB
/
generator_v2.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// This file should not be edited anymore since a stable version refers to it
var generator_v2 = function(layout, difficulty, bingoList)
{
var amountOfVeryHard;
var amountOfHard;
var amountOfMedium;
var amountOfEasy;
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)
{
// Easy with some Very Easy
case 2:
amountOfVeryHard = 0;
amountOfHard = 0;
amountOfMedium = 0;
amountOfEasy = getRandomInt(15, 19);
break;
// Medium with some Easy
case 3:
amountOfVeryHard = 0;
amountOfHard = 0;
amountOfMedium = getRandomInt(15, 19);
amountOfEasy = 25 - amountOfMedium;
break;
// Hard with some Medium
case 4:
amountOfVeryHard = 0;
amountOfHard = getRandomInt(15, 19);
amountOfMedium = 25 - amountOfHard;
amountOfEasy = 25 - amountOfHard - amountOfMedium;
break;
// Very Hard with some Hard
case 5:
amountOfVeryHard = getRandomInt(15, 19);
amountOfHard = 25 - amountOfVeryHard;
amountOfMedium = 25 - amountOfHard - amountOfVeryHard;
amountOfEasy = 25 - amountOfHard - amountOfMedium- amountOfVeryHard;
break;
// Very Easy
default:
amountOfVeryHard = 0;
amountOfHard = 0;
amountOfMedium = 0;
amountOfEasy = 0;
}
function distributeDifficulty(amountOfDifficulty, difficulty)
{
for (var i = 0; i < amountOfDifficulty; i++)
{
var cont = true;
var failSafe = 0;
do
{
cont = true;
failSafe++;
var rng = Math.floor((Math.random() * 25));
if (sheetLayout[rng] == 0)
{
sheetLayout[rng] = difficulty;
}
else
{
cont = false;
if (failSafe >= 500)
{
break;
}
}
}
while (cont == false);
}
}
distributeDifficulty(amountOfVeryHard, 4);
distributeDifficulty(amountOfHard, 3);
distributeDifficulty(amountOfMedium, 2);
distributeDifficulty(amountOfEasy, 1);
}
for (var i=0; i<=24; i++)
{
var failSafe = 0;
do
{
var cont = true;
failSafe++;
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;
}
// Check if the goal generated is a catalyst for anything already on the sheet
else if (currentSheet[z].reactant == goalCandidate.catalyst && typeof currentSheet[z].reactant !== 'undefined')
{
// If it is get a new goal
cont = false;
}
// Check if the goal generated is a reactant for anything already on the sheet
else if (currentSheet[z].catalyst == goalCandidate.reactant && typeof currentSheet[z].catalyst !== 'undefined')
{
// If it is get a new goal
cont = false;
}
}
}
// If the loop is stuck because no more suitable goals
if (failSafe >= 500)
{
// Check for a non-broken goal list
if (sheetLayout[i] == 0)
{
window.alert("Invalid Goal List");
break;
}
// Move the difficulty down by one
sheetLayout[i]--;
failSafe = 0;
}
}
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 getRandomInt(n1, n2);
});
currentSheet[i] = goal;
// TESTING PURPOSES
goal.difficulty = sheetLayout[i];
}
return currentSheet;
}