Example #1
0
 /**
  * Method that compares if two cards are identical
  *
  * @param card1 First card being compared
  * @param card2 Second card being compared
  * @return Returns whether the two cards are identical (true/false)
  */
 @Override
 public boolean equals(Card card1, Card card2) {
   if (card1.toString().equals(card2.toString())) {
     return true;
   } else {
     return false;
   }
 }
Example #2
0
 /** Returns a string representation of the hand */
 public String toString() {
   String str = "[";
   str += card1.toString();
   str += ",";
   str += card2.toString();
   str += "]";
   return str;
 }
Example #3
0
 public static void main(String[] args) {
   Card card1 = new Card("spade", 7);
   Card card2 = new Card("heart", 2);
   System.out.println(card1.toString());
   System.out.println(card2.toString());
   /*
    * java.lang.Object의 toString 은 해시코드(객체 주소값)을
    * 리턴하므로, toString을 오버라이딩해서
    * 원하는 결과를 얻도록 한다.
    */
 }
 private double calculatePotentialVAndT(
     int roundedTime,
     int needRounds,
     Hand currentHand,
     int[][] rankings,
     HashMap<String, Boolean> exsiting,
     int[] types) {
   if (roundedTime < needRounds) {
     double value = 0;
     for (int i = 0; i < Card.NO_OF_RANKS; ++i) {
       for (int j = 0; j < Card.NO_OF_SUITS; ++j) {
         if (rankings[i][j] == 0) {
           Card newCard = new Card(i, j);
           Hand newHand = new Hand(currentHand.toString() + ' ' + newCard.toString());
           rankings[i][j] = 1;
           //                        System.out.println(newHand.toString());
           value +=
               calculatePotentialVAndT(
                   roundedTime + 1, needRounds, newHand, rankings, exsiting, types);
           rankings[i][j] = 0;
         }
       }
     }
     return value;
   } else {
     if (exsiting.containsKey(currentHand.toString())) {
       return 0;
     }
     exsiting.put(currentHand.toString(), true);
     types[calculateHandType(currentHand)]++;
     return calculateHandValue(currentHand);
   }
 }
 public String toString() {
   StringBuilder ans = new StringBuilder();
   for (Card c : cardList) {
     ans.append(c.toString());
   }
   return ans.toString();
 }
 @Override
 public String toString() {
   String str = "=================================================\n";
   str += "Freecells: ";
   for (LinkedList<Card> freecell : freecells) {
     if (freecell.isEmpty()) str += " ";
     else str += freecell.getLast().toString() + " ";
   }
   str += "\t\tFoundations: ";
   for (LinkedList<Card> foundation : foundations) {
     if (foundation.isEmpty()) str += " ";
     else str += foundation.getLast().toString() + "(" + foundation.size() + ") ";
   }
   str += "\n\n";
   for (LinkedList<Card> cascade : cascades) {
     if (cascade.isEmpty()) str += "\n";
     else {
       for (Card c : cascade) {
         str += c.toString() + " ";
       }
       str += "\n";
     }
   }
   str += "\nF: " + f + "\tG: " + g + "\tH: " + h + "\n";
   str += "=================================================\n";
   return str;
 }
Example #7
0
 @Test
 public void should_output_card_suit_and_face_value() throws Exception {
   // given
   final Card cardA3 = card(A, 3);
   // when
   // then
   assertThat(cardA3.toString(), is("A3"));
 }
Example #8
0
 /*
  * print player's hand to screen
  */
 static void showHand(Player player, String msg) {
   int i = 0;
   System.out.print(msg);
   for (Card card : player.getHand().getHighestToLowestRankCards(true)) {
     System.out.print(String.valueOf(++i) + ") " + card.toString() + "   ");
   }
   System.out.println();
 }
Example #9
0
 /**
  * this method returns a card from a players hand using a String name of the card
  *
  * @param cardName takes in a name of a card as a String
  * @return a card the matches the cardName
  */
 public Card getCardByName(String cardName) {
   for (Card card : playerCards) {
     if (card.toString().equals(cardName)) {
       return card;
     }
   }
   return null;
 }
Example #10
0
 private String topFiveCards() {
   String ranks = "";
   int num = 0;
   while (num < 5 && num < stackPot.size()) {
     ranks += Card.toString(stackPot.get(num)) + ", ";
     num++;
   }
   return ranks;
 }
Example #11
0
 public int getScore() {
   int score = 0;
   for (Card card : cards) {
     score += Integer.parseInt(card.toString().split("_")[1]);
   }
   String str = score + "";
   String x = str.substring(str.length() - 1);
   return Integer.parseInt(x);
 }
