예제 #1
0
  /** Tests that the interactive strategy properly stops and waits for input and then continues */
  @Test
  public void testGameInteractive() {
    // test number of rounds played (1 round)
    PlayingStrategy playingStrategy = new PlayingStrategyInteractive();
    Game game = new Game(playingStrategy, 1, MONEY_10);
    playGameWrapException(game);
    game.setDeck(
        new MockDeckFixed(
            Rank.TEN)); // deterministic deck needed here; with random may sometimes deal an ACE to
    // dealer, which will cause insurance offer to be made
    assertEquals(game.isFinished(), false);
    assertEquals(game.isUserInputNeeded(), true);
    Round round = game.getCurrentRound();
    assertEquals(Round.RoundStatus.HAND_BEING_DEALT, round.getRoundStatus());

    playingStrategy.setAmountBet(MONEY_1);
    playGameWrapException(game);

    assertEquals(game.isFinished(), false);
    assertEquals(game.isUserInputNeeded(), true);
    round = game.getCurrentRound();
    assertEquals(Round.RoundStatus.HANDS_BEING_PLAYED_OUT, round.getRoundStatus());

    playingStrategy.setResponseToOffer(Offer.STAND);
    playGameWrapException(game);

    assertEquals(game.isFinished(), true);
    assertEquals(game.isUserInputNeeded(), false);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);
    assertEquals(game.getNumRoundsPlayed(), 1);
    assertEquals(game.getNumRoundsToPlay(), 1);
    assertEquals(game.getPastRounds().size(), 1);
  }
예제 #2
0
  @Test
  public void testHandSplit() {
    PlayingStrategy playingStrategy = new PlayingStrategyInteractive();
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.THREE, Rank.TEN, Rank.TWO, Rank.EIGHT, Rank.SEVEN);
    game.setDeck(deck);

    playGameWrapException(game);
    playingStrategy.setAmountBet(MONEY_1);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.SPLIT);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.STAND);
    playGameWrapException(game);
    playingStrategy.setResponseToOffer(Offer.STAND);

    Round round = game.getLastRound();
    Hand hand1 = round.getHand(1);
    Hand hand2 = round.getHand(2);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand1, HandTest.toHand(Rank.THREE, Rank.TWO));
    assertEquals(hand2, HandTest.toHand(Rank.THREE, Rank.EIGHT));
    assertEquals(dealerHand, HandTest.toHand(Rank.TEN, Rank.SEVEN));

    // status changes
    assertEquals(hand1.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand2.getHandOutcome(), Hand.HandOutcome.LOSS);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_8);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_8);
  }