Exemple #1
0
 @Test
 public void testOneSpare() throws Exception {
   rollSpare();
   g.roll(3);
   rollMany(17, 0);
   assertEquals(16, g.score());
 }
  @Test
  public void testInsuranceWinGameLose() {
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, true);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.TEN, Rank.ACE, Rank.JACK);
    game.setDeck(deck);
    playGameWrapException(game);
    Round round = game.getLastRound();
    Hand hand = round.getHand(1);
    Hand dealerHand = round.getDealerHand();

    // dealing of cards
    assertEquals(hand, HandTest.toHand(Rank.THREE, Rank.TEN));
    assertEquals(dealerHand, HandTest.toHand(Rank.ACE, Rank.JACK));

    // calculation of points
    assertEquals(hand.getFinalPoints().intValue(), 13);
    assertEquals(dealerHand.getFinalPoints().intValue(), 21);

    // status changes
    assertEquals(hand.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand.getInsuranceOutcome(), Hand.InsuranceOutcome.WIN);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_10);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_10);
  }
  @Test
  public void testBuildDeck() {
    Game g = new spGame();
    g.buildDeck();

    assertEquals(40, g.deck.size());
  }
  @Test
  public void testHandDouble() {
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.DOUBLE, MONEY_1, false);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    Deck deck = new MockDeck(Rank.THREE, Rank.TEN, Rank.TEN, Rank.TWO, Rank.EIGHT);
    game.setDeck(deck);
    playGameWrapException(game);
    Round round = game.getLastRound();
    Hand hand = round.getHand(1);
    Hand dealerHand = round.getDealerHand();

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

    // calculation of points
    assertEquals(hand.getFinalPoints().intValue(), 15);
    assertEquals(dealerHand.getFinalPoints().intValue(), 18);

    // status changes
    assertEquals(hand.getHandOutcome(), Hand.HandOutcome.LOSS);
    assertEquals(hand.getInsuranceOutcome(), Hand.InsuranceOutcome.NOT_OFFERED);

    // money adjustment
    assertEquals(round.getMoneyStart(), MONEY_10);
    assertEquals(round.getMoneyEnd(), MONEY_8);
    assertEquals(game.getMoneyStart(), MONEY_10);
    assertEquals(game.getMoneyCurrent(), MONEY_8);
  }
Exemple #5
0
 @Test
 public void testGameInit() {
   Game g = new Game();
   g.buildDeck();
   g.shuffle();
   assertNotEquals(2, g.deck.get(0).getValue());
 }
  @Test
  public void testPerfectGame() {
    for (int frameIndex = 0; frameIndex < 12; frameIndex++) {
      game.roll(10);
    }

    assertEquals(300, game.getScore());
  }
Exemple #7
0
 @Test
 public void testPlay() {
   assert game.isNew();
   assertTrue("server in game", game.players().has(server));
   assertTrue("receiver in game", game.players().has(receiver));
   game.play();
   assert game.isOver();
 }
 @Test
 public void testSpRemoveFunction() {
   Game g = new spGame();
   g.buildDeck();
   g.customDeal(0, 3, 6, 9);
   g.remove(2);
   assertEquals(0, g.cols.get(2).size());
 }
Exemple #9
0
 @Test
 public void testOneStrike() throws Exception {
   rollStrike();
   g.roll(3);
   g.roll(4);
   rollMany(16, 0);
   assertEquals(24, g.score());
 }
Exemple #10
0
  @Test
  public void allGutterGame() {

    for (int frameIndex = 0; frameIndex < 20; frameIndex++) {
      game.roll(0);
    }

    assertEquals(0, game.getScore());
  }
