poker - How can I make my PokerHand class randomly deal a thousand hands? -
public class pokerhand { // arraylist cards private arraylist<card> cards; /** * constructor class pokerhand */ public pokerhand() { cards = new arraylist<card>(); // arraylist of cards } /** * add cards list */ public void addcard(card card1, card card2, card card3) { cards.add(card1); cards.add(card2); cards.add(card3); } }
this card class
public class card() { private int value; private int suit; private static string[] suits = { "hearts", "spades", "diamonds", "clubs" }; private static string[] values = { "ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "king" }; public static string valueasstring( int value ) { return values[value]; } card(int suit, int rank) { this.value=value; this.suit=suit; } public string tostring() { return values[value] + " of " + suits[suit]; } public int getvalue() { return value; } public int getsuit() { return suit; } }
how can deal 1000 3 card hands? stuck on how variety of things, including additional methods need. how can construct deal method , how can make deal method dish out thousand random hands while shuffling every time hand dealt?
all of these implementations based on code my card library.
shuffle
public card[] shuffle(card[] deck) { random gen = new random(); boolean[] added = new boolean[deck.length]; int positiontoadd = gen.nextint(deck.length); card[] newdeck = new card[deck.length]; (int = 0; < deck.length; i++) { while (newdeck[i] == null) { if (!added[positiontoadd]) { newdeck[i] = deck[positiontoadd]; positiontoadd = gen.nextint(deck.length); added[i] = true; } else { positiontoadd = gen.nextint(deck.length); } } } return newdeck; }
implementation
arraylist<card> dealfrom = new arraylist<card>(); pokerhand[] hands = new pokerhand[1000]; /*populate "dealfrom" here*/ dealfrom = array.aslist(shuffle(dealfrom.toarray())); (int = 0; < 3000; += 3) { //write deal method here hands[i] = new pokerhand(dealfrom[i], dealfrom[i + 1], dealfrom[i + 2]); }
hope helps.
Comments
Post a Comment