Skip to content

Commit

Permalink
avoid almost infinite loop with synergy wheel special rule after leve…
Browse files Browse the repository at this point in the history
…l 20 (#1648)
  • Loading branch information
sylvainpolletvillard authored Apr 12, 2024
1 parent 865bba3 commit 1466b6f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/core/matter/mini-game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export class MiniGame {

if (specialGameRule === SpecialGameRule.SYNERGY_WHEEL) {
itemsSet = SynergyStones
maxCopiesPerItem = 4
}

if (specialGameRule === SpecialGameRule.KECLEONS_SHOP) {
Expand All @@ -362,11 +363,14 @@ export class MiniGame {
}

for (let j = 0; j < nbItemsToPick; j++) {
let item, count
let item,
count,
tries = 0
do {
item = pickRandomIn(itemsSet)
count = items.filter((i) => i === item).length
} while (count >= maxCopiesPerItem)
tries++
} while (count >= maxCopiesPerItem && tries < 10)
items.push(item)
}
return items
Expand Down

0 comments on commit 1466b6f

Please sign in to comment.