Best JavaScript code snippet using fast-check-monorepo
encounter-generator.ts
Source:encounter-generator.ts
1import { IMonster } from "./monster-manager";2import { Monsters } from "./monsters";3export interface IEncounterGenerator4{5 GenerateEncounter(numPlayers: number, playerLevel: number, singleMonster: boolean, enemyType?: string): IMonster[]6}7interface IMonsterRatio8{9 numMonsters: number;10 numCharacters: number;11 cr: number;12}13interface IMonsterGroup14{15 num: number;16 cr: number;17}18export class EncounterGenerator implements IEncounterGenerator19{20 public GenerateEncounter(numPlayers: number, playerLevel: number, singleMonster: boolean, enemyType?: string)21 {22 if (singleMonster && numPlayers >= 4 && numPlayers <= 6)23 {24 return this.getMonstersByCr([{ num: 1, cr: this.singleMonsterTable(numPlayers, playerLevel) }], enemyType);25 }26 switch (playerLevel)27 {28 case 1:29 return this.getMonstersByCr(this.multipleMonsterFirst(numPlayers, singleMonster), enemyType);30 case 2:31 return this.getMonstersByCr(this.multipleMonsterSecond(numPlayers, singleMonster), enemyType);32 case 3:33 return this.getMonstersByCr(this.multipleMonsterThird(numPlayers, singleMonster), enemyType);34 case 4:35 return this.getMonstersByCr(this.multipleMonsterFourth(numPlayers, singleMonster), enemyType);36 case 5:37 return this.getMonstersByCr(this.multipleMonsterFifth(numPlayers, singleMonster), enemyType);38 case 6:39 return this.getMonstersByCr(this.multipleMonsterSixth(numPlayers, singleMonster), enemyType);40 case 7:41 return this.getMonstersByCr(this.multipleMonsterSeventh(numPlayers, singleMonster), enemyType);42 case 8:43 return this.getMonstersByCr(this.multipleMonsterEighth(numPlayers, singleMonster), enemyType);44 case 9:45 return this.getMonstersByCr(this.multipleMonsterNinth(numPlayers, singleMonster), enemyType);46 case 10:47 return this.getMonstersByCr(this.multipleMonsterTenth(numPlayers, singleMonster), enemyType);48 case 11:49 return this.getMonstersByCr(this.multipleMonsterEleventh(numPlayers, singleMonster), enemyType);50 case 12:51 return this.getMonstersByCr(this.multipleMonsterTwelf(numPlayers, singleMonster), enemyType);52 case 13:53 return this.getMonstersByCr(this.multipleMonsterThirteenth(numPlayers, singleMonster), enemyType);54 case 14:55 return this.getMonstersByCr(this.multipleMonsterFourteenth(numPlayers, singleMonster), enemyType);56 case 15:57 return this.getMonstersByCr(this.multipleMonsterFifthteenth(numPlayers, singleMonster), enemyType);58 case 16:59 return this.getMonstersByCr(this.multipleMonsterSixteenth(numPlayers, singleMonster), enemyType);60 case 17:61 return this.getMonstersByCr(this.multipleMonsterSeventeenth(numPlayers, singleMonster), enemyType);62 case 18:63 return this.getMonstersByCr(this.multipleMonsterEightteenth(numPlayers, singleMonster), enemyType);64 case 19:65 return this.getMonstersByCr(this.multipleMonsterNineteenth(numPlayers, singleMonster), enemyType);66 case 20:67 return this.getMonstersByCr(this.multipleMonsterTwentieth(numPlayers, singleMonster), enemyType);68 default:69 return [];70 }71 }72 protected getMonstersByCr(crs: IMonsterGroup[], enemyType?: string): IMonster[]73 {74 const monsters: IMonster[] = [];75 crs.forEach(group =>76 {77 let monstersForCr = Monsters.filter(monster => monster.CR === group.cr);78 if (enemyType)79 {80 let tempArr = monstersForCr.filter(monster => monster.Type === enemyType);81 if (tempArr.length > 0) monstersForCr = tempArr;82 }83 const monster = monstersForCr[Math.floor(Math.random() * monstersForCr.length)];84 monster.Amount = group.num;85 monsters.push(monster);86 });87 return monsters88 }89 protected singleMonsterTable(numPlayers: number, playerLevel: number): number90 {91 let cr: number;92 if (playerLevel === 1)93 {94 cr = numPlayers === 4 ? 1 : 295 }96 else if (playerLevel >= 2 && playerLevel <= 4)97 {98 cr = playerLevel + (numPlayers - 4);99 }100 else if (playerLevel <= 17)101 {102 cr = playerLevel + (numPlayers - 1);103 }104 else105 {106 cr = playerLevel + (numPlayers - 2);107 }108 return cr;109 }110 protected multipleMonsterFirst(numPlayers: number, singleMonster = false): IMonsterGroup[]111 {112 const ratios: IMonsterRatio[] = [113 { numCharacters: 1, numMonsters: 2, cr: 0.125 },114 { numCharacters: 1, numMonsters: 1, cr: 0.25 },115 { numCharacters: 3, numMonsters: 1, cr: 0.5 },116 { numCharacters: 5, numMonsters: 1, cr: 1 },117 ]118 if (singleMonster)119 {120 if (numPlayers >= 5) { return [{ num: 1, cr: 1 }]; }121 else if (numPlayers >= 3) { return [{ num: 1, cr: 0.5 }]; }122 else { return [{ num: 1, cr: 0.25 }]; }123 }124 else125 {126 return this.getMonsterCrs(ratios, numPlayers);127 }128 }129 protected multipleMonsterSecond(numPlayers: number, singleMonster = false): IMonsterGroup[]130 {131 const ratios: IMonsterRatio[] = [132 { numCharacters: 1, numMonsters: 3, cr: 0.125 },133 { numCharacters: 1, numMonsters: 2, cr: 0.25 },134 { numCharacters: 1, numMonsters: 1, cr: 0.5 },135 { numCharacters: 3, numMonsters: 1, cr: 1 },136 { numCharacters: 6, numMonsters: 1, cr: 2 },137 ]138 if (singleMonster)139 {140 if (numPlayers >= 6) { return [{ num: 1, cr: 2 }]; }141 else if (numPlayers >= 3) { return [{ num: 1, cr: 1 }]; }142 else { return [{ num: 1, cr: 0.5 }]; }143 }144 else145 {146 return this.getMonsterCrs(ratios, numPlayers);147 }148 }149 protected multipleMonsterThird(numPlayers: number, singleMonster = false): IMonsterGroup[]150 {151 const ratios: IMonsterRatio[] = [152 { numCharacters: 1, numMonsters: 5, cr: 0.125 },153 { numCharacters: 1, numMonsters: 2, cr: 0.25 },154 { numCharacters: 1, numMonsters: 1, cr: 0.5 },155 { numCharacters: 2, numMonsters: 1, cr: 1 },156 { numCharacters: 4, numMonsters: 1, cr: 2 },157 { numCharacters: 6, numMonsters: 1, cr: 3 },158 ]159 if (singleMonster)160 {161 if (numPlayers >= 6) { return [{ num: 1, cr: 3 }]; }162 else if (numPlayers >= 4) { return [{ num: 1, cr: 2 }]; }163 else if (numPlayers >= 2) { return [{ num: 1, cr: 1 }]; }164 else { return [{ num: 1, cr: 0.5 }]; }165 }166 else167 {168 return this.getMonsterCrs(ratios, numPlayers);169 }170 }171 protected multipleMonsterFourth(numPlayers: number, singleMonster = false): IMonsterGroup[]172 {173 const ratios: IMonsterRatio[] = [174 { numCharacters: 1, numMonsters: 8, cr: 0.125 },175 { numCharacters: 1, numMonsters: 4, cr: 0.25 },176 { numCharacters: 1, numMonsters: 2, cr: 0.5 },177 { numCharacters: 1, numMonsters: 1, cr: 1 },178 { numCharacters: 2, numMonsters: 1, cr: 2 },179 { numCharacters: 4, numMonsters: 1, cr: 3 },180 { numCharacters: 6, numMonsters: 1, cr: 4 },181 ]182 if (singleMonster)183 {184 if (numPlayers >= 6) { return [{ num: 1, cr: 4 }]; }185 else if (numPlayers >= 4) { return [{ num: 1, cr: 3 }]; }186 else if (numPlayers >= 2) { return [{ num: 1, cr: 2 }]; }187 else { return [{ num: 1, cr: 1 }]; }188 }189 else190 {191 return this.getMonsterCrs(ratios, numPlayers);192 }193 }194 protected multipleMonsterFifth(numPlayers: number, singleMonster = false): IMonsterGroup[]195 {196 const ratios: IMonsterRatio[] = [197 { numCharacters: 1, numMonsters: 12, cr: 0.125 },198 { numCharacters: 1, numMonsters: 8, cr: 0.25 },199 { numCharacters: 1, numMonsters: 4, cr: 0.5 },200 { numCharacters: 1, numMonsters: 2, cr: 1 },201 { numCharacters: 1, numMonsters: 1, cr: 2 },202 { numCharacters: 2, numMonsters: 1, cr: 3 },203 { numCharacters: 3, numMonsters: 1, cr: 4 },204 { numCharacters: 5, numMonsters: 1, cr: 5 },205 { numCharacters: 6, numMonsters: 1, cr: 6 },206 ]207 if (singleMonster)208 {209 if (numPlayers >= 6) { return [{ num: 1, cr: 6 }]; }210 else if (numPlayers >= 5) { return [{ num: 1, cr: 5 }]; }211 else if (numPlayers >= 3) { return [{ num: 1, cr: 4 }]; }212 else if (numPlayers >= 2) { return [{ num: 1, cr: 3 }]; }213 else { return [{ num: 1, cr: 2 }]; }214 }215 else216 {217 return this.getMonsterCrs(ratios, numPlayers);218 }219 }220 protected multipleMonsterSixth(numPlayers: number, singleMonster = false): IMonsterGroup[]221 {222 const ratios: IMonsterRatio[] = [223 { numCharacters: 1, numMonsters: 12, cr: 0.125 },224 { numCharacters: 1, numMonsters: 9, cr: 0.25 },225 { numCharacters: 1, numMonsters: 5, cr: 0.5 },226 { numCharacters: 1, numMonsters: 2, cr: 1 },227 { numCharacters: 1, numMonsters: 1, cr: 2 },228 { numCharacters: 2, numMonsters: 1, cr: 3 },229 { numCharacters: 2, numMonsters: 1, cr: 4 },230 { numCharacters: 4, numMonsters: 1, cr: 5 },231 { numCharacters: 5, numMonsters: 1, cr: 6 },232 { numCharacters: 6, numMonsters: 1, cr: 7 },233 ]234 if (singleMonster)235 {236 if (numPlayers >= 6) { return [{ num: 1, cr: 7 }]; }237 else if (numPlayers >= 5) { return [{ num: 1, cr: 6 }]; }238 else if (numPlayers >= 4) { return [{ num: 1, cr: 5 }]; }239 else if (numPlayers >= 2) { return [{ num: 1, cr: 4 }]; }240 else { return [{ num: 1, cr: 2 }]; }241 }242 else243 {244 return this.getMonsterCrs(ratios, numPlayers);245 }246 }247 protected multipleMonsterSeventh(numPlayers: number, singleMonster = false): IMonsterGroup[]248 {249 const ratios: IMonsterRatio[] = [250 { numCharacters: 1, numMonsters: 12, cr: 0.125 },251 { numCharacters: 1, numMonsters: 12, cr: 0.25 },252 { numCharacters: 1, numMonsters: 6, cr: 0.5 },253 { numCharacters: 1, numMonsters: 3, cr: 1 },254 { numCharacters: 1, numMonsters: 1, cr: 2 },255 { numCharacters: 1, numMonsters: 1, cr: 3 },256 { numCharacters: 2, numMonsters: 1, cr: 4 },257 { numCharacters: 3, numMonsters: 1, cr: 5 },258 { numCharacters: 4, numMonsters: 1, cr: 6 },259 { numCharacters: 5, numMonsters: 1, cr: 7 },260 ]261 if (singleMonster)262 {263 if (numPlayers >= 5) { return [{ num: 1, cr: 7 }]; }264 else if (numPlayers >= 4) { return [{ num: 1, cr: 6 }]; }265 else if (numPlayers >= 3) { return [{ num: 1, cr: 5 }]; }266 else if (numPlayers >= 2) { return [{ num: 1, cr: 4 }]; }267 else { return [{ num: 1, cr: 3 }]; }268 }269 else270 {271 return this.getMonsterCrs(ratios, numPlayers);272 }273 }274 protected multipleMonsterEighth(numPlayers: number, singleMonster = false): IMonsterGroup[]275 {276 const ratios: IMonsterRatio[] = [277 { numCharacters: 1, numMonsters: 12, cr: 0.125 },278 { numCharacters: 1, numMonsters: 12, cr: 0.25 },279 { numCharacters: 1, numMonsters: 7, cr: 0.5 },280 { numCharacters: 1, numMonsters: 4, cr: 1 },281 { numCharacters: 1, numMonsters: 2, cr: 2 },282 { numCharacters: 1, numMonsters: 1, cr: 3 },283 { numCharacters: 2, numMonsters: 1, cr: 4 },284 { numCharacters: 3, numMonsters: 1, cr: 5 },285 { numCharacters: 3, numMonsters: 1, cr: 6 },286 { numCharacters: 4, numMonsters: 1, cr: 7 },287 { numCharacters: 6, numMonsters: 1, cr: 8 },288 ]289 if (singleMonster)290 {291 if (numPlayers >= 6) { return [{ num: 1, cr: 8 }]; }292 else if (numPlayers >= 4) { return [{ num: 1, cr: 7 }]; }293 else if (numPlayers >= 3) { return [{ num: 1, cr: 6 }]; }294 else if (numPlayers >= 2) { return [{ num: 1, cr: 4 }]; }295 else { return [{ num: 1, cr: 3 }]; }296 }297 else298 {299 return this.getMonsterCrs(ratios, numPlayers);300 }301 }302 protected multipleMonsterNinth(numPlayers: number, singleMonster = false): IMonsterGroup[]303 {304 const ratios: IMonsterRatio[] = [305 { numCharacters: 1, numMonsters: 12, cr: 0.125 },306 { numCharacters: 1, numMonsters: 12, cr: 0.25 },307 { numCharacters: 1, numMonsters: 8, cr: 0.5 },308 { numCharacters: 1, numMonsters: 4, cr: 1 },309 { numCharacters: 1, numMonsters: 2, cr: 2 },310 { numCharacters: 1, numMonsters: 1, cr: 3 },311 { numCharacters: 1, numMonsters: 1, cr: 4 },312 { numCharacters: 2, numMonsters: 1, cr: 5 },313 { numCharacters: 3, numMonsters: 1, cr: 6 },314 { numCharacters: 4, numMonsters: 1, cr: 7 },315 { numCharacters: 5, numMonsters: 1, cr: 8 },316 { numCharacters: 6, numMonsters: 1, cr: 9 },317 ]318 if (singleMonster)319 {320 if (numPlayers >= 6) { return [{ num: 1, cr: 9 }]; }321 else if (numPlayers >= 5) { return [{ num: 1, cr: 8 }]; }322 else if (numPlayers >= 4) { return [{ num: 1, cr: 7 }]; }323 else if (numPlayers >= 3) { return [{ num: 1, cr: 6 }]; }324 else if (numPlayers >= 2) { return [{ num: 1, cr: 5 }]; }325 else { return [{ num: 1, cr: 4 }]; }326 }327 else328 {329 return this.getMonsterCrs(ratios, numPlayers);330 }331 }332 protected multipleMonsterTenth(numPlayers: number, singleMonster = false): IMonsterGroup[]333 {334 const ratios: IMonsterRatio[] = [335 { numCharacters: 1, numMonsters: 12, cr: 0.125 },336 { numCharacters: 1, numMonsters: 12, cr: 0.25 },337 { numCharacters: 1, numMonsters: 10, cr: 0.5 },338 { numCharacters: 1, numMonsters: 5, cr: 1 },339 { numCharacters: 1, numMonsters: 2, cr: 2 },340 { numCharacters: 1, numMonsters: 1, cr: 3 },341 { numCharacters: 1, numMonsters: 1, cr: 4 },342 { numCharacters: 2, numMonsters: 1, cr: 5 },343 { numCharacters: 2, numMonsters: 1, cr: 6 },344 { numCharacters: 3, numMonsters: 1, cr: 7 },345 { numCharacters: 4, numMonsters: 1, cr: 8 },346 { numCharacters: 5, numMonsters: 1, cr: 9 },347 { numCharacters: 6, numMonsters: 1, cr: 10 },348 ]349 if (singleMonster)350 {351 if (numPlayers >= 6) { return [{ num: 1, cr: 10 }]; }352 else if (numPlayers >= 5) { return [{ num: 1, cr: 9 }]; }353 else if (numPlayers >= 4) { return [{ num: 1, cr: 8 }]; }354 else if (numPlayers >= 3) { return [{ num: 1, cr: 7 }]; }355 else if (numPlayers >= 2) { return [{ num: 1, cr: 6 }]; }356 else { return [{ num: 1, cr: 4 }]; }357 }358 else359 {360 return this.getMonsterCrs(ratios, numPlayers);361 }362 }363 protected multipleMonsterEleventh(numPlayers: number, singleMonster = false): IMonsterGroup[]364 {365 const ratios: IMonsterRatio[] = [366 { numCharacters: 1, numMonsters: 6, cr: 1 },367 { numCharacters: 1, numMonsters: 3, cr: 2 },368 { numCharacters: 1, numMonsters: 2, cr: 3 },369 { numCharacters: 1, numMonsters: 1, cr: 4 },370 { numCharacters: 2, numMonsters: 1, cr: 5 },371 { numCharacters: 2, numMonsters: 1, cr: 6 },372 { numCharacters: 2, numMonsters: 1, cr: 7 },373 { numCharacters: 3, numMonsters: 1, cr: 8 },374 { numCharacters: 4, numMonsters: 1, cr: 9 },375 { numCharacters: 5, numMonsters: 1, cr: 10 },376 { numCharacters: 6, numMonsters: 1, cr: 11 },377 ]378 if (singleMonster)379 {380 if (numPlayers >= 6) { return [{ num: 1, cr: 11 }]; }381 else if (numPlayers >= 5) { return [{ num: 1, cr: 10 }]; }382 else if (numPlayers >= 4) { return [{ num: 1, cr: 9 }]; }383 else if (numPlayers >= 3) { return [{ num: 1, cr: 8 }]; }384 else if (numPlayers >= 2) { return [{ num: 1, cr: 7 }]; }385 else { return [{ num: 1, cr: 4 }]; }386 }387 else388 {389 return this.getMonsterCrs(ratios, numPlayers);390 }391 }392 protected multipleMonsterTwelf(numPlayers: number, singleMonster = false): IMonsterGroup[]393 {394 const ratios: IMonsterRatio[] = [395 { numCharacters: 1, numMonsters: 8, cr: 1 },396 { numCharacters: 1, numMonsters: 3, cr: 2 },397 { numCharacters: 1, numMonsters: 2, cr: 3 },398 { numCharacters: 1, numMonsters: 1, cr: 4 },399 { numCharacters: 1, numMonsters: 1, cr: 5 },400 { numCharacters: 2, numMonsters: 1, cr: 6 },401 { numCharacters: 2, numMonsters: 1, cr: 7 },402 { numCharacters: 3, numMonsters: 1, cr: 8 },403 { numCharacters: 3, numMonsters: 1, cr: 9 },404 { numCharacters: 4, numMonsters: 1, cr: 10 },405 { numCharacters: 5, numMonsters: 1, cr: 11 },406 { numCharacters: 6, numMonsters: 1, cr: 12 },407 ]408 if (singleMonster)409 {410 if (numPlayers >= 6) { return [{ num: 1, cr: 12 }]; }411 else if (numPlayers >= 5) { return [{ num: 1, cr: 11 }]; }412 else if (numPlayers >= 4) { return [{ num: 1, cr: 10 }]; }413 else if (numPlayers >= 3) { return [{ num: 1, cr: 9 }]; }414 else if (numPlayers >= 2) { return [{ num: 1, cr: 7 }]; }415 else { return [{ num: 1, cr: 5 }]; }416 }417 else418 {419 return this.getMonsterCrs(ratios, numPlayers);420 }421 }422 protected multipleMonsterThirteenth(numPlayers: number, singleMonster = false): IMonsterGroup[]423 {424 const ratios: IMonsterRatio[] = [425 { numCharacters: 1, numMonsters: 9, cr: 1 },426 { numCharacters: 1, numMonsters: 4, cr: 2 },427 { numCharacters: 1, numMonsters: 2, cr: 3 },428 { numCharacters: 1, numMonsters: 2, cr: 4 },429 { numCharacters: 1, numMonsters: 1, cr: 5 },430 { numCharacters: 1, numMonsters: 1, cr: 6 },431 { numCharacters: 2, numMonsters: 1, cr: 7 },432 { numCharacters: 2, numMonsters: 1, cr: 8 },433 { numCharacters: 3, numMonsters: 1, cr: 9 },434 { numCharacters: 3, numMonsters: 1, cr: 10 },435 { numCharacters: 4, numMonsters: 1, cr: 11 },436 { numCharacters: 5, numMonsters: 1, cr: 12 },437 { numCharacters: 6, numMonsters: 1, cr: 13 },438 ]439 if (singleMonster)440 {441 if (numPlayers >= 6) { return [{ num: 1, cr: 13 }]; }442 else if (numPlayers >= 5) { return [{ num: 1, cr: 12 }]; }443 else if (numPlayers >= 4) { return [{ num: 1, cr: 11 }]; }444 else if (numPlayers >= 3) { return [{ num: 1, cr: 10 }]; }445 else if (numPlayers >= 2) { return [{ num: 1, cr: 8 }]; }446 else { return [{ num: 1, cr: 6 }]; }447 }448 else449 {450 return this.getMonsterCrs(ratios, numPlayers);451 }452 }453 protected multipleMonsterFourteenth(numPlayers: number, singleMonster = false): IMonsterGroup[]454 {455 const ratios: IMonsterRatio[] = [456 { numCharacters: 1, numMonsters: 10, cr: 1 },457 { numCharacters: 1, numMonsters: 4, cr: 2 },458 { numCharacters: 1, numMonsters: 3, cr: 3 },459 { numCharacters: 1, numMonsters: 2, cr: 4 },460 { numCharacters: 1, numMonsters: 1, cr: 5 },461 { numCharacters: 1, numMonsters: 1, cr: 6 },462 { numCharacters: 2, numMonsters: 1, cr: 7 },463 { numCharacters: 2, numMonsters: 1, cr: 8 },464 { numCharacters: 3, numMonsters: 1, cr: 9 },465 { numCharacters: 3, numMonsters: 1, cr: 10 },466 { numCharacters: 4, numMonsters: 1, cr: 11 },467 { numCharacters: 4, numMonsters: 1, cr: 12 },468 { numCharacters: 5, numMonsters: 1, cr: 13 },469 { numCharacters: 6, numMonsters: 1, cr: 14 },470 ]471 if (singleMonster)472 {473 if (numPlayers >= 6) { return [{ num: 1, cr: 14 }]; }474 else if (numPlayers >= 5) { return [{ num: 1, cr: 13 }]; }475 else if (numPlayers >= 4) { return [{ num: 1, cr: 14 }]; }476 else if (numPlayers >= 3) { return [{ num: 1, cr: 10 }]; }477 else if (numPlayers >= 2) { return [{ num: 1, cr: 8 }]; }478 else { return [{ num: 1, cr: 6 }]; }479 }480 else481 {482 return this.getMonsterCrs(ratios, numPlayers);483 }484 }485 protected multipleMonsterFifthteenth(numPlayers: number, singleMonster = false): IMonsterGroup[]486 {487 const ratios: IMonsterRatio[] = [488 { numCharacters: 1, numMonsters: 12, cr: 1 },489 { numCharacters: 1, numMonsters: 5, cr: 2 },490 { numCharacters: 1, numMonsters: 3, cr: 3 },491 { numCharacters: 1, numMonsters: 2, cr: 4 },492 { numCharacters: 1, numMonsters: 1, cr: 5 },493 { numCharacters: 1, numMonsters: 1, cr: 6 },494 { numCharacters: 1, numMonsters: 1, cr: 7 },495 { numCharacters: 2, numMonsters: 1, cr: 8 },496 { numCharacters: 2, numMonsters: 1, cr: 9 },497 { numCharacters: 3, numMonsters: 1, cr: 10 },498 { numCharacters: 3, numMonsters: 1, cr: 11 },499 { numCharacters: 4, numMonsters: 1, cr: 12 },500 { numCharacters: 5, numMonsters: 1, cr: 13 },501 { numCharacters: 5, numMonsters: 1, cr: 14 },502 { numCharacters: 6, numMonsters: 1, cr: 15 },503 ]504 if (singleMonster)505 {506 if (numPlayers >= 6) { return [{ num: 1, cr: 15 }]; }507 else if (numPlayers >= 5) { return [{ num: 1, cr: 14 }]; }508 else if (numPlayers >= 4) { return [{ num: 1, cr: 12 }]; }509 else if (numPlayers >= 3) { return [{ num: 1, cr: 11 }]; }510 else if (numPlayers >= 2) { return [{ num: 1, cr: 9 }]; }511 else { return [{ num: 1, cr: 7 }]; }512 }513 else514 {515 return this.getMonsterCrs(ratios, numPlayers);516 }517 }518 protected multipleMonsterSixteenth(numPlayers: number, singleMonster = false): IMonsterGroup[]519 {520 const ratios: IMonsterRatio[] = [521 { numCharacters: 1, numMonsters: 5, cr: 2 },522 { numCharacters: 1, numMonsters: 3, cr: 3 },523 { numCharacters: 1, numMonsters: 2, cr: 4 },524 { numCharacters: 1, numMonsters: 1, cr: 5 },525 { numCharacters: 1, numMonsters: 1, cr: 6 },526 { numCharacters: 1, numMonsters: 1, cr: 7 },527 { numCharacters: 2, numMonsters: 1, cr: 8 },528 { numCharacters: 2, numMonsters: 1, cr: 9 },529 { numCharacters: 2, numMonsters: 1, cr: 10 },530 { numCharacters: 3, numMonsters: 1, cr: 11 },531 { numCharacters: 4, numMonsters: 1, cr: 12 },532 { numCharacters: 4, numMonsters: 1, cr: 13 },533 { numCharacters: 5, numMonsters: 1, cr: 14 },534 { numCharacters: 5, numMonsters: 1, cr: 15 },535 { numCharacters: 6, numMonsters: 1, cr: 16 },536 ]537 if (singleMonster)538 {539 if (numPlayers >= 6) { return [{ num: 1, cr: 16 }]; }540 else if (numPlayers >= 5) { return [{ num: 1, cr: 15 }]; }541 else if (numPlayers >= 4) { return [{ num: 1, cr: 13 }]; }542 else if (numPlayers >= 3) { return [{ num: 1, cr: 11 }]; }543 else if (numPlayers >= 2) { return [{ num: 1, cr: 10 }]; }544 else { return [{ num: 1, cr: 7 }]; }545 }546 else547 {548 return this.getMonsterCrs(ratios, numPlayers);549 }550 }551 protected multipleMonsterSeventeenth(numPlayers: number, singleMonster = false): IMonsterGroup[]552 {553 const ratios: IMonsterRatio[] = [554 { numCharacters: 1, numMonsters: 7, cr: 2 },555 { numCharacters: 1, numMonsters: 4, cr: 3 },556 { numCharacters: 1, numMonsters: 3, cr: 4 },557 { numCharacters: 1, numMonsters: 2, cr: 5 },558 { numCharacters: 1, numMonsters: 1, cr: 6 },559 { numCharacters: 1, numMonsters: 1, cr: 7 },560 { numCharacters: 1, numMonsters: 1, cr: 8 },561 { numCharacters: 2, numMonsters: 1, cr: 9 },562 { numCharacters: 2, numMonsters: 1, cr: 10 },563 { numCharacters: 2, numMonsters: 1, cr: 11 },564 { numCharacters: 3, numMonsters: 1, cr: 12 },565 { numCharacters: 3, numMonsters: 1, cr: 13 },566 { numCharacters: 4, numMonsters: 1, cr: 14 },567 { numCharacters: 4, numMonsters: 1, cr: 15 },568 { numCharacters: 5, numMonsters: 1, cr: 16 },569 { numCharacters: 6, numMonsters: 1, cr: 17 },570 ]571 if (singleMonster)572 {573 if (numPlayers >= 6) { return [{ num: 1, cr: 17 }]; }574 else if (numPlayers >= 5) { return [{ num: 1, cr: 16 }]; }575 else if (numPlayers >= 4) { return [{ num: 1, cr: 15 }]; }576 else if (numPlayers >= 3) { return [{ num: 1, cr: 13 }]; }577 else if (numPlayers >= 2) { return [{ num: 1, cr: 11 }]; }578 else { return [{ num: 1, cr: 8 }]; }579 }580 else581 {582 return this.getMonsterCrs(ratios, numPlayers);583 }584 }585 protected multipleMonsterEightteenth(numPlayers: number, singleMonster = false): IMonsterGroup[]586 {587 const ratios: IMonsterRatio[] = [588 { numCharacters: 1, numMonsters: 7, cr: 2 },589 { numCharacters: 1, numMonsters: 5, cr: 3 },590 { numCharacters: 1, numMonsters: 3, cr: 4 },591 { numCharacters: 1, numMonsters: 2, cr: 5 },592 { numCharacters: 1, numMonsters: 1, cr: 6 },593 { numCharacters: 1, numMonsters: 1, cr: 7 },594 { numCharacters: 1, numMonsters: 1, cr: 8 },595 { numCharacters: 2, numMonsters: 1, cr: 9 },596 { numCharacters: 2, numMonsters: 1, cr: 10 },597 { numCharacters: 2, numMonsters: 1, cr: 11 },598 { numCharacters: 3, numMonsters: 1, cr: 12 },599 { numCharacters: 3, numMonsters: 1, cr: 13 },600 { numCharacters: 4, numMonsters: 1, cr: 14 },601 { numCharacters: 4, numMonsters: 1, cr: 15 },602 { numCharacters: 5, numMonsters: 1, cr: 16 },603 { numCharacters: 6, numMonsters: 1, cr: 17 },604 { numCharacters: 6, numMonsters: 1, cr: 18 },605 ]606 if (singleMonster)607 {608 if (numPlayers >= 6) { return [{ num: 1, cr: 18 }]; }609 else if (numPlayers >= 5) { return [{ num: 1, cr: 16 }]; }610 else if (numPlayers >= 4) { return [{ num: 1, cr: 15 }]; }611 else if (numPlayers >= 3) { return [{ num: 1, cr: 13 }]; }612 else if (numPlayers >= 2) { return [{ num: 1, cr: 11 }]; }613 else { return [{ num: 1, cr: 8 }]; }614 }615 else616 {617 return this.getMonsterCrs(ratios, numPlayers);618 }619 }620 protected multipleMonsterNineteenth(numPlayers: number, singleMonster = false): IMonsterGroup[]621 {622 const ratios: IMonsterRatio[] = [623 { numCharacters: 1, numMonsters: 8, cr: 2 },624 { numCharacters: 1, numMonsters: 5, cr: 3 },625 { numCharacters: 1, numMonsters: 3, cr: 4 },626 { numCharacters: 1, numMonsters: 2, cr: 5 },627 { numCharacters: 1, numMonsters: 2, cr: 6 },628 { numCharacters: 1, numMonsters: 1, cr: 7 },629 { numCharacters: 1, numMonsters: 1, cr: 8 },630 { numCharacters: 1, numMonsters: 1, cr: 9 },631 { numCharacters: 2, numMonsters: 1, cr: 10 },632 { numCharacters: 2, numMonsters: 1, cr: 11 },633 { numCharacters: 2, numMonsters: 1, cr: 12 },634 { numCharacters: 3, numMonsters: 1, cr: 13 },635 { numCharacters: 3, numMonsters: 1, cr: 14 },636 { numCharacters: 4, numMonsters: 1, cr: 15 },637 { numCharacters: 4, numMonsters: 1, cr: 16 },638 { numCharacters: 5, numMonsters: 1, cr: 17 },639 { numCharacters: 6, numMonsters: 1, cr: 18 },640 { numCharacters: 6, numMonsters: 1, cr: 19 },641 ]642 if (singleMonster)643 {644 if (numPlayers >= 6) { return [{ num: 1, cr: 19 }]; }645 else if (numPlayers >= 5) { return [{ num: 1, cr: 17 }]; }646 else if (numPlayers >= 4) { return [{ num: 1, cr: 16 }]; }647 else if (numPlayers >= 3) { return [{ num: 1, cr: 14 }]; }648 else if (numPlayers >= 2) { return [{ num: 1, cr: 12 }]; }649 else { return [{ num: 1, cr: 9 }]; }650 }651 else652 {653 return this.getMonsterCrs(ratios, numPlayers);654 }655 }656 protected multipleMonsterTwentieth(numPlayers: number, singleMonster = false): IMonsterGroup[]657 {658 const ratios: IMonsterRatio[] = [659 { numCharacters: 1, numMonsters: 9, cr: 2 },660 { numCharacters: 1, numMonsters: 6, cr: 3 },661 { numCharacters: 1, numMonsters: 4, cr: 4 },662 { numCharacters: 1, numMonsters: 2, cr: 5 },663 { numCharacters: 1, numMonsters: 2, cr: 6 },664 { numCharacters: 1, numMonsters: 1, cr: 7 },665 { numCharacters: 1, numMonsters: 1, cr: 8 },666 { numCharacters: 1, numMonsters: 1, cr: 9 },667 { numCharacters: 1, numMonsters: 1, cr: 10 },668 { numCharacters: 2, numMonsters: 1, cr: 11 },669 { numCharacters: 2, numMonsters: 1, cr: 12 },670 { numCharacters: 2, numMonsters: 1, cr: 13 },671 { numCharacters: 3, numMonsters: 1, cr: 14 },672 { numCharacters: 3, numMonsters: 1, cr: 15 },673 { numCharacters: 4, numMonsters: 1, cr: 16 },674 { numCharacters: 4, numMonsters: 1, cr: 17 },675 { numCharacters: 5, numMonsters: 1, cr: 18 },676 { numCharacters: 5, numMonsters: 1, cr: 19 },677 { numCharacters: 6, numMonsters: 1, cr: 20 },678 ]679 if (singleMonster)680 {681 if (numPlayers >= 6) { return [{ num: 1, cr: 20 }]; }682 else if (numPlayers >= 5) { return [{ num: 1, cr: 19 }]; }683 else if (numPlayers >= 4) { return [{ num: 1, cr: 17 }]; }684 else if (numPlayers >= 3) { return [{ num: 1, cr: 15 }]; }685 else if (numPlayers >= 2) { return [{ num: 1, cr: 13 }]; }686 else { return [{ num: 1, cr: 10 }]; }687 }688 else689 {690 return this.getMonsterCrs(ratios, numPlayers);691 }692 }693 protected getMonsterCrs(ratios: IMonsterRatio[], numPlayers: number): IMonsterGroup[]694 {695 const monsterCrs: IMonsterGroup[] = []696 let playersRemaining = numPlayers;697 while (playersRemaining > 0)698 {699 const index = Math.floor(Math.random() * ratios.length);700 const ratio = ratios[index];701 if (ratio.numCharacters <= playersRemaining)702 {703 playersRemaining -= ratio.numCharacters704 monsterCrs.push({ num: ratio.numMonsters, cr: ratio.cr })705 }706 }707 return monsterCrs;708 }...
moviedescext.js
Source:moviedescext.js
1let fs = require("fs");2let data = fs.readFileSync(0, "utf-8");3let idx = 0;4data = data.split("\n");5function readLine() {6 idx++;7 return data[idx - 1];8}9// -------- Do NOT edit anything above this line ----------10// Define your class here11// your class name should be 'Movie' and method names as 'certify' and 'run'12class Movie {13 cert;14 constructor(lengthInMinutes, numCharacters, language) {15 this.lengthInMinutes = lengthInMinutes;16 this.numCharacters = numCharacters;17 this.language = language;18 }19 run() {20 this.cert = this.certify();21 if (this.cert) {22 return `This is a ${this.language} movie with ${this.numCharacters} characters, is ${this.lengthInMinutes} minutes long and is certified.`;23 } else {24 return `This is a ${this.language} movie with ${this.numCharacters} characters, is ${this.lengthInMinutes} minutes long and is not certified.`;25 }26 }27 certify() {28 if (this.numCharacters >= 2 && this.lengthInMinutes <= 240) {29 return true;30 } else {31 return false;32 }33 }34}35// DO NOT CHANGE ANYTHING BELOW THIS LINE36let language = readLine();37let numCharacters = parseInt(readLine());38let lengthInMinutes = parseInt(readLine());39let movie = new Movie(lengthInMinutes, numCharacters, language);...
moviedesc.js
Source:moviedesc.js
1let fs = require("fs");2let data = fs.readFileSync(0, "utf-8");3let idx = 0;4data = data.split("\n");5function readLine() {6 idx++;7 return data[idx - 1];8}9// -------- Do NOT edit anything above this line ----------10// Define your class here11// your class name should be 'Movie' and method name as 'run'12class Movie {13 constructor(lengthInMinutes, numCharacters, language) {14 this.lengthInMinutes = lengthInMinutes;15 this.numCharacters = numCharacters;16 this.language = language;17 }18 run() {19 return `This is a ${this.language} movie with ${this.numCharacters} characters and is ${this.lengthInMinutes} minutes`;20 }21}22// DO NOT CHANGE ANYTHING BELOW THIS LINE23let language = readLine();24let numCharacters = readLine();25let lengthInMinutes = readLine();26let movie = new Movie(lengthInMinutes, numCharacters, language);...
Using AI Code Generation
1const fc = require('fast-check');2const { numCharacters } = require('@fast-check/monorepo');3fc.assert(4 fc.property(fc.string(), fc.nat(10), (s, n) => {5 return numCharacters(s, n) <= n;6 })7);
Using AI Code Generation
1const fc = require('fast-check');2const { numCharacters } = require('fast-check-monorepo');3const { numCharacters: numCharacters2 } = require('fast-check-monorepo');4const arb = numCharacters();5fc.assert(6 fc.property(arb, (s) => {7 return s.length === 3;8 })9);10fc.assert(11 fc.property(arb, (s) => {12 return s.length === 3;13 })14);
Using AI Code Generation
1const { numCharacters } = require('@dubzzz/fast-check');2const fc = require('fast-check');3const str = fc.string(numCharacters(1, 10));4fc.assert(fc.property(str, (s) => s.length >= 1 && s.length <= 10));5const { numCharacters } = require('@dubzzz/fast-check');6const fc = require('fast-check');7const str = fc.string(numCharacters(1, 10));8fc.assert(fc.property(str, (s) => s.length >= 1 && s.length <= 10));
Using AI Code Generation
1const { numCharacters } = require('fast-check-monorepo');2console.log(numCharacters('Hello World'));3const { numCharacters } = require('fast-check-monorepo');4console.log(numCharacters('Hello World'));5const { numCharacters } = require('fast-check-monorepo');6console.log(numCharacters('Hello World'));7const { numCharacters } = require('fast-check-monorepo');8console.log(numCharacters('Hello World'));9const { numCharacters } = require('fast-check-monorepo');10console.log(numCharacters('Hello World'));11const { numCharacters } = require('fast-check-monorepo');12console.log(numCharacters('Hello World'));13const { numCharacters } = require('fast-check-monorepo');14console.log(numCharacters
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!