Example #12
0
 // return a String representation of a list of Cards
 public static String cardsToString(List<Card> cards, String delimiter) {
   StringBuilder sb = new StringBuilder();
   String prefix = "";
   for (Card card : cards) {
     sb.append(prefix);
     sb.append(card.toString());
     prefix = delimiter;
   }
   return sb.toString();
 }
Example #13
0
 public void tryFlip(int player) {
   if (player == playerTurn && !isFacecardPickup()) {
     // flipping
     GamePanel.playNoiseFlip();
     stackPot.addToTop(playerCards.get(player).removeTopCard());
     log.finer(getPlayerName(player) + " flipped the " + Card.toString(stackPot.getTopCard()));
     if (Card.isFaceCard(stackPot.getTopCard())) {
       topFacecardOwner = player;
       topFacecardMaxSize = Card.getRank(stackPot.getTopCard());
       switch (topFacecardMaxSize) {
         case Card.ACE:
           topFacecardMaxSize = stackPot.size() + 4;
           break;
         case Card.KING:
           topFacecardMaxSize = stackPot.size() + 3;
           break;
         case Card.QUEEN:
           topFacecardMaxSize = stackPot.size() + 2;
           break;
         case Card.JACK:
           topFacecardMaxSize = stackPot.size() + 1;
           break;
         default:
           throw new RuntimeException(
               "This should never happen. A face card was not an ace, king, queen, or jack.");
       }
       turnIncrement();
     } else if (topFacecardOwner == -1) {
       // if no facecards have been played this hand
       turnIncrement();
     }
     if (playerCards.get(player).isEmpty()) {
       log.fine(getPlayerName(player) + " is eliminated because they flipped their last card");
       eliminatePlayer(player);
     }
     if (isSlap()) {
       AI.registerEvent(AI.TYPESLAP);
     } else {
       AI.registerEvent(AI.TYPEFLIP);
     }
   } else {
     // flipping out of turn
     if (playerCards.get(player).isEmpty()) {
       // flipping out of turn but have no cards
       log.finer(
           getPlayerName(player) + " tried to flip a card even though they have no cards...");
     } else {
       // flipping out of turn so burning
       log.fine(getPlayerName(player) + " tried to flip a card illegally and had to burn a card");
       burn(player);
     }
   }
 }
  public int genCard(
      int num1er,
      int num2er,
      int num3er,
      int num4er,
      int num5er,
      int num6er,
      int shootAbility,
      int cardCost1) {
    int cardCount = 0;
    int numOfActions = 0;
    ArrayList<Action> listOfActions;
    // Fighting Values
    for (int attackValue = 0; attackValue < 5; attackValue++) { // ATK€0-4
      for (int defenseValue = 1; defenseValue < 6; defenseValue++) { // DEF1-4
        for (int shootX = 0; shootX < 5; shootX++) {
          if (shootAbility == 0 && shootX > 0) continue;
          listOfActions = new ArrayList<>();
          for (int i = 0; i < num1er; i++) {
            listOfActions.add(actionsPool.get(1));
          }
          for (int i = 0; i < num2er; i++) {
            listOfActions.add(actionsPool.get(2));
          }
          for (int i = 0; i < num3er; i++) {
            listOfActions.add(actionsPool.get(3));
          }
          for (int i = 0; i < num4er; i++) {
            listOfActions.add(actionsPool.get(4));
          }
          for (int i = 0; i < num5er; i++) {
            listOfActions.add(actionsPool.get(5));
          }
          for (int i = 0; i < num6er; i++) {
            listOfActions.add(actionsPool.get(6));
          }
          for (int s = 0; s < shootAbility; s++) {
            listOfActions.add(new Action(diceForShootAction, shootX, attackValue));
          }
          Card test = new Card(attackValue, defenseValue, listOfActions);

          // numOfActions = num1er + num2er + num3er + num4er + num5er + num6er;
          if (test.balanceWert() == cardCost1) {
            if (true) System.out.println(test.toString());
            cardCount++;
          }
        }
      }
    }

    return cardCount;
  }
Example #15
0
  @Override
  public String toString() {
    String cards = "";
    if (isEmpty()) {
      return "Empty";
    }

    for (Card card : deck) {
      cards += card.toString() + "\n";
    }

    return cards;
  }
