Skip to content

Commit

Permalink
bug fix change to shallow matching
Browse files Browse the repository at this point in the history
  • Loading branch information
tmwilliamlin168 committed Feb 16, 2021
1 parent 9814108 commit 134e4c1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions back/src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default class Game {
}, 5000);
}
broadcastGameState() {
console.log('broadcast');
this.players.forEach((p: Player) => p.sendGameState());
}
async round() {
Expand Down Expand Up @@ -132,14 +133,14 @@ export default class Game {
}
// Play
console.log('got cards', cards);
if (cards && cards.isArray() && cards.every((card: Card) => p.cards.includes(card)) && canPlay(this.lastPlayed, cards)) {
if (cards && Array.isArray(cards) && cards.every((a: Card) => a && p.cards.some((b: Card) => !cmpCard(a, b))) && canPlay(this.lastPlayed, cards)) {
// Cards have to be ascending
let ok = true;
for (let i = 0; i + 1 < cards.length; ++i)
ok = ok && cmpCard(cards[i], cards[i + 1]) < 0;
if (ok) {
// Remove cards
p.cards = p.cards.filter((card: Card) => cards.indexOf(card) < 0);
p.cards = p.cards.filter((a: Card) => !cards.some((b: Card) => !cmpCard(a, b)));
// Check if won
if (!p.cards.length)
p.rank = ++this.playersFinished;
Expand Down

0 comments on commit 134e4c1

Please sign in to comment.