コード例 #1
0
ファイル: AdvisorTest.java プロジェクト: JacobLeach/charlie
  @Test
  public void fuzzTest() {
    Hand hand = null;
    Card upCard = null;

    try {
      for (int i = 0; i < RUN_NUMBER; i++) {
        hand = new Hand(new Hid(Seat.YOU));
        hand.hit(RandomCardGenerator.getRandomCard());
        hand.hit(RandomCardGenerator.getRandomCard());
        upCard = RandomCardGenerator.getRandomCard();
        advisor.advise(hand, upCard);

        hand.hit(RandomCardGenerator.getRandomCard());
        while (hand.getValue() < 21) {
          advisor.advise(hand, upCard);
          hand.hit(RandomCardGenerator.getRandomCard());
        }

        System.out.println("Hand: " + hand);
        System.out.println("Up Card: " + upCard);
      }

    } catch (Exception e) {
      System.out.println("Hand: " + hand);
      System.out.println("Up Card: " + upCard);
      fail("The method threw an exception: \n" + e);
    }

    assertTrue(true);
  }
コード例 #2
0
 // TODO add test methods here.
 // The methods must be annotated with annotation @Test. For example:
 //
 @Test
 public void test1() {
   BasicStrategy bs = new BasicStrategy();
   Hid hid = new Hid(Seat.YOU, 125.0, 25.0);
   Hand newHand = new Hand(hid);
   Card card1 = new Card(5, Card.Suit.DIAMONDS);
   Card card2 = new Card(5, Card.Suit.CLUBS);
   newHand.hit(card1);
   newHand.hit(card2);
   Card card3 = new Card(9, Card.Suit.SPADES);
   assertEquals(Play.DOUBLE_DOWN, bs.advise(newHand, card3));
 }
コード例 #3
0
  @Test
  public void Test00_Hand_12_Up_2() {
    Hid hid = new Hid(Seat.YOU, 1.0, 1.5);
    Hand hand = new Hand(hid);

    // Hand total = 18
    hand.hit(new Card(10, Card.Suit.HEARTS));
    hand.hit(new Card(8, Card.Suit.HEARTS));

    // Up card = 5
    Play result = advisor.advise(hand, new Card(13, Card.Suit.HEARTS));
    Play expectedPlay = Play.STAY;

    assertEquals(expectedPlay, result);
  }
コード例 #4
0
  @Test
  public void Test00_Hand_22_Up_7() {
    Hid hid = new Hid(Seat.YOU, 1.0, 1.5);
    Hand hand = new Hand(hid);

    // Hand comp = 7, 7
    hand.hit(new Card(7, Card.Suit.HEARTS));
    hand.hit(new Card(7, Card.Suit.SPADES));

    // Up card = A
    Play result = advisor.advise(hand, new Card(1, Card.Suit.HEARTS));
    Play expectedPlay = Play.HIT;

    assertEquals(expectedPlay, result);
  }
コード例 #5
0
  @Override
  protected String getText() {
    //        int value = values[Constant.HAND_SOFT_VALUE] <= 21 ?
    //                values[Constant.HAND_SOFT_VALUE] :
    //                values[Constant.HAND_LITERAL_VALUE];
    int value = Hand.getValue(values);

    String text = name + ": " + value;

    //        if(value != 0) {
    //            if(cards.size() == 2 && value == 21)
    //                text += ": Blackjack !";
    //            else
    //                text += ": "+value;
    //        }

    return text;
  }
コード例 #6
0
  /**
   * Renders the hand state (i.e., the value and its outcomeText in case of Blackjack).
   *
   * @param g Graphics context
   * @param text Message
   */
  @Override
  protected void renderState(Graphics2D g, String text) {
    if (cards.isEmpty()) return;

    FontMetrics fm = g.getFontMetrics(outcomeFont);

    int textWidth = fm.charsWidth(text.toCharArray(), 0, text.length());

    int x = cards.get(0).getX() + getPileWidth() / 2 - textWidth / 2;
    int y = ACard.getCardHeight() + fm.getHeight();

    g.setColor(stateColor);
    g.setFont(stateFont);

    g.drawString(text, x, y);

    int value = Hand.getValue(values);
    if (cards.isEmpty() || value < 21) return;

    String outcomeText = "";
    if (isBlackjack()) outcomeText += " BLACKJACK ! ";
    else if (isBroke()) outcomeText += " BUST ! ";

    int sz = cards.size();

    ACard lastCard = cards.get(sz - 1);
    x = cards.get(0).getX() + getPileWidth() - 15;
    y = lastCard.getY() + ACard.getCardHeight() / 2;

    int w = fm.charsWidth(outcomeText.toCharArray(), 0, outcomeText.length());
    int h = fm.getHeight();

    if (isBlackjack()) g.setColor(bjBgColor);
    else if (isBroke()) g.setColor(bustBgColor);

    g.fillRoundRect(x, y - h + 5, w, h, 5, 5);

    if (isBlackjack()) g.setColor(bjFgColor);
    else if (isBroke()) g.setColor(bustFgColor);

    g.setFont(outcomeFont);
    g.drawString(outcomeText, x, y);
  }
コード例 #7
0
 protected boolean isBlackjack() {
   return Hand.getValue(values) == 21 && cards.size() == 2;
 }