Skip to content

Commit

Permalink
fix bug where deck runs out and gets stuck in inifinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonahss committed Aug 12, 2023
1 parent b690cfc commit d0602c2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/tarot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ async function main() {
let drawCard = async () => {
let directory = path.resolve('/', 'home', 'pi', 'Pictures', 'wyldcard', 'tarot-reliberate')
let imageNames = await fs.readdir(directory)

// soft reset
if (alreadyDrawn.length >= imageNames.length) {
alreadyDrawn = alreadyDrawn.slice(alreadyDrawn.length/2)
alreadyDrawn.push('back.png')
}

let randomImageName = _.sample(imageNames)
console.log('random image name', randomImageName, !alreadyDrawn.includes(randomImageName))
while (alreadyDrawn.includes(randomImageName)) {
Expand Down

0 comments on commit d0602c2

Please sign in to comment.