Skip to content
Snippets Groups Projects
Commit f7c30e21 authored by giovanni.novati@studenti.unimi.it's avatar giovanni.novati@studenti.unimi.it
Browse files

REFACTORING: migliorato metodo chooseCard in TryHigherRankStrategy

parent 319ba6d2
Branches
Tags
No related merge requests found
......@@ -13,11 +13,20 @@ public class TryHigherRankStrategy implements Strategy {
@Override
public @NotNull Card chooseCard(@NotNull Player me, @NotNull Player other, @NotNull Suit briscola) {
for (Card card : me) {
if (card.getSuit().equals(other.playedCard().getSuit()) && card.getRank().points() > other.playedCard().getRank().points())
Card otherCard = other.playedCard();
for (Card card : me)
if (isSameSuit(card, otherCard) && isHigherRank(card, otherCard))
return card;
}
return next.chooseCard(me, other, briscola);
}
private boolean isHigherRank(Card mine, Card other) {
return mine.getRank().points() > other.getRank().points();
}
private boolean isSameSuit(@NotNull Card mine, @NotNull Card other) {
return mine.getSuit().equals(other.getSuit());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment