35 lines
623 B
JavaScript
35 lines
623 B
JavaScript
import { strategies } from './strategies';
|
|
|
|
class Strategies {
|
|
constructor() {
|
|
this.reset();
|
|
this.shuffle();
|
|
}
|
|
|
|
reset() {
|
|
this.cards = strategies;
|
|
}
|
|
|
|
shuffle() {
|
|
const { cards } = this;
|
|
let f = cards.length, y;
|
|
|
|
while (f) {
|
|
y = Math.floor(Math.random() * f--);
|
|
[cards[f], cards[y]] = [cards[y], cards[f]];
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
draw() {
|
|
const drawn = this.cards.pop();
|
|
if (this.cards.length === 0) this.reset();
|
|
return drawn.toLowerCase();
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
Strategies,
|
|
}
|