From 8238da3377cde24ddf3c08e1f1e060e5ca8389e6 Mon Sep 17 00:00:00 2001 From: b0n541 Date: Sun, 22 Oct 2023 08:13:12 +0200 Subject: [PATCH 1/4] #167 Minor refactorings and formatting --- .../main/java/org/jskat/util/CardDeck.java | 88 +++++---------- .../org/jskat/util/rule/SuitGrandRule.java | 3 +- .../java/org/jskat/util/rule/SuitRule.java | 106 ++++++++---------- .../org/jskat/util/rule/SuitRuleTest.java | 14 +++ .../gui/swing/table/GameInformationPanel.java | 2 +- .../jskat/gui/swing/table/SkatTablePanel.java | 6 +- 6 files changed, 96 insertions(+), 123 deletions(-) diff --git a/jskat-base/src/main/java/org/jskat/util/CardDeck.java b/jskat-base/src/main/java/org/jskat/util/CardDeck.java index a56d21b5f..51775b049 100644 --- a/jskat-base/src/main/java/org/jskat/util/CardDeck.java +++ b/jskat-base/src/main/java/org/jskat/util/CardDeck.java @@ -13,51 +13,21 @@ public class CardDeck extends CardList { public final static Map> RANK_CARDS; static { - Map> suitCards = new HashMap<>(); - suitCards.put(Suit.CLUBS, - Collections.unmodifiableList( - Arrays.asList(Card.CJ, Card.CA, Card.CT, Card.CK, - Card.CQ, Card.C9, Card.C8, Card.C7))); - suitCards.put(Suit.SPADES, - Collections.unmodifiableList( - Arrays.asList(Card.SJ, Card.SA, Card.ST, Card.SK, - Card.SQ, Card.S9, Card.S8, Card.S7))); - suitCards.put(Suit.HEARTS, - Collections.unmodifiableList( - Arrays.asList(Card.HJ, Card.HA, Card.HT, Card.HK, - Card.HQ, Card.H9, Card.H8, Card.H7))); - suitCards.put(Suit.DIAMONDS, - Collections.unmodifiableList( - Arrays.asList(Card.DJ, Card.DA, Card.DT, Card.DK, - Card.DQ, Card.D9, Card.D8, Card.D7))); - SUIT_CARDS = Collections.unmodifiableMap(suitCards); - - Map> rankCards = new HashMap<>(); - rankCards.put(Rank.JACK, - Collections.unmodifiableList( - Arrays.asList(Card.CJ, Card.SJ, Card.HJ, Card.DJ))); - rankCards.put(Rank.ACE, - Collections.unmodifiableList( - Arrays.asList(Card.CA, Card.SA, Card.HA, Card.DA))); - rankCards.put(Rank.TEN, - Collections.unmodifiableList( - Arrays.asList(Card.CT, Card.ST, Card.HT, Card.DT))); - rankCards.put(Rank.KING, - Collections.unmodifiableList( - Arrays.asList(Card.CK, Card.SK, Card.HK, Card.DK))); - rankCards.put(Rank.QUEEN, - Collections.unmodifiableList( - Arrays.asList(Card.CQ, Card.SQ, Card.HQ, Card.DQ))); - rankCards.put(Rank.NINE, - Collections.unmodifiableList( - Arrays.asList(Card.C9, Card.S9, Card.H9, Card.D9))); - rankCards.put(Rank.EIGHT, - Collections.unmodifiableList( - Arrays.asList(Card.C8, Card.S8, Card.H8, Card.D8))); - rankCards.put(Rank.SEVEN, - Collections.unmodifiableList( - Arrays.asList(Card.C7, Card.S7, Card.H7, Card.D7))); - RANK_CARDS = Collections.unmodifiableMap(rankCards); + SUIT_CARDS = Map.of( + Suit.CLUBS, List.of(Card.CJ, Card.CA, Card.CT, Card.CK, Card.CQ, Card.C9, Card.C8, Card.C7), + Suit.SPADES, List.of(Card.SJ, Card.SA, Card.ST, Card.SK, Card.SQ, Card.S9, Card.S8, Card.S7), + Suit.HEARTS, List.of(Card.HJ, Card.HA, Card.HT, Card.HK, Card.HQ, Card.H9, Card.H8, Card.H7), + Suit.DIAMONDS, List.of(Card.DJ, Card.DA, Card.DT, Card.DK, Card.DQ, Card.D9, Card.D8, Card.D7)); + + RANK_CARDS = Map.of( + Rank.JACK, List.of(Card.CJ, Card.SJ, Card.HJ, Card.DJ), + Rank.ACE, List.of(Card.CA, Card.SA, Card.HA, Card.DA), + Rank.TEN, List.of(Card.CT, Card.ST, Card.HT, Card.DT), + Rank.KING, List.of(Card.CK, Card.SK, Card.HK, Card.DK), + Rank.QUEEN, List.of(Card.CQ, Card.SQ, Card.HQ, Card.DQ), + Rank.NINE, List.of(Card.C9, Card.S9, Card.H9, Card.D9), + Rank.EIGHT, List.of(Card.C8, Card.S8, Card.H8, Card.D8), + Rank.SEVEN, List.of(Card.C7, Card.S7, Card.H7, Card.D7)); } /** @@ -68,8 +38,7 @@ public CardDeck() { super(); // Adds a card for every suit and value - for (Card card : Card.values()) { - + for (final Card card : Card.values()) { add(card); } } @@ -82,8 +51,10 @@ public CardDeck() { * @param rearHandCards Cards of rear hand * @param skatCards Cards of skat */ - public CardDeck(List foreHandCards, List middleHandCards, - List rearHandCards, List skatCards) { + public CardDeck(final List foreHandCards, + final List middleHandCards, + final List rearHandCards, + final List skatCards) { addAll(foreHandCards.subList(0, 3)); addAll(middleHandCards.subList(0, 3)); addAll(rearHandCards.subList(0, 3)); @@ -104,8 +75,10 @@ public CardDeck(List foreHandCards, List middleHandCards, * @param rearHandCards Cards of rear hand * @param skatCards Cards of skat */ - public CardDeck(String foreHandCards, String middleHandCards, - String rearHandCards, String skatCards) { + public CardDeck(final String foreHandCards, + final String middleHandCards, + final String rearHandCards, + final String skatCards) { this(getCardsFromString(foreHandCards), getCardsFromString(middleHandCards), getCardsFromString(rearHandCards), @@ -124,11 +97,10 @@ public CardDeck(final String cards) { private static List getCardsFromString(final String cards) { - List result = new ArrayList(); - StringTokenizer token = new StringTokenizer(cards); + final List result = new ArrayList<>(); + final StringTokenizer token = new StringTokenizer(cards); while (token.hasMoreTokens()) { - result.add(Card.getCardFromString(token.nextToken())); } @@ -152,12 +124,10 @@ public CardDeck(final CardList cards) { public boolean add(final Card card) { if (size() == MAX_CARDS) { - throw new IllegalStateException("Card deck is already filled with " - + MAX_CARDS + " cards."); + throw new IllegalStateException("Card deck is already filled with " + MAX_CARDS + " cards."); } if (contains(card)) { - throw new IllegalArgumentException("Card " + card - + " is already contained in card deck."); + throw new IllegalArgumentException("Card " + card + " is already contained in card deck."); } return super.add(card); @@ -170,7 +140,7 @@ public boolean add(final Card card) { */ public static EnumSet getAllCards() { - EnumSet allCards = EnumSet.allOf(Card.class); + final EnumSet allCards = EnumSet.allOf(Card.class); return allCards; } diff --git a/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java b/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java index f068b626a..b2fd00832 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java @@ -124,8 +124,7 @@ public int getMultiplier(final SkatGameData gameData) { } private CardList getDeclarerCards(final SkatGameData gameData) { - final CardList declarerCards = new CardList(gameData.getDealtCards().get( - gameData.getDeclarer())); + final CardList declarerCards = new CardList(gameData.getDealtCards().get(gameData.getDeclarer())); declarerCards.addAll(gameData.getDealtSkat()); return declarerCards; } diff --git a/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java b/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java index 0897bb5ea..1a16fd3e6 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java @@ -1,66 +1,58 @@ - package org.jskat.util.rule; -import org.jskat.util.Card; -import org.jskat.util.CardList; -import org.jskat.util.GameType; -import org.jskat.util.Rank; -import org.jskat.util.Suit; +import org.jskat.util.*; /** * Implementation of skat rules for Suit games */ public class SuitRule extends SuitGrandRule { - /** - * {@inheritDoc} - */ - @Override - public int getMultiplier(CardList cards, GameType gameType) { - if (gameType == GameType.GRAND || gameType == GameType.RAMSCH - || gameType == GameType.NULL) { - throw new IllegalArgumentException("Wrong ruleset - " + gameType); - } - int result = 1; - if (cards.contains(Card.CJ)) { - result++; - if (cards.contains(Card.SJ)) { - result++; - if (cards.contains(Card.HJ)) { - result++; - if (cards.contains(Card.DJ)) { - result++; - for (Rank r : Rank.getRankList()) { - if (cards.contains(Card.getCard( - Suit.valueOf(gameType.toString()), r))) { - result++; - } else { - break; - } - } - } - } - } - } else { - result++; - if (!cards.contains(Card.SJ)) { - result++; - if (!cards.contains(Card.HJ)) { - result++; - if (!cards.contains(Card.DJ)) { - result++; - for (Rank r : Rank.getRankList()) { - if (!cards.contains(Card.getCard( - Suit.valueOf(gameType.toString()), r))) { - result++; - } else { - break; - } - } - } - } - } - } - return result; - } + /** + * {@inheritDoc} + */ + @Override + public int getMultiplier(final CardList cards, final GameType gameType) { + if (gameType == GameType.GRAND || gameType == GameType.RAMSCH || gameType == GameType.NULL) { + throw new IllegalArgumentException("Wrong ruleset - " + gameType); + } + int result = 1; + if (cards.contains(Card.CJ)) { + result++; + if (cards.contains(Card.SJ)) { + result++; + if (cards.contains(Card.HJ)) { + result++; + if (cards.contains(Card.DJ)) { + result++; + for (final Rank r : Rank.getRankList()) { + if (cards.contains(Card.getCard(Suit.valueOf(gameType.toString()), r))) { + result++; + } else { + break; + } + } + } + } + } + } else { + result++; + if (!cards.contains(Card.SJ)) { + result++; + if (!cards.contains(Card.HJ)) { + result++; + if (!cards.contains(Card.DJ)) { + result++; + for (final Rank r : Rank.getRankList()) { + if (!cards.contains(Card.getCard(Suit.valueOf(gameType.toString()), r))) { + result++; + } else { + break; + } + } + } + } + } + } + return result; + } } diff --git a/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java b/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java index 1699be594..a7a207108 100644 --- a/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java +++ b/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java @@ -350,4 +350,18 @@ public void testOverbidWithSchneider() { assertTrue(data.getResult().isWon()); assertThat(data.getResult().getGameValue()).isEqualTo(27); } + + @Test + public void testGetMultiplier() { + final var rule = new SuitRule(); + + assertThat(rule.getMultiplier( + CardList.of(Card.SJ, Card.HJ, Card.DJ, Card.DT, Card.D8, Card.SQ, Card.S9, Card.HA, Card.HK, Card.HQ), + GameType.DIAMONDS)) + .isEqualTo(2); + assertThat(rule.getMultiplier( + CardList.of(Card.HJ, Card.DJ, Card.DT, Card.D8, Card.SQ, Card.S9, Card.HA, Card.HK, Card.HQ, Card.H7), + GameType.DIAMONDS)) + .isEqualTo(3); + } } diff --git a/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java b/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java index 49cd6c915..75b02e793 100644 --- a/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java +++ b/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java @@ -112,7 +112,7 @@ private void resetGameData() { gameWon = false; declarerPoints = 0; opponentPoints = 0; - ramschLoosers = new HashSet(); + ramschLoosers = new HashSet<>(); } private void refreshText() { diff --git a/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/SkatTablePanel.java b/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/SkatTablePanel.java index a77ddf16b..b15fa004a 100644 --- a/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/SkatTablePanel.java +++ b/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/SkatTablePanel.java @@ -204,12 +204,10 @@ private void createGameContextPanel() { new StartContextPanel((StartSkatSeriesAction) getActionMap() .get(JSkatAction.START_LOCAL_SERIES))); - biddingPanel = new BiddingContextPanel(getActionMap(), - bitmaps, userPanel); + biddingPanel = new BiddingContextPanel(getActionMap(), bitmaps, userPanel); addContextPanel(ContextPanelType.BIDDING, biddingPanel); - declaringPanel = new DeclaringContextPanel(getActionMap(), - userPanel); + declaringPanel = new DeclaringContextPanel(getActionMap(), userPanel); addContextPanel(ContextPanelType.DECLARING, declaringPanel); schieberamschPanel = new SchieberamschContextPanel(getActionMap(), From 71fed8a4d9dc72b2f045ba3feb88b607416e5b71 Mon Sep 17 00:00:00 2001 From: b0n541 Date: Sun, 22 Oct 2023 08:39:45 +0200 Subject: [PATCH 2/4] #167 Shuffle cards every time --- jskat-base/src/main/java/org/jskat/control/SkatGame.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jskat-base/src/main/java/org/jskat/control/SkatGame.java b/jskat-base/src/main/java/org/jskat/control/SkatGame.java index 1ec178678..81c6d05ee 100644 --- a/jskat-base/src/main/java/org/jskat/control/SkatGame.java +++ b/jskat-base/src/main/java/org/jskat/control/SkatGame.java @@ -265,12 +265,12 @@ public void dealCards() { // Skat game has no cards, yet deck = new CardDeck(); - log.debug("shuffling..."); - deck.shuffle(); - log.debug(deck.toString()); } + log.info("shuffling..."); + deck.shuffle(); + doSleep(maxSleep); log.debug("dealing..."); From ba6303a2137a90464b3db0cfcfb967a6b2c1ba04 Mon Sep 17 00:00:00 2001 From: b0n541 Date: Sat, 28 Oct 2023 08:32:13 +0200 Subject: [PATCH 3/4] #167 Prevent shuffling for predefined card decks --- .../main/java/org/jskat/util/CardDeck.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/jskat-base/src/main/java/org/jskat/util/CardDeck.java b/jskat-base/src/main/java/org/jskat/util/CardDeck.java index 51775b049..6ee340901 100644 --- a/jskat-base/src/main/java/org/jskat/util/CardDeck.java +++ b/jskat-base/src/main/java/org/jskat/util/CardDeck.java @@ -30,6 +30,8 @@ public class CardDeck extends CardList { Rank.SEVEN, List.of(Card.C7, Card.S7, Card.H7, Card.D7)); } + private boolean isShuffled = false; + /** * Creates a new instance of CardDeck */ @@ -37,10 +39,7 @@ public CardDeck() { super(); - // Adds a card for every suit and value - for (final Card card : Card.values()) { - add(card); - } + addAll(Arrays.stream(Card.values()).toList()); } /** @@ -65,6 +64,8 @@ public CardDeck(final List foreHandCards, addAll(foreHandCards.subList(7, 10)); addAll(middleHandCards.subList(7, 10)); addAll(rearHandCards.subList(7, 10)); + + isShuffled = true; } /** @@ -85,16 +86,6 @@ public CardDeck(final String foreHandCards, getCardsFromString(skatCards)); } - /** - * Constructor - * - * @param cards Card distribution - */ - public CardDeck(final String cards) { - - addAll(getCardsFromString(cards)); - } - private static List getCardsFromString(final String cards) { final List result = new ArrayList<>(); @@ -107,16 +98,6 @@ private static List getCardsFromString(final String cards) { return result; } - /** - * Constructor - * - * @param cards Card distribution - */ - public CardDeck(final CardList cards) { - - addAll(cards); - } - /** * {@inheritDoc} */ @@ -133,6 +114,15 @@ public boolean add(final Card card) { return super.add(card); } + @Override + public boolean addAll(final Collection newCards) { + boolean result = false; + for (final Card card : newCards) { + result |= add(card); + } + return result; + } + /** * Gets a complete card deck * @@ -152,14 +142,20 @@ public static EnumSet getAllCards() { */ public static CardDeck getPerfectDistribution() { return new CardDeck( - "CJ SJ HJ CK CQ SK C7 C8 S7 H7 D7 DJ CA CT C9 SQ HA HK HQ S8 H8 H9 HT SA ST S9 D8 D9 DT DA DK DQ"); + "CJ SJ HJ DJ CA CT C9 SA ST S9", + "CK CQ SK SQ HA HK HQ D8 D9 DT", + "C7 C8 S7 S8 H8 H9 HT DA DK DQ", + "H7 D7"); } /** * Shuffles the CardDeck */ public void shuffle() { - // Simple random shuffling - Collections.shuffle(cards); + if (!isShuffled) { + // Simple random shuffling + Collections.shuffle(cards); + isShuffled = true; + } } } From 7165df801138033b54078e493dacf3122bbef7eb Mon Sep 17 00:00:00 2001 From: b0n541 Date: Sat, 28 Oct 2023 08:34:28 +0200 Subject: [PATCH 4/4] #167 Use matadors instead of multipliers for game result display --- .../org/jskat/control/iss/MessageParser.java | 7 +- .../main/java/org/jskat/data/GameSummary.java | 20 ++-- .../java/org/jskat/data/SkatGameData.java | 13 ++- .../java/org/jskat/data/SkatGameResult.java | 102 +++++++++--------- .../java/org/jskat/util/rule/GrandRule.java | 12 ++- .../java/org/jskat/util/rule/NullRule.java | 6 +- .../java/org/jskat/util/rule/RamschRule.java | 24 +++-- .../java/org/jskat/util/rule/SkatRule.java | 9 +- .../org/jskat/util/rule/SuitGrandRule.java | 43 +++----- .../java/org/jskat/util/rule/SuitRule.java | 12 ++- .../jskat/control/iss/MessageParserTest.java | 23 ++-- .../java/org/jskat/util/CardDeckTest.java | 6 +- .../org/jskat/util/rule/RamschRuleTest.java | 22 ++-- .../org/jskat/util/rule/SuitRuleTest.java | 10 +- .../gui/swing/table/GameInformationPanel.java | 31 +++--- 15 files changed, 183 insertions(+), 157 deletions(-) diff --git a/jskat-base/src/main/java/org/jskat/control/iss/MessageParser.java b/jskat-base/src/main/java/org/jskat/control/iss/MessageParser.java index 217cf2167..dc89ec785 100644 --- a/jskat-base/src/main/java/org/jskat/control/iss/MessageParser.java +++ b/jskat-base/src/main/java/org/jskat/control/iss/MessageParser.java @@ -443,8 +443,7 @@ static SkatGameData parseGameSummary(final String gameSummary) { final SkatGameData result = new SkatGameData(); final Pattern summaryPartPattern = Pattern.compile("(\\w+)\\[(.*?)\\]"); - final Matcher summaryPartMatcher = summaryPartPattern - .matcher(gameSummary); + final Matcher summaryPartMatcher = summaryPartPattern.matcher(gameSummary); while (summaryPartMatcher.find()) { @@ -600,11 +599,11 @@ private static void parseResultToken(final SkatGameData gameData, final int matadors = Integer.parseInt(token.substring(2)); gameData.getGameResult().setPlayWithJacks(matadors > 0); - gameData.getGameResult().setMultiplier(Math.abs(matadors)); + gameData.getGameResult().setMatadors(Math.abs(matadors)); } else if ("overbid".equals(token)) { - gameData.getResult().setOverBidded(true); + gameData.getResult().setOverBid(true); } else if (token.startsWith("p:")) { diff --git a/jskat-base/src/main/java/org/jskat/data/GameSummary.java b/jskat-base/src/main/java/org/jskat/data/GameSummary.java index 3105807f0..df667a299 100644 --- a/jskat-base/src/main/java/org/jskat/data/GameSummary.java +++ b/jskat-base/src/main/java/org/jskat/data/GameSummary.java @@ -95,7 +95,7 @@ public final static class GameSummaryFactory { * @return Game announcement */ public GameSummary getSummary() { - GameSummary result; + final GameSummary result; if (validate()) { result = tmpSummary; tmpSummary = new GameSummary(); @@ -183,7 +183,7 @@ public void setDeclarer(final Player position) { tmpSummary.declarer = position; } - public void addRamschLooser(Player looser) { + public void addRamschLooser(final Player looser) { tmpSummary.ramschLosers.add(looser); } @@ -210,11 +210,11 @@ private boolean validate() { return true; } - public void setContra(Boolean contra) { + public void setContra(final Boolean contra) { tmpSummary.contra = contra; } - public void setRe(Boolean re) { + public void setRe(final Boolean re) { tmpSummary.re = re; } } @@ -307,12 +307,12 @@ public int getFinalOpponentScore() { } /** - * Gets the multiplier for the game + * Gets the matadors for the game * - * @return Multiplier for the game + * @return Matadors for the game */ - public int getGameMultiplier() { - return gameResult.getMultiplier(); + public int getMatadors() { + return gameResult.getMatadors(); } /** @@ -348,7 +348,7 @@ public final List getTricks() { @Override public String toString() { - StringBuffer result = new StringBuffer(); + final StringBuffer result = new StringBuffer(); result.append("Game summary: ").append(gameType); @@ -414,7 +414,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } diff --git a/jskat-base/src/main/java/org/jskat/data/SkatGameData.java b/jskat-base/src/main/java/org/jskat/data/SkatGameData.java index cba4c9efc..378541560 100644 --- a/jskat-base/src/main/java/org/jskat/data/SkatGameData.java +++ b/jskat-base/src/main/java/org/jskat/data/SkatGameData.java @@ -303,7 +303,7 @@ public boolean isOverBid() { log.warn("Overbidding cannot happen in Ramsch games: gameType=" + getGameType()); } - return result.isOverBidded(); + return result.getOverBid(); } /** @@ -464,7 +464,7 @@ public void calcResult() { } else { if (rules.isOverbid(this)) { result.setWon(false); - result.setOverBidded(true); + result.setOverBid(true); result.setGameValue(rules.calcOverbidGameResult(this)); } else { if (!result.isWon()) { @@ -481,8 +481,8 @@ public void calcResult() { } if (GameType.GRAND_SUIT.contains(announcement.contract().gameType())) { - result.setMultiplier(rules.getMultiplier(this)); result.setPlayWithJacks(rules.isPlayWithJacks(this)); + result.setMatadors(rules.getMatadors(this)); } if (GameType.RAMSCH == announcement.contract().gameType()) { @@ -718,6 +718,13 @@ public Map getDealtCards() { Player.REARHAND, dealtCards.get(Player.REARHAND).getImmutableCopy()); } + public CardList getDealtDeclarerCardsAndSkat() { + final CardList declarerCards = new CardList(getDealtCards().get(getDeclarer())); + declarerCards.addAll(getDealtSkat()); + return declarerCards; + } + + /** * Gets the dealt skat * diff --git a/jskat-base/src/main/java/org/jskat/data/SkatGameResult.java b/jskat-base/src/main/java/org/jskat/data/SkatGameResult.java index e0fb89a83..8c85fd036 100644 --- a/jskat-base/src/main/java/org/jskat/data/SkatGameResult.java +++ b/jskat-base/src/main/java/org/jskat/data/SkatGameResult.java @@ -7,29 +7,29 @@ */ public class SkatGameResult implements Cloneable { - private Integer gameValue; - private Integer multiplier; - private Integer finalDeclarerPoints; - private Integer finalOpponentPoints; - private Boolean playWithJacks; - private Boolean won; - private Boolean overBidded; - private Boolean schneider; - private Boolean schwarz; - private Boolean durchmarsch; - private Boolean jungfrau; + private int gameValue; + private int finalDeclarerPoints; + private int finalOpponentPoints; + private boolean playWithJacks; + private int matadors; + private boolean won; + private boolean overBid; + private boolean schneider; + private boolean schwarz; + private boolean durchmarsch; + private boolean jungfrau; /** * Constructor */ public SkatGameResult() { gameValue = -1; - multiplier = 0; + matadors = 0; finalDeclarerPoints = 0; finalOpponentPoints = 0; playWithJacks = false; won = false; - overBidded = false; + overBid = false; schneider = false; schwarz = false; durchmarsch = false; @@ -42,12 +42,12 @@ public SkatGameResult() { @Override public SkatGameResult clone() { - SkatGameResult result = new SkatGameResult(); + final SkatGameResult result = new SkatGameResult(); result.setGameValue(gameValue); - result.setMultiplier(multiplier); + result.setMatadors(matadors); result.setPlayWithJacks(playWithJacks); result.setWon(won); - result.setOverBidded(overBidded); + result.setOverBid(overBid); result.setSchneider(schneider); result.setSchwarz(schwarz); result.setDurchmarsch(durchmarsch); @@ -79,17 +79,17 @@ public void setWon(final boolean won) { * * @return TRUE, if the declarer did overbid */ - public boolean isOverBidded() { - return overBidded; + public boolean getOverBid() { + return overBid; } /** * Sets whether the declarer did overbid * - * @param overBidded TRUE, if the declarer did overvid + * @param overBid TRUE, if the declarer did overvid */ - public void setOverBidded(final boolean overBidded) { - this.overBidded = overBidded; + public void setOverBid(final boolean overBid) { + this.overBid = overBid; } /** @@ -150,7 +150,7 @@ public boolean isDurchmarsch() { */ public void setDurchmarsch(final boolean durchmarsch) { if (durchmarsch) { - setJungfrau(true); + setJungfrau(false); } this.durchmarsch = durchmarsch; } @@ -193,41 +193,39 @@ public void setGameValue(final int gameValue) { } /** - * Gets the multiplier
- * only meaningful in suit and grand games + * Gets whether the declarer played with or without jacks * - * @return Multiplier + * @return TRUE, if the declarer played with jacks */ - public int getMultiplier() { - return multiplier; + public boolean isPlayWithJacks() { + return playWithJacks; } /** - * Sets the multiplier
- * only meaningful in suit and grand games + * Sets whether the declarer played with or without jacks * - * @param multiplier Multiplier + * @param playWithJacks TRUE, if the declarer played with jacks */ - public void setMultiplier(final int multiplier) { - this.multiplier = multiplier; + public void setPlayWithJacks(final boolean playWithJacks) { + this.playWithJacks = playWithJacks; } /** - * Gets wether the declarer played with or without jacks + * Gets the number of matadors (Jacks and trump cards in a row without gaps). * - * @return TRUE, if the declarer played with jacks + * @return Number of matadors */ - public boolean isPlayWithJacks() { - return playWithJacks; + public int getMatadors() { + return matadors; } /** - * Sets whether the declarer played with or without jacks + * Sets the number of matadors. * - * @param playWithJacks TRUE, if the declarer played with jacks + * @param matadors Number of matadors. */ - public void setPlayWithJacks(final boolean playWithJacks) { - this.playWithJacks = playWithJacks; + public void setMatadors(final int matadors) { + this.matadors = matadors; } /** @@ -273,10 +271,18 @@ public int getFinalDeclarerPoints() { */ @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(gameValue).append(", mult:").append(multiplier); - if (overBidded) { - sb.append(" (overbidded)"); + final StringBuilder sb = new StringBuilder(); + sb.append(gameValue); + if (matadors > 0) { + if (playWithJacks) { + sb.append(" with: "); + } else { + sb.append(" without: "); + } + sb.append(matadors).append(" play ").append(matadors + 1); + } + if (overBid) { + sb.append(" (overbid)"); } if (durchmarsch) { sb.append(" (Durchmarsch)"); @@ -296,12 +302,12 @@ public String toString() { public int hashCode() { return Objects .hash(durchmarsch, finalDeclarerPoints, finalOpponentPoints, gameValue, - jungfrau, multiplier, overBidded, playWithJacks, schneider, + jungfrau, matadors, overBid, playWithJacks, schneider, schwarz, won); } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -318,8 +324,8 @@ public boolean equals(Object obj) { Objects.equals(finalOpponentPoints, other.finalOpponentPoints) && Objects.equals(gameValue, other.gameValue) && Objects.equals(jungfrau, other.jungfrau) && - Objects.equals(multiplier, other.multiplier) && - Objects.equals(overBidded, other.overBidded) && + Objects.equals(matadors, other.matadors) && + Objects.equals(overBid, other.overBid) && Objects.equals(playWithJacks, other.playWithJacks) && Objects.equals(schneider, other.schneider) && Objects.equals(schwarz, other.schwarz) && diff --git a/jskat-base/src/main/java/org/jskat/util/rule/GrandRule.java b/jskat-base/src/main/java/org/jskat/util/rule/GrandRule.java index 5eb4592ef..dc0156c16 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/GrandRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/GrandRule.java @@ -12,12 +12,17 @@ public class GrandRule extends SuitGrandRule { /** * {@inheritDoc} */ - @Override - public int getMultiplier(CardList cards, GameType gameType) { + public int getBaseMultiplier(final CardList cards, final GameType gameType) { if (gameType != GameType.GRAND) { throw new IllegalArgumentException("Wrong ruleset - " + gameType); } - int result = 1; + + return getMatadors(cards, gameType) + 1; + } + + public int getMatadors(final CardList cards, final GameType gameType) { + int result = 0; + if (cards.contains(Card.CJ)) { result++; if (cards.contains(Card.SJ)) { @@ -41,6 +46,7 @@ public int getMultiplier(CardList cards, GameType gameType) { } } } + return result; } } diff --git a/jskat-base/src/main/java/org/jskat/util/rule/NullRule.java b/jskat-base/src/main/java/org/jskat/util/rule/NullRule.java index 81426e925..5b19be24e 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/NullRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/NullRule.java @@ -121,12 +121,8 @@ public boolean hasSuit(final GameType gameType, final CardList hand, return result; } - /** - * {@inheritDoc} - */ @Override - public int getMultiplier( - @SuppressWarnings("unused") final SkatGameData gameData) { + public int getMatadors(final SkatGameData gameData) { return 0; } diff --git a/jskat-base/src/main/java/org/jskat/util/rule/RamschRule.java b/jskat-base/src/main/java/org/jskat/util/rule/RamschRule.java index 51add7380..d82dc5c20 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/RamschRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/RamschRule.java @@ -20,9 +20,9 @@ public class RamschRule extends SuitGrandRamschRule { */ @Override public int getGameValueForWonGame(final SkatGameData gameData) { - int highestPlayerPoints = getGetHighestPlayerPoints(gameData); + final int highestPlayerPoints = getGetHighestPlayerPoints(gameData); - return highestPlayerPoints * getMultiplier(gameData); + return highestPlayerPoints * getBaseMultiplier(gameData); } /** @@ -38,10 +38,10 @@ private static int getGetHighestPlayerPoints(final SkatGameData gameData) { int result = 0; - int foreHandPoints = gameData.getPlayerPoints(Player.FOREHAND); - int middleHandPoints = gameData.getPlayerPoints(Player.MIDDLEHAND); - int rearHandPoints = gameData.getPlayerPoints(Player.REARHAND); - int skatPoints = JSkatOptions.instance().getRamschSkatOwner() == RamschSkatOwner.LOSER ? gameData + final int foreHandPoints = gameData.getPlayerPoints(Player.FOREHAND); + final int middleHandPoints = gameData.getPlayerPoints(Player.MIDDLEHAND); + final int rearHandPoints = gameData.getPlayerPoints(Player.REARHAND); + final int skatPoints = JSkatOptions.instance().getRamschSkatOwner() == RamschSkatOwner.LOSER ? gameData .getSkat().getTotalValue() : 0; // FIXME (jan 18.11.2011) make this simpler @@ -91,7 +91,7 @@ public boolean isGameWon(final SkatGameData gameData) { public static final boolean isDurchmarsch(final Player player, final SkatGameData gameData) { if (gameData.getTricks().size() == 10) { - for (Trick t : gameData.getTricks()) { + for (final Trick t : gameData.getTricks()) { if (t.getTrickWinner() != player) { return false; } @@ -113,7 +113,7 @@ public static final boolean isDurchmarsch(final Player player, public static final boolean isJungfrau(final Player player, final SkatGameData gameData) { if (gameData.getTricks().size() == 10) { - for (Trick t : gameData.getTricks()) { + for (final Trick t : gameData.getTricks()) { if (t.getTrickWinner() == player) { return false; } @@ -126,8 +126,7 @@ public static final boolean isJungfrau(final Player player, /** * {@inheritDoc} */ - @Override - public int getMultiplier(final SkatGameData gameData) { + public int getBaseMultiplier(final SkatGameData gameData) { int multiplier = 1; @@ -142,6 +141,11 @@ public int getMultiplier(final SkatGameData gameData) { return multiplier; } + @Override + public int getMatadors(final SkatGameData gameData) { + return 0; + } + /** * {@inheritDoc} */ diff --git a/jskat-base/src/main/java/org/jskat/util/rule/SkatRule.java b/jskat-base/src/main/java/org/jskat/util/rule/SkatRule.java index 48f9533c4..c39c36c89 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/SkatRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/SkatRule.java @@ -83,12 +83,11 @@ public interface SkatRule { Player calculateTrickWinner(GameType gameType, Trick trick); /** - * calculates the multiplier of a card list with regard to the ruleset - * - * @param gameData Game data - * @return the multiplier for bidding and game announcement + * Calculates the number of matadors (Jacks and trump cards in a row without gaps). + *

+ * return Number of matadors */ - int getMultiplier(SkatGameData gameData); + int getMatadors(SkatGameData gameData); /** * Checks whether the game is played with jacks or without diff --git a/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java b/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java index b2fd00832..b92387aea 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/SuitGrandRule.java @@ -40,7 +40,7 @@ private static int getMinimumWinningScore(final SkatGameData gameData) { */ @Override public int getGameValueForWonGame(final SkatGameData gameData) { - int multiplier = getMultiplier(gameData); + int multiplier = getBaseMultiplier(gameData); log.debug("calcSuitResult: after Jacks and Trump: multiplier " + multiplier); @@ -111,43 +111,34 @@ public int calcGameResult(final SkatGameData gameData) { * @param gameData Game data * @return Multiplier */ - @Override - public int getMultiplier(final SkatGameData gameData) { - - int result = 0; - - final CardList declarerCards = getDeclarerCards(gameData); + public int getBaseMultiplier(final SkatGameData gameData) { + return getBaseMultiplier(gameData.getDealtDeclarerCardsAndSkat(), gameData.getGameType()); + } - result = getMultiplier(declarerCards, gameData.getGameType()); + /** + * Gets the multiplier for a {@link CardList} and a {@link GameType} + * + * @param cards Card list + * @param gameType Game type + * @return Multiplier + */ + protected abstract int getBaseMultiplier(CardList cards, GameType gameType); - return result; + @Override + public int getMatadors(final SkatGameData gameData) { + return getMatadors(gameData.getDealtDeclarerCardsAndSkat(), gameData.getGameType()); } - private CardList getDeclarerCards(final SkatGameData gameData) { - final CardList declarerCards = new CardList(gameData.getDealtCards().get(gameData.getDeclarer())); - declarerCards.addAll(gameData.getDealtSkat()); - return declarerCards; - } + public abstract int getMatadors(CardList cards, GameType gameType); /** * {@inheritDoc} */ @Override public boolean isPlayWithJacks(final SkatGameData gameData) { - final CardList declarerCards = getDeclarerCards(gameData); - - return declarerCards.contains(Card.CJ); + return gameData.getDealtDeclarerCardsAndSkat().contains(Card.CJ); } - /** - * Gets the multiplier for a {@link CardList} and a {@link GameType} - * - * @param cards Card list - * @param gameType Game type - * @return Multiplier - */ - public abstract int getMultiplier(CardList cards, GameType gameType); - /** * Checks whether a game was a schneider game
* schneider means one party made only 30 points or below diff --git a/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java b/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java index 1a16fd3e6..4453fa536 100644 --- a/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java +++ b/jskat-base/src/main/java/org/jskat/util/rule/SuitRule.java @@ -10,12 +10,17 @@ public class SuitRule extends SuitGrandRule { /** * {@inheritDoc} */ - @Override - public int getMultiplier(final CardList cards, final GameType gameType) { + public int getBaseMultiplier(final CardList cards, final GameType gameType) { if (gameType == GameType.GRAND || gameType == GameType.RAMSCH || gameType == GameType.NULL) { throw new IllegalArgumentException("Wrong ruleset - " + gameType); } - int result = 1; + + return getMatadors(cards, gameType) + 1; + } + + public int getMatadors(final CardList cards, final GameType gameType) { + int result = 0; + if (cards.contains(Card.CJ)) { result++; if (cards.contains(Card.SJ)) { @@ -53,6 +58,7 @@ public int getMultiplier(final CardList cards, final GameType gameType) { } } } + return result; } } diff --git a/jskat-base/src/test/java/org/jskat/control/iss/MessageParserTest.java b/jskat-base/src/test/java/org/jskat/control/iss/MessageParserTest.java index 61242a6ab..dae5fbb1b 100644 --- a/jskat-base/src/test/java/org/jskat/control/iss/MessageParserTest.java +++ b/jskat-base/src/test/java/org/jskat/control/iss/MessageParserTest.java @@ -93,7 +93,7 @@ public void testParseGameSummary() { assertFalse(gameData.isGameWon()); assertThat(gameData.getResult().getGameValue()).isEqualTo(-54); assertThat(gameData.getResult().isPlayWithJacks()).isFalse(); - assertThat(gameData.getResult().getMultiplier()).isEqualTo(2); + assertThat(gameData.getResult().getMatadors()).isEqualTo(2); assertThat(gameData.getDeclarerScore()).isEqualTo(59); assertThat(gameData.getOpponentScore()).isEqualTo(61); assertFalse(gameData.isSchneider()); @@ -102,10 +102,11 @@ public void testParseGameSummary() { } private static void checkTrick(final Trick trick, - final Player trickForeHand, final Card firstCard, - final Card secondCard, final Card thirdCard, + final Player trickForeHand, + final Card firstCard, + final Card secondCard, + final Card thirdCard, final Player trickWinner) { - final int trickNo = trick.getTrickNumberInGame(); assertThat(trick.getForeHand()).isEqualTo(trickForeHand); assertThat(trick.getFirstCard()).isEqualTo(firstCard); assertThat(trick.getSecondCard()).isEqualTo(secondCard); @@ -161,7 +162,7 @@ public void testParseGameSummary002() { assertTrue(gameData.isGameWon()); assertThat(gameData.getResult().getGameValue()).isEqualTo(96); assertThat(gameData.getResult().isPlayWithJacks()).isTrue(); - assertThat(gameData.getResult().getMultiplier()).isEqualTo(3); + assertThat(gameData.getResult().getMatadors()).isEqualTo(3); assertThat(gameData.getDeclarerScore()).isEqualTo(85); assertThat(gameData.getOpponentScore()).isEqualTo(35); assertFalse(gameData.isSchneider()); @@ -235,7 +236,7 @@ public void testParseGameSummary_PassedGame() { assertFalse(gameData.isGameWon()); assertThat(gameData.getResult().getGameValue()).isEqualTo(0); assertThat(gameData.getResult().isPlayWithJacks()).isFalse(); - assertThat(gameData.getResult().getMultiplier()).isEqualTo(0); + assertThat(gameData.getResult().getMatadors()).isEqualTo(0); assertThat(gameData.getDeclarerScore()).isEqualTo(0); assertThat(gameData.getOpponentScore()).isEqualTo(0); assertFalse(gameData.isSchneider()); @@ -290,6 +291,16 @@ public void testParseGameSummary_CorruptData() { final SkatGameData gameData = MessageParser.parseGameSummary(gameSummary); } + @Test + public void testParseGameSummary_OverbidSuitGame() { + + final String gameSummary = "(;GM[Skat]PC[International Skat Server]CO[]SE[403949]ID[8650652]DT[2023-10-18/18:44:11/UTC]P0[kermit]P1[bonsai]P2[kermit:2]R0[]R1[0.0]R2[]MV[w DQ.CK.HT.CT.SK.C9.DA.D9.DK.S8.H9.S7.SA.H8.C7.CA.H7.CJ.CQ.D7.SQ.S9.C8.DT.SJ.HA.ST.D8.DJ.HJ.HQ.HK 1 18 0 p 2 20 1 y 2 22 1 y 2 23 1 y 2 24 1 y 2 27 1 y 2 30 1 y 2 33 1 y 2 35 1 y 2 36 1 p 2 s w HQ.HK 2 D.C8.ST 0 HT 1 H9 2 HA 2 DJ 0 D9 1 D7 2 HJ 0 DQ 1 CJ 1 CA 2 DT 0 C9 2 SJ 0 DK 1 H8 2 HK 0 S8 1 H7 2 HQ 0 SK 1 C7 2 SQ 0 CT 1 SA 1 S7 2 S9 0 CK 2 D8 0 DA 1 CQ ]R[d:2 loss v:-72 m:-1 overbid p:75 t:7 s:0 z:0 p0:0 p1:0 p2:0 l:-1 to:-1 r:0] ;)"; + + final SkatGameData gameData = MessageParser.parseGameSummary(gameSummary); + + assertThat(gameData.getResult().getMatadors()).isEqualTo(1); + } + @Test public void testParseTableUpdatePlayerLeft() { diff --git a/jskat-base/src/test/java/org/jskat/util/CardDeckTest.java b/jskat-base/src/test/java/org/jskat/util/CardDeckTest.java index c4f27a558..46c684441 100644 --- a/jskat-base/src/test/java/org/jskat/util/CardDeckTest.java +++ b/jskat-base/src/test/java/org/jskat/util/CardDeckTest.java @@ -1,4 +1,3 @@ - package org.jskat.util; @@ -48,7 +47,10 @@ public void addDoubleCard() { public void addTooMuchCards() { assertThrows(IllegalStateException.class, () -> { final CardDeck cards = new CardDeck( - "CJ SJ HJ CK CQ SK C7 C8 S7 H7 D7 DJ CA CT C9 SQ HA HK HQ S8 H8 H9 HT SA ST S9 D8 D9 DT DA DK DQ"); + "CJ SJ HJ CK CQ SK C7 C8 S7 H7", + "D7 DJ CA CT C9 SQ HA HK HQ S8", + "H8 H9 HT SA ST S9 D8 D9 DT DA", + "DK DQ"); cards.add(Card.CJ); }); } diff --git a/jskat-base/src/test/java/org/jskat/util/rule/RamschRuleTest.java b/jskat-base/src/test/java/org/jskat/util/rule/RamschRuleTest.java index 543f52eaa..8c69dc380 100644 --- a/jskat-base/src/test/java/org/jskat/util/rule/RamschRuleTest.java +++ b/jskat-base/src/test/java/org/jskat/util/rule/RamschRuleTest.java @@ -20,7 +20,7 @@ public class RamschRuleTest extends AbstractJSkatTest { private SkatGameData data; - private static final SkatRule ramschRules = SkatRuleFactory.getSkatRules(GameType.RAMSCH); + private static final RamschRule ramschRules = (RamschRule) SkatRuleFactory.getSkatRules(GameType.RAMSCH); /** * {@inheritDoc} @@ -224,19 +224,19 @@ public void testCalcGameValue_AllPlayerEqualPoints() { @Test public void testGetMultiplierGeschoben() { - assertThat(ramschRules.getMultiplier(data)).isEqualTo(1); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(1); data.addGeschoben(); - assertThat(ramschRules.getMultiplier(data)).isEqualTo(2); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(2); data.addGeschoben(); - assertThat(ramschRules.getMultiplier(data)).isEqualTo(4); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(4); data.addGeschoben(); - assertThat(ramschRules.getMultiplier(data)).isEqualTo(8); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(8); } /** @@ -245,7 +245,7 @@ public void testGetMultiplierGeschoben() { @Test public void testMultiplierJungfrau() { - assertThat(ramschRules.getMultiplier(data)).isEqualTo(1); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(1); for (int i = 0; i < 10; i++) { final Trick trick = new Trick(0, Player.FOREHAND); @@ -259,7 +259,7 @@ public void testMultiplierJungfrau() { data.setJungfrauDurchmarsch(); - assertThat(ramschRules.getMultiplier(data)).isEqualTo(2); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(2); assertTrue(data.isJungfrau()); assertFalse(data.isDurchmarsch()); } @@ -270,7 +270,7 @@ public void testMultiplierJungfrau() { @Test public void testMultiplierGeschobenJungfrau() { - assertThat(ramschRules.getMultiplier(data)).isEqualTo(1); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(1); data.addGeschoben(); data.addGeschoben(); @@ -288,7 +288,7 @@ public void testMultiplierGeschobenJungfrau() { data.setJungfrauDurchmarsch(); - assertThat(ramschRules.getMultiplier(data)).isEqualTo(16); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(16); assertTrue(data.isJungfrau()); assertFalse(data.isDurchmarsch()); } @@ -299,7 +299,7 @@ public void testMultiplierGeschobenJungfrau() { @Test public void testMultiplierDurchmarsch() { - assertThat(ramschRules.getMultiplier(data)).isEqualTo(1); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(1); // all tricks are made by forehand player for (int i = 0; i < 10; i++) { @@ -310,7 +310,7 @@ public void testMultiplierDurchmarsch() { data.setJungfrauDurchmarsch(); - assertThat(ramschRules.getMultiplier(data)).isEqualTo(2); + assertThat(ramschRules.getBaseMultiplier(data)).isEqualTo(2); assertTrue(data.isJungfrau()); assertTrue(data.isDurchmarsch()); } diff --git a/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java b/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java index a7a207108..e07537b33 100644 --- a/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java +++ b/jskat-base/src/test/java/org/jskat/util/rule/SuitRuleTest.java @@ -327,7 +327,7 @@ public void testOverbid() { assertThat(data.getResult().isWon()).isFalse(); assertThat(data.getResult().getGameValue()).isEqualTo(-54); - assertThat(data.getResult().isOverBidded()).isTrue(); + assertThat(data.getResult().getOverBid()).isTrue(); } /** @@ -355,13 +355,13 @@ public void testOverbidWithSchneider() { public void testGetMultiplier() { final var rule = new SuitRule(); - assertThat(rule.getMultiplier( + assertThat(rule.getMatadors( CardList.of(Card.SJ, Card.HJ, Card.DJ, Card.DT, Card.D8, Card.SQ, Card.S9, Card.HA, Card.HK, Card.HQ), GameType.DIAMONDS)) - .isEqualTo(2); - assertThat(rule.getMultiplier( + .isEqualTo(1); + assertThat(rule.getMatadors( CardList.of(Card.HJ, Card.DJ, Card.DT, Card.D8, Card.SQ, Card.S9, Card.HA, Card.HK, Card.HQ, Card.H7), GameType.DIAMONDS)) - .isEqualTo(3); + .isEqualTo(2); } } diff --git a/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java b/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java index 75b02e793..69e38a29b 100644 --- a/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java +++ b/jskat-swing-gui/src/main/java/org/jskat/gui/swing/table/GameInformationPanel.java @@ -28,22 +28,22 @@ class GameInformationPanel extends JPanel { private int gameNumber; private GameState gameState; private GameType gameType; - private int multiplier; private boolean playWithJacks; + private int matadors; private boolean handGame; private boolean ouvertGame; private boolean schneiderAnnounced; private boolean schneider; private boolean schwarzAnnounced; private boolean schwarz; - private boolean overBidded; + private boolean overBid; private boolean contra; private boolean re; private int trick; private boolean gameWon; private int declarerPoints; private int opponentPoints; - private Set ramschLoosers; + private Set ramschLosers; /** * Constructor @@ -97,7 +97,7 @@ void setGameContract(final GameContract contract) { private void resetGameData() { gameType = null; - multiplier = 0; + matadors = 0; playWithJacks = false; handGame = false; ouvertGame = false; @@ -105,14 +105,14 @@ private void resetGameData() { schneider = false; schwarzAnnounced = false; schwarz = false; - overBidded = false; + overBid = false; contra = false; re = false; trick = 1; gameWon = false; declarerPoints = 0; opponentPoints = 0; - ramschLoosers = new HashSet<>(); + ramschLosers = new HashSet<>(); } private void refreshText() { @@ -152,7 +152,7 @@ private void appendGameOverDetails(final StringBuffer text) { if (gameType == GameType.RAMSCH) { text.append(" - "); - final Iterator iterator = ramschLoosers.iterator(); + final Iterator iterator = ramschLosers.iterator(); if (iterator.hasNext()) { text.append(strings.getPlayerString(iterator.next())); } @@ -164,8 +164,7 @@ private void appendGameOverDetails(final StringBuffer text) { } else if (gameType != GameType.NULL && gameType != GameType.PASSED_IN) { text.append(" - "); - text.append( - declarerPoints + " " + strings.getString("versus") + " "); + text.append(declarerPoints + " " + strings.getString("versus") + " "); text.append(opponentPoints + " " + strings.getString("points")); } } @@ -178,15 +177,15 @@ private void appendGameType(final StringBuffer text) { if (gameType != null) { text.append(" [" + strings.getGameType(gameType)); - if (gameState.equals(GameState.GAME_OVER) && multiplier > 0) { + if (gameState.equals(GameState.GAME_OVER) && matadors > 0) { if (playWithJacks) { text.append(" " + strings.getString("with")); } else { text.append(" " + strings.getString("without")); } - text.append(" " + (multiplier - 1)); + text.append(" " + matadors); text.append(" " + strings.getString("play")); - text.append(" " + multiplier); + text.append(" " + (matadors + 1)); } if (handGame) { @@ -217,7 +216,7 @@ private void appendGameType(final StringBuffer text) { text.append(" " + strings.getString("re")); } - if (overBidded) { + if (overBid) { text.append(" " + strings.getString("overbidded")); } @@ -233,13 +232,13 @@ private void appendGameNumber(final StringBuffer text) { void setGameSummary(final GameSummary summary) { - multiplier = summary.getGameMultiplier(); playWithJacks = summary.isGamePlayedWithJacks(); + matadors = summary.getMatadors(); gameWon = summary.isGameWon(); declarerPoints = summary.getFinalDeclarerPoints(); opponentPoints = summary.getFinalOpponentScore(); - ramschLoosers = summary.getRamschLosers(); - overBidded = summary.gameResult.isOverBidded(); + ramschLosers = summary.getRamschLosers(); + overBid = summary.gameResult.getOverBid(); schneider = summary.gameResult.isSchneider(); schwarz = summary.gameResult.isSchwarz(); refreshText();