Exemple #11
0
  @Test
  public void perfectGame() {

    for (int frameIndex = 0; frameIndex < 20; frameIndex++) {
      game.roll(1);
    }

    assertEquals(20, game.getScore());
  }
 @Test
 public void testSpCustomDeal() {
   Game g = new spGame();
   g.buildDeck();
   g.customDeal(0, 3, 6, 9);
   assertEquals("1Clubs", g.cols.get(0).get(0).toString());
   assertEquals("2Clubs", g.cols.get(1).get(0).toString());
   assertEquals("3Clubs", g.cols.get(2).get(0).toString());
   assertEquals("4Clubs", g.cols.get(3).get(0).toString());
 }
  /** Test de l'effet pour ue partie normal */
  @Test
  public void testPlayEffect() {
    // On pré-remplit le plateau pour les besoins de la simulation
    Utils.simulateAGame(aGame);

    aGame
        .getBoard()
        .getTileIJ(aGame.getBoard().getHeight() - 3, 0)
        .setEffect(new DeleteColumnEffect());

    // Récupération de l'ID du joueur avant que le coup soit joué
    int id_player = aGame.getCurrentPlayer().getId();

    // Récupération du nombre de pions présents
    int nb_tokens_before = aGame.getBoard().getTotalTilesCount();

    // Coup joué sur une case contenant l'effet
    aGame.playMove(0);

    // Récupération du nombre de pions après le coup
    int nb_tokens_after = aGame.getBoard().getTotalTilesCount();

    // Vérifications :
    // - l'effet est bien appliqué sur la case
    // - le tour de jeu a bien changé
    // - il y a bien moins de pion sur le plateau
    assertTrue(
        "Doit être d'effet delete column",
        aGame.getBoard().getTileIJ(aGame.getBoard().getHeight() - 3, 0).getEffect()
            instanceof DeleteColumnEffect);
    assertTrue(aGame.getCurrentPlayer().getId() != id_player);
    System.out.println(nb_tokens_before);
    System.out.println(nb_tokens_after);
    assertTrue(nb_tokens_after < nb_tokens_before);
  }
Exemple #14
0
 @Test
 public void testRemoveFunction() {
   Game g = new Game();
   g.buildDeck();
   g.customDeal(0, 3, 6, 9);
   g.remove(2);
   assertEquals(0, g.cols.get(2).size());
   // make sure that we did not remove from an empty column
   g.remove(2);
   assertEquals(0, g.cols.get(2).size());
 }
 @Test
 public void testSpGameStart() {
   Game g = new spGame();
   g.buildDeck();
   g.shuffle();
   g.dealFour();
   assertEquals(1, g.cols.get(0).size());
   assertEquals(1, g.cols.get(1).size());
   assertEquals(1, g.cols.get(2).size());
   assertEquals(1, g.cols.get(3).size());
 }
Exemple #16
0
  @Test
  public void oneSpareGame() {
    game.roll(5);
    game.roll(5);
    game.roll(3);

    for (int frameIndex = 0; frameIndex < 17; frameIndex++) {
      game.roll(0);
    }

    assertEquals(16, game.getScore());
  }
Exemple #17
0
  @Test
  public void oneStrikeGame() {
    game.roll(10);
    game.roll(3);
    game.roll(4);

    for (int frameIndex = 0; frameIndex < 16; frameIndex++) {
      game.roll(0);
    }

    assertEquals(24, game.getScore());
  }
Exemple #18
0
 @Test
 public void testPointBuild2() {
   b = g.getMyBoard();
   try {
     /* black on 14 & 12 heading for 0; white on 4 (has long way to go)*/
     b.makePointBuild2Board();
     assertNotNull(b);
   } catch (Exception e) {
     /* isn't there a way to test without catching excetions? */
     fail(e.toString());
   }
   g.setCurrentPlayer(aiColor);
   g.myAI.setHowManyTurnsSoFar(4); // so AI uses pointBuilderStrategy
   b.myDice.roll(4, 3);
 }
 @BeforeClass
 public static void setUpClass() {
   // Création d'un jeu vide
   aGame = new Game();
   Board b = new Board(10, 10);
   aGame.setBoard(b);
 }
 private void playGameWrapException(Game game) {
   try {
     game.play();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
  @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);
  }
Exemple #22
0
 @Test
 public final void testEasyVsHard() {
   for (int i = 0; i < 10; i++) {
     try {
       setUp();
       Player aiPlayer1 = TestAccessor.Game.getPlayer1(game);
       AI ai1 = new AI(aiPlayer1, game, false);
       while (game.getWinner() == null) {
         Player currPlayer = TestAccessor.Game.getCurrentPlayer(game);
         if (currPlayer == aiPlayer) ai.doNextMove();
         else ai1.doNextMove();
       }
       //        System.out.println("Winner: " + game.getWinner().name);
     } catch (IllegalMoveException e) {
       e.printStackTrace();
       fail();
     } catch (Exception e) {
       e.printStackTrace();
       fail();
     }
   }
 }
  /**
   * Test de DisappearEffect sur grille vide Vérification de l'état de la tuile après application de
   * l'effet Résultats attendus : la case doit être vide, le tour de jeu doit être passé
   */
  @Test
  public void testDeleteColumnEffectEmptyGame() {

    // Effet fixé sur une case
    int height = aGame.getBoard().getHeight();
    aGame.getBoard().getTileIJ(height - 1, 0).setEffect(new DeleteColumnEffect());

    // Récupération de l'ID du joueur courant
    int id_player = aGame.getCurrentPlayer().getId();

    // Coup joué sur la case de l'effet
    aGame.playMove(0);

    // Vérifications :
    // - la case est bien vide après
    // - le tour de jeu a bien changé
    assertEquals(-1, aGame.getBoard().getTileIJ(height - 1, 0).getStatus());
    assertTrue(aGame.getCurrentPlayer().getId() != id_player);
  }
Exemple #24
0
 @Test
 public void testGameBuildDeck() {
   Game g = new Game();
   g.buildDeck();
   assertEquals(52, g.deck.size());
 }
Exemple #25
0
 @Test
 public void testPerfectGame() throws Exception {
   rollMany(12, 10);
   assertEquals(300, g.score());
 }
  @Test
  public void testHandCompare() {
    Hand royalFlushHand1 = new Hand("1 TenHearts JackHearts QueenHearts KingHearts AceHearts");
    Hand royalFlushHand2 = new Hand("1 TenSpades JackSpades QueenSpades KingSpades AceSpades");

    Hand straightFlushHand1 = new Hand("1 ThreeClubs FourClubs FiveClubs SixClubs SevenClubs");
    Hand straightFlushHand2 =
        new Hand("1 ThreeDiamonds FourDiamonds FiveDiamonds SixDiamonds SevenDiamonds");

    Hand fourOfAKindHand1 = new Hand("3 TwoClubs TwoHearts TwoSpades TwoDiamonds FiveClubs");
    Hand fourOfAKindHand2 = new Hand("3 TwoClubs JackDiamonds TwoSpades TwoDiamonds TwoHearts");

    Hand fullHouseHand1 = new Hand("2 AceHearts AceClubs AceSpades KingDiamonds KingHearts");
    Hand fullHouseHand2 = new Hand("2 AceHearts AceClubs KingSpades KingDiamonds KingHearts");

    Hand flushHand1 = new Hand("1 AceClubs TenClubs FiveClubs ThreeClubs NineClubs");
    Hand flushHand2 = new Hand("1 AceClubs TenClubs FourClubs ThreeClubs NineClubs");

    Hand straightHand1 = new Hand("1 TwoClubs ThreeClubs FourSpades FiveClubs SixDiamonds");
    Hand straightHand2 = new Hand("1 SevenClubs ThreeClubs FourSpades FiveHearts SixDiamonds");

    Hand threeOfAKindHand1 = new Hand("4 TwoSpades TwoClubs KingHearts TwoHearts QueenDiamonds");
    Hand threeOfAKindHand2 = new Hand("4 TwoSpades TwoClubs AceHearts TwoHearts QueenDiamonds");

    Hand twoPairHand1 = new Hand("2 AceClubs KingDiamonds AceHearts KingSpades ThreeDiamonds");
    Hand twoPairHand2 = new Hand("2 AceClubs KingDiamonds AceHearts KingSpades AceDiamonds");

    Hand onePairHand1 = new Hand("3 AceHearts AceDiamonds KingSpades FourClubs SixHearts");
    Hand onePairHand2 = new Hand("3 KingHearts AceClubs KingSpades FourClubs SixHearts");

    Hand highCardHand1 = new Hand("1 AceHearts KingClubs QueenDiamonds JackClubs NineClubs");
    Hand highCardHand2 = new Hand("1 AceClubs KingDiamonds QueenSpades JackClubs NineClubs");

    assertEquals(0, royalFlushHand2.compareTo(royalFlushHand1));
    assertEquals(0, straightFlushHand1.compareTo(straightFlushHand2));
    assertEquals(-1, fourOfAKindHand1.compareTo(fourOfAKindHand2));
    assertEquals(1, fullHouseHand1.compareTo(fullHouseHand2));
    assertEquals(1, flushHand1.compareTo(flushHand2));
    assertEquals(-1, straightHand1.compareTo(straightHand2));
    assertEquals(-1, threeOfAKindHand1.compareTo(threeOfAKindHand2));
    assertEquals(-1, twoPairHand1.compareTo(twoPairHand2));
    assertEquals(1, onePairHand1.compareTo(onePairHand2));
    assertEquals(0, highCardHand1.compareTo(highCardHand2));

    assertEquals(-1, highCardHand1.compareTo(onePairHand1));
    assertEquals(-1, onePairHand1.compareTo(twoPairHand1));
    assertEquals(-1, threeOfAKindHand1.compareTo(straightHand1));
    assertEquals(-1, straightHand1.compareTo(flushHand1));
    assertEquals(-1, flushHand1.compareTo(fullHouseHand1));
    assertEquals(-1, fullHouseHand1.compareTo(fourOfAKindHand1));
    assertEquals(-1, fourOfAKindHand1.compareTo(straightFlushHand1));
    assertEquals(-1, straightFlushHand1.compareTo(royalFlushHand1));

    assertEquals(1, royalFlushHand1.compareTo(flushHand1));
    assertEquals(1, threeOfAKindHand1.compareTo(onePairHand1));

    List<Card> deck = makeDeck();
    int n = 2;

    String input = n + "\n";

    List<Hand> hands = new ArrayList<Hand>();
    String handString = "";
    String tmp = "";
    for (int i = 1; i <= n; i++) {
      input += i;
      handString = "";
      handString += i;
      for (int j = 0; j < 5; j++) {
        tmp = deck.remove(0).toString();
        input += " " + tmp;
        handString += " " + tmp;
      }
      input += "\n";
      hands.add(new Hand(handString));
    }

    // get sorted order

    List<Card> sortedCards;
    Card tmpCard;

    for (int g = 0; g < n; g++) {
      sortedCards = new ArrayList<Card>();

      for (Card c : hands.get(g).getCards()) sortedCards.add(c);

      for (int i = 0; i < 4; i++) {
        for (int j = i + 1; j < 5; j++) {
          if (sortedCards.get(i).getRank().rank > sortedCards.get(j).getRank().rank) {
            tmpCard = sortedCards.get(i);
            sortedCards.set(i, sortedCards.get(j));
            sortedCards.set(j, tmpCard);
          }
        }
      }
      hands.get(g).setCards(sortedCards);
    }

    InputStream stream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));

    System.out.println(n);
    for (int i = 0; i < n; i++) {
      System.out.println(
          hands.get(i).toString() + ", rank: " + hands.get(i).getHandRanking().name());
    }

    Game game = new Game(stream);
    game.play();
  }
Exemple #27
0
 private void rollStrike() {
   g.roll(10);
 }
  /** 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);
  }
  /**
   * Tests that the game starts and stops properly given the number of rounds requested and money
   * available
   */
  @Test
  public void testNumRounds() {
    // test number of rounds played (1 round)
    PlayingStrategy playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, false);
    Game game = new Game(playingStrategy, 1, MONEY_10);
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 1);
    assertEquals(game.getNumRoundsToPlay(), 1);
    assertEquals(game.getPastRounds().size(), 1);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    Round round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);

    // test number of rounds played (5 rounds)
    playingStrategy = new PlayingStrategyFixed(Round.Offer.STAND, MONEY_1, false);
    game = new Game(playingStrategy, 5, MONEY_10);
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 5);
    assertEquals(game.getNumRoundsToPlay(), 5);
    assertEquals(game.getPastRounds().size(), 5);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);

    // test number of rounds played (money runs out)
    playingStrategy = new PlayingStrategyFixed(Round.Offer.HIT, MONEY_1, false);
    game = new Game(playingStrategy, 20, MONEY_10);
    game.setDeck(
        new MockDeckFixed(
            Rank.TEN)); // by getting only 10s and hitting each time will definitely lose
    playGameWrapException(game);
    assertEquals(game.getNumRoundsPlayed(), 10);
    assertEquals(game.getNumRoundsToPlay(), 20);
    assertEquals(game.getPastRounds().size(), 10);
    assertEquals(game.isUserInputNeeded(), false);
    assertEquals(game.isFinished(), true);
    assertNull(game.getCurrentRound());
    round = game.getLastRound();
    assertEquals(round.getRoundStatus(), Round.RoundStatus.ROUND_FINISHED);
    assertNull(round.getCurrentHand());
    assertEquals(round.getHands().size(), 1);
  }
Exemple #30
0
 private void rollSpare() {
   g.roll(5);
   g.roll(5);
 }