// import "./tile.js"; class Hand { constructor(option = {}) { this.tiles = option.tiles || []; this.draw = null; this.sort(); } sort() { this.tiles.sort((a, b) => { if (a.lessThan(b)) return -1; if (b.lessThan(a)) return 1; return 0; }); } flatten() { if (this.draw) { this.tiles.push(this.draw); this.draw = null; } } } class Wall { constructor() { this.tiles = Tile.generateAll(); for (let i = this.tiles.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [this.tiles[i], this.tiles[j]] = [this.tiles[j], this.tiles[i]]; } } draw() { return this.tiles.pop(); } drawHand() { let tiles = []; for (let i = 0; i < 13; i++) { tiles.push(this.draw()); } return new Hand({ tiles }); } } class Discard { constructor() { this.tiles = []; this.hiddenTiles = []; // for stollen tiles } } class Game { constructor() { this.wall = new Wall(); this.hands = Array.from({ length: 4 }, () => this.wall.drawHand()); this.discards = Array.from({ length: 4 }, () => new Discard()); this.turn = 0; } }