Last active
October 3, 2023 17:46
-
-
Save jtrussell/b851907ceba6780a40e51b73f54b7fe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player extends GameObject { | |
// [... lots o' other stuff ...] | |
shuffleDeck() { | |
this.game.emitEvent( | |
'onDeckShuffled', | |
{ player: this } | |
) | |
this.deck = _.shuffle(this.deck) | |
if ( | |
this.isTopCardOfDeckVisible() && | |
this.deck.length > 0 | |
) { | |
this.deck[0].facedown = false | |
this.deck.slice(1).forEach((card) => { | |
card.facedown = true | |
}) | |
this.addTopCardOfDeckVisibleMessage() | |
} | |
} | |
// [... more other stuff ...] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player extends GameObject { | |
// [... lots o' other stuff ...] | |
takeMulligan() { | |
let size = this.hand.length | |
for (let card of this.hand) { | |
this.moveCard(card, 'deck') | |
} | |
this.shuffleDeck() | |
this.drawCardsToHand(size - 1) | |
this.takenMulligan = true | |
} | |
// [... more other stuff ...] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function random(min, max) { | |
if (max == null) { | |
max = min; | |
min = 0; | |
} | |
return min + Math.floor(Math.random() * (max - min + 1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sample(obj, n, guard) { | |
if (n == null || guard) { | |
if (!isArrayLike(obj)) obj = values(obj) | |
return obj[random(obj.length - 1)] | |
} | |
var sample = toArray(obj) | |
var length = getLength(sample) | |
n = Math.max(Math.min(n, length), 0) | |
var last = length - 1 | |
for (var index = 0; index < n; index++) { | |
var rand = random(index, last) | |
var temp = sample[index] | |
sample[index] = sample[rand] | |
sample[rand] = temp | |
} | |
return sample.slice(0, n) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shuffle(obj) { | |
return sample(obj, Infinity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment