@Override public GameAnnouncement announceGame() { log.debug("position: " + knowledge.getPlayerPosition()); // $NON-NLS-1$ log.debug( "bids: " + knowledge.getHighestBid(Player.FOREHAND) + //$NON-NLS-1$ " " + knowledge.getHighestBid(Player.MIDDLEHAND) + //$NON-NLS-1$ " " + knowledge.getHighestBid(Player.REARHAND)); // $NON-NLS-1$ final GameAnnouncementFactory factory = GameAnnouncement.getFactory(); // select a random game type (without RAMSCH and PASSED_IN) final GameType gameType = GameType.values()[random.nextInt(GameType.values().length - 2)]; factory.setGameType(gameType); if (Boolean.valueOf(random.nextBoolean())) { factory.setOuvert(true); if (gameType != GameType.NULL) { factory.setHand(true); factory.setSchneider(true); factory.setSchwarz(true); } } return factory.getAnnouncement(); }
private static void parseMoves(final SkatGameData result, final String summaryPart) { // FIXME (jansch 12.02.2012) parse moves correctly final GameAnnouncementFactory factory = GameAnnouncement.getFactory(); factory.setGameType(GameType.PASSED_IN); result.setAnnouncement(factory.getAnnouncement()); final StringTokenizer token = new StringTokenizer(summaryPart); while (token.hasMoreTokens()) { final List<String> moveToken = new ArrayList<String>(); moveToken.add(token.nextToken()); moveToken.add(token.nextToken()); final MoveInformation moveInfo = getMoveInformation(moveToken); switch (moveInfo.getType()) { case DEAL: for (final Player player : Player.values()) { result.addDealtCards(player, moveInfo.getCards(player)); } result.setDealtSkatCards(moveInfo.getSkat()); break; case BID: result.addPlayerBid(moveInfo.getPlayer(), moveInfo.getBidValue()); break; case HOLD_BID: result.addPlayerBid(moveInfo.getPlayer(), result.getMaxBidValue()); break; case PASS: result.setPlayerPass(moveInfo.getPlayer(), true); break; case GAME_ANNOUNCEMENT: result.setAnnouncement(moveInfo.getGameAnnouncement()); if (!moveInfo.getGameAnnouncement().isHand()) { result.setDiscardedSkat( moveInfo.getPlayer(), moveInfo.getGameAnnouncement().getDiscardedCards()); } break; case CARD_PLAY: if (result.getTricks().size() == 0) { // no tricks played so far result.addTrick(new Trick(0, Player.FOREHAND)); } else if (result.getCurrentTrick().getThirdCard() != null) { // last card of trick is played // set trick winner result.getCurrentTrick().setTrickWinner(moveInfo.getPlayer()); // create next trick result.addTrick(new Trick(result.getTricks().size(), moveInfo.getPlayer())); } result.addTrickCard(moveInfo.getCard()); if (result.getTricks().size() == 10 && result.getCurrentTrick().getThirdCard() != null) { // set the trick winner of the last trick final SkatRule skatRules = SkatRuleFactory.getSkatRules(result.getGameType()); result.setTrickWinner( 9, skatRules.calculateTrickWinner(result.getGameType(), result.getCurrentTrick())); } break; } } }
/** * <game-type> :: (G | C | S | H | D | N) (type Grand .. Null) [O] (ouvert) [H] (hand, not given * if O + trump game) [S] (schneider announced, only in H games, not if O or Z) [Z] (schwarz * announced, only in H games) */ private static GameAnnouncement parseGameAnnoucement( final MoveInformation info, final String move) { final StringTokenizer annToken = new StringTokenizer(move, "."); // $NON-NLS-1$ final String gameTypeString = annToken.nextToken(); final GameAnnouncementFactory factory = GameAnnouncement.getFactory(); // at first the game type GameType gameType = null; if (gameTypeString.startsWith("G")) { // $NON-NLS-1$ gameType = GameType.GRAND; } else if (gameTypeString.startsWith("C")) { // $NON-NLS-1$ gameType = GameType.CLUBS; } else if (gameTypeString.startsWith("S")) { // $NON-NLS-1$ gameType = GameType.SPADES; } else if (gameTypeString.startsWith("H")) { // $NON-NLS-1$ gameType = GameType.HEARTS; } else if (gameTypeString.startsWith("D")) { // $NON-NLS-1$ gameType = GameType.DIAMONDS; } else if (gameTypeString.startsWith("N")) { // $NON-NLS-1$ gameType = GameType.NULL; } factory.setGameType(gameType); boolean handGame = false; boolean ouvertGame = false; boolean schwarzGame = false; // parse other game modifiers for (int i = 1; i < gameTypeString.length(); i++) { final char mod = gameTypeString.charAt(i); if (mod == 'O') { factory.setOuvert(Boolean.TRUE); ouvertGame = true; } else if (mod == 'H') { factory.setHand(Boolean.TRUE); handGame = true; } else if (mod == 'S') { factory.setSchneider(Boolean.TRUE); } else if (mod == 'Z') { factory.setSchwarz(Boolean.TRUE); schwarzGame = true; } } if (gameType != GameType.NULL && handGame && schwarzGame) { factory.setSchneider(true); } if (gameType != GameType.NULL && ouvertGame) { factory.setHand(true); handGame = true; } if (gameType != GameType.NULL && ouvertGame && handGame) { factory.setSchneider(true); factory.setSchwarz(true); } if (annToken.hasMoreTokens()) { CardList showedCards = new CardList(); while (annToken.hasMoreTokens()) { showedCards.add(Card.getCardFromString(annToken.nextToken())); } CardList discardedCards = new CardList(); CardList ouvertCards = new CardList(); if (handGame) { ouvertCards.addAll(showedCards); } else if (showedCards.size() == 2) { discardedCards.addAll(showedCards); } else { discardedCards.add(showedCards.get(0)); discardedCards.add(showedCards.get(1)); for (int i = 2; i < showedCards.size(); i++) { ouvertCards.add(showedCards.get(i)); } } info.setOuvertCards(ouvertCards); factory.setDiscardedCards(discardedCards); } final GameAnnouncement ann = factory.getAnnouncement(); info.setGameAnnouncement(ann); return ann; }