Skip to content

Commit

Permalink
Improving buy risk logic
Browse files Browse the repository at this point in the history
If you have 5 trumps down warn the player
  • Loading branch information
daithihearn committed Jul 9, 2023
1 parent f71d5cf commit de426c4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/utils/GameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,32 @@ export const riskOfMistakeBuyingCards = <T extends Card>(
selectedCards: T[],
myCards: T[],
) => {
// If you have selected 5 trumps then return false
if (areAllTrumpCards(selectedCards, suit)) {
return false
}

const deletingCards = removeAllFromHand(selectedCards, myCards)

for (const element of deletingCards) {
return containsATrumpCard(deletingCards, suit)
}

export const areAllTrumpCards = <T extends Card>(cards: T[], suit: Suit) => {
for (const element of cards) {
if (
element.name !== "JOKER" &&
element.name !== "ACE_HEARTS" &&
element.suit !== suit
) {
return false
}
}

return true
}

export const containsATrumpCard = <T extends Card>(cards: T[], suit: Suit) => {
for (const element of cards) {
if (
element.name === "JOKER" ||
element.name === "ACE_HEARTS" ||
Expand Down

0 comments on commit de426c4

Please sign in to comment.