Skip to content

Commit

Permalink
fix starting player bug
Browse files Browse the repository at this point in the history
can't shallow compare for 3 of clubs (or any card), also ts enum starts at 0 not 1
  • Loading branch information
tmwilliamlin168 committed Feb 16, 2021
1 parent 54e1e79 commit 6b634ca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions back/src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class Game {
async start() {
const cards = [];
for (let i = 1; i <= 13; ++i)
for (let j = 1; j <= 4; ++j)
for (let j = 0; j < 4; ++j)
cards.push({rank: i, suit: j});
for (let i = 0; i < 52; ++i) {
const j = Math.floor(Math.random() * (i+1));
Expand All @@ -66,7 +66,9 @@ export default class Game {
this.players.push(new Player(this, this.room.clients[i]));
this.players[i].cards = cards.slice(i * handSize, (i + 1) * handSize);
}
const startingPlayer = (this.players.find((p: Player) => p.cards.includes({rank: 3, suit: Suit.Clubs})) || this.players[0]);
const startingPlayer = this.players.find((p: Player) => p.cards.some(
(card: Card) => card.rank === 3 && card.suit === Suit.Clubs
)) || this.players[0];
if (this.room.clients.length === 3)
startingPlayer.cards.push(cards[51]);
this.playerTurn = this.players.indexOf(startingPlayer);
Expand Down

0 comments on commit 6b634ca

Please sign in to comment.