Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEmacs
package game.poker;
import java.util.Collections;
import java.util.Random;
import java.util.Stack;

import game.poker.Card.Suit;

public class Deck
{

    private Stack<Card> cards;
    private Random rand;

    public Deck()
    {
        rand = new Random();
        init();
    }

    public Deck(Random givenGenerator)
    {
        rand = givenGenerator;
        init();
    }

    public Card pop()
    {
        return cards.pop();
    }

    /**
     * Initializes a new deck of 52 cards.
     */
    private void init()
    {
        cards = new Stack<>();
        int index = 0;
        for (int rank = 1; rank <= 13; ++rank)
        {
            cards.push(new Card(rank, Suit.CLUBS));
            cards.push(new Card(rank, Suit.DIAMONDS));
            cards.push(new Card(rank, Suit.HEARTS));
            cards.push(new Card(rank, Suit.SPADES));
        }

        // Todo : Improve Shuffle Rule...
        Collections.shuffle(cards);
    }
}
  • init : 덱을 초기화할때 초기화후 자동으로 썩어준다. /

  • shuffle : 카드를 썩어주는 기능을 한다. 난수발생기를 고오급화하여 적용할수도 있다. 서비스에 실 사용시 난수검증은 중요한 사항이다.

...