|
@@ -1,3 +1,4 @@
|
|
1
|
+var RandomUtil = require('./RandomUtil');
|
1
|
2
|
//var nouns = [
|
2
|
3
|
//];
|
3
|
4
|
var pluralNouns = [
|
|
@@ -160,14 +161,6 @@ var PATTERNS = [
|
160
|
161
|
//"_ADJECTIVE__PLURALNOUN_AtThe_PLACE_",
|
161
|
162
|
];
|
162
|
163
|
|
163
|
|
-
|
164
|
|
-/*
|
165
|
|
- * Returns a random element from the array 'arr'
|
166
|
|
- */
|
167
|
|
-function randomElement(arr) {
|
168
|
|
- return arr[Math.floor(Math.random() * arr.length)];
|
169
|
|
-}
|
170
|
|
-
|
171
|
164
|
/*
|
172
|
165
|
* Returns true if the string 's' contains one of the
|
173
|
166
|
* template strings.
|
|
@@ -183,17 +176,17 @@ function hasTemplate(s) {
|
183
|
176
|
/**
|
184
|
177
|
* Generates new room name.
|
185
|
178
|
*/
|
186
|
|
-var RoomNameGenerator = {
|
|
179
|
+var RoomnameGenerator = {
|
187
|
180
|
generateRoomWithoutSeparator: function() {
|
188
|
181
|
// Note that if more than one pattern is available, the choice of
|
189
|
182
|
// 'name' won't have a uniform distribution amongst all patterns (names
|
190
|
183
|
// from patterns with fewer options will have higher probability of
|
191
|
184
|
// being chosen that names from patterns with more options).
|
192
|
|
- var name = randomElement(PATTERNS);
|
|
185
|
+ var name = RandomUtil.randomElement(PATTERNS);
|
193
|
186
|
var word;
|
194
|
187
|
while (hasTemplate(name)) {
|
195
|
188
|
for (var template in CATEGORIES) {
|
196
|
|
- word = randomElement(CATEGORIES[template]);
|
|
189
|
+ word = RandomUtil.randomElement(CATEGORIES[template]);
|
197
|
190
|
name = name.replace(template, word);
|
198
|
191
|
}
|
199
|
192
|
}
|
|
@@ -202,4 +195,4 @@ var RoomNameGenerator = {
|
202
|
195
|
}
|
203
|
196
|
};
|
204
|
197
|
|
205
|
|
-module.exports = RoomNameGenerator;
|
|
198
|
+module.exports = RoomnameGenerator;
|