Example #16
0
 @Test
 public void testCard() {
   // if card was created (is not null)
   assertNotNull(card);
   // if card was created with proper rank
   assertEquals(rank3, card.getRank());
   // if cards suit is different than another suit
   assertNotEquals(suitD, card.getSuit());
   // if after change suits match
   card.setSuit(suitD);
   assertEquals(suitD, card.getSuit());
   // if card's String representation is as expected
   assertEquals("3♦", card.toString());
 }
  private int generateCards(int cardsCost, boolean print) {
    int numOfActions = 0;
    int cardCount = 0;
    ArrayList<Action> listOfActions;
    for (int attackValue = 0; attackValue < 5; attackValue++) { // ATK€0-4
      for (int defenseValue = 1; defenseValue < 6; defenseValue++) { // DEF€1-4
        for (int ac1 = 0; ac1 < actionCount1er + 1; ac1++) {
          for (int ac2 = 0; ac2 < actionCount2er + 1; ac2++) {
            for (int ac3 = 0; ac3 < actionCount3er + 1; ac3++) {
              for (int ac4 = 0; ac4 < actionCount4er + 1; ac4++) {
                for (int ac5 = 0; ac5 < actionCount5er + 1; ac5++) {
                  for (int ac6 = 0; ac6 < actionCount6er + 1; ac6++) {
                    for (int shootActionCount = 0;
                        shootActionCount < 2;
                        shootActionCount++) { // 1ShootAction
                      for (int shootX = 0; shootX < 5; shootX++) {
                        if (shootActionCount == 0 && shootX > 0) continue;
                        // FILL_In_Actions
                        listOfActions = new ArrayList<>();
                        for (int i = 0; i < ac1; i++) listOfActions.add(actionsPool.get(1));
                        for (int i = 0; i < ac2; i++) listOfActions.add(actionsPool.get(2));
                        for (int i = 0; i < ac3; i++) listOfActions.add(actionsPool.get(3));
                        for (int i = 0; i < ac4; i++) listOfActions.add(actionsPool.get(4));
                        for (int i = 0; i < ac5; i++) listOfActions.add(actionsPool.get(5));
                        for (int i = 0; i < ac6; i++) listOfActions.add(actionsPool.get(6));
                        for (int s = 0; s < shootActionCount; s++)
                          listOfActions.add(new Action(diceForShootAction, shootX, attackValue));
                        Card test = new Card(attackValue, defenseValue, listOfActions);

                        // numOfActions = ac1 + ac2 + ac3 + ac4 + ac5 + ac6;
                        if (test.balanceWert() == cardsCost) {
                          if (print) System.out.println(test.toString());
                          cardCount++;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    return cardCount;
  }
Example #18
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // layout = new RelativeLayout(this);
    layout = (RelativeLayout) this.findViewById(R.id.mainLayout);
    layout.setBackgroundColor(Color.rgb(16, 142, 58));

    setContentView(layout);

    SinglePlayer game = new SinglePlayer(1, 3, "Dave");
    int numCards = game.gameLogic.players.get(0).getNumCards();
    int midScreen = getWindowManager().getDefaultDisplay().getWidth() / 2;
    leftOffset = midScreen - (numCards / 2 + 1) * 25;
    minBottomMargin = 75;

    cardImgs = new ArrayList<ImageView>();
    List<Card> cards = game.gameLogic.players.get(0).getHand();
    for (Card c : cards) drawCardToScreen(c.toString().toLowerCase());

    setMarginsOnBtns(midScreen);
  }
Example #19
0
 public String toString() {
   String a = "";
   for (Card b : cards) a += b.toString() + "\n";
   return a;
 }
Example #20
0
 public boolean isEqual(Card c) {
   return c.toString().equals(toString());
 }
Example #21
0
  /**
   * Main class that test the functionality of methods in Card and BinSet class.
   *
   * @param args
   */
  public static void main(java.lang.String[] args) {

    Card one = new Card(Ranks.FIVE, "SPADES");
    Card two = new Card(Ranks.NINE, "HEARTS");
    Card three = new Card(Ranks.KING, "DIAMONDS");
    Card four = new Card(Ranks.ACE, "DIAMONDS");
    Card five = new Card(Ranks.ACE, "CLUBS");
    Card six = new Card(Ranks.FIVE, "SPADES");

    System.out.println("Five of Spades equals Nine of Hearts:");
    System.out.println(one.equals(two));
    System.out.println();
    System.out.println("Five of Spades equals King of Diamonds:");
    System.out.println(one.equals(three));
    System.out.println();
    System.out.println("Five of Spades equals Ace of Diamonds:");
    System.out.println(one.equals(four));
    System.out.println();
    System.out.println("Five of Spades equals Ace of Clubs:");
    System.out.println(one.equals(five));
    System.out.println();
    System.out.println("Five of Spades equals Five of Spades:");
    System.out.println(one.equals(six));
    System.out.println();

    System.out.println("___________________________________________________");
    System.out.println("Value is greater than 0 when 1 is compared to 2.");
    System.out.println(one.compareTo(two));
    System.out.println();
    System.out.println("Value is greater than 0 when 1 is compared to 3.");
    System.out.println(one.compareTo(three));
    System.out.println();
    System.out.println("Value is greater than 0 when 1 is compared to 4.");
    System.out.println(one.compareTo(four));
    System.out.println();
    System.out.println("Value is greater than 0 when 1 is compared to 5.");
    System.out.println(one.compareTo(five));
    System.out.println();
    System.out.println("Value is equal to 0 when 1 is compared to 6.");
    System.out.println(one.compareTo(six));
    System.out.println();

    System.out.println("___________________________________________________");
    System.out.println("Card1 as a String:");
    System.out.println(one.toString());
    System.out.println();
    System.out.println("Card2 as a String:");
    System.out.println(two.toString());
    System.out.println();
    System.out.println("Card3 as a String:");
    System.out.println(three.toString());
    System.out.println();
    System.out.println("Card4 as a String:");
    System.out.println(four.toString());
    System.out.println();
    System.out.println("Card5 as a String:");
    System.out.println(five.toString());
    System.out.println();
    System.out.println("Card6 as a String:");
    System.out.println(six.toString());
    System.out.println();
    System.out.println("___________________________________________________");

    System.out.println("Create List1.");
    BinSet<String> List1 = new BinSet<String>();

    System.out.println();
    System.out.println("Add A to List1:");
    System.out.println(List1.add("A"));
    System.out.println();
    System.out.println("Add B to List1:");
    System.out.println(List1.add("B"));
    System.out.println();
    System.out.println("Add A to List1:");
    System.out.println(List1.add("A"));
    System.out.println();
    System.out.println("Print out List1:");
    System.out.println(List1.toString());
    System.out.println();
    System.out.println("___________________________________________________");

    System.out.println("Create List2.");
    Collection<String> List2 = new ArrayList<String>();

    System.out.println();
    System.out.println("Add C to List2:");
    List2.add("C");
    System.out.println("Add D to List2:");
    List2.add("D");
    System.out.println("Add E to List2:");
    List2.add("E");
    System.out.println();
    System.out.println("Are we able to add List2 to List1?");
    System.out.println(List1.addAll(List2));
    System.out.println();

    System.out.println("Clear List2.");
    List2.clear();
    System.out.println();

    System.out.println("Add A to List2.");
    List2.add("A");
    System.out.println("Add C to List2.");
    List2.add("C");
    System.out.println("Add D to List2.");
    List2.add("D");
    System.out.println("Add E to List2.");
    List2.add("E");
    System.out.println();

    System.out.println("Can I add List2 to List1?");
    System.out.println(List1.addAll(List2));
    System.out.println();

    System.out.println("Display List1:");
    System.out.println(List1.toString());
    System.out.println();

    System.out.println("Is List2 Empty?");
    System.out.println(List2.isEmpty());
    System.out.println();

    System.out.println("Clear List2.");
    List2.clear();
    System.out.println();

    System.out.println("Is List2 Empty?");
    System.out.println(List2.isEmpty());
    System.out.println();

    System.out.println("Can I add List1 to List2?");
    System.out.println(List2.addAll(List1));
    System.out.println();
    System.out.println("Does List1 Contain all of List2?");
    System.out.println(List1.containsAll(List2));
    System.out.println();
    System.out.println("Does List2 Contain Z?");
    System.out.println(List2.contains("Z"));
    System.out.println();

    System.out.println("Does List2 Contain A?");
    System.out.println(List2.contains("A"));
    System.out.println();

    System.out.println("Can I remove Z from List2?");
    System.out.println(List2.remove("Z"));
    System.out.println();
    System.out.println("Can I remove A from List2?");
    System.out.println(List2.remove("A"));
    System.out.println();
    System.out.println("Display List2:");
    System.out.println(List2.toString());
    System.out.println();

    System.out.println("Display List1:");
    System.out.println(List1.toString());
    System.out.println();

    Object[] array = List1.toArray();
    System.out.println("Display the array created from List1:");
    System.out.println(Arrays.toString(array));
    System.out.println();
  }
Example #22
0
 @Test
 public final void testToString() {
   String expected = "Ace of CLUBS";
   Assert.assertEquals(expected, AC.toString());
 }
Example #23
0
 public void testToStringCardArray() {
   final Card[] notSuited = {Card.aceLowOfClubs, Card.dueceOfDiamonds};
   assertEquals("ac, 2d", Card.toString(notSuited));
 }
 public String toString() {
   String s = "Cards on the table:\n";
   for (Card c : this.tableCards) s += c.toString() + "\t";
   return s;
 }
Example #25
0
 public static void main(String[] args) {
   Card c = new Card(Suit.C, Value.ACE);
   System.out.println(c.toString());
 }
Example #26
0
 @Override
 public String toString() {
   return card.toString();
 }
Example #27
0
 public void testToString() {
   final Card card = Card.aceLowOfClubs;
   assertEquals("Ace(low) of Clubs", card.toString());
   final Card card2 = Card.aceOfClubs;
   assertEquals("Ace of Clubs", card2.toString());
 }