|
@@ -0,0 +1,206 @@
|
|
|
|
+package com.company;
|
|
|
|
+
|
|
|
|
+import java.util.Random;
|
|
|
|
+
|
|
|
|
+public class Dealler {
|
|
|
|
+ private final Player []players;
|
|
|
|
+ private final Deck deck = new Deck();
|
|
|
|
+ private final Card [] table = new Card[5];
|
|
|
|
+ private int CardOnDesk = 0;
|
|
|
|
+ private RATE_TYPE currentRateType;
|
|
|
|
+ Random random = new Random(System.currentTimeMillis());
|
|
|
|
+
|
|
|
|
+ public Dealler(int playerCount) throws Exception {
|
|
|
|
+ if (playerCount < 2 || playerCount > 9) {
|
|
|
|
+ throw new Exception("Некорректное количество игроков!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ players = new Player[playerCount];
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < playerCount; i++) {
|
|
|
|
+ players[i] = new Player();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ currentRateType = RATE_TYPE.PREFLOP;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void HandOut() {
|
|
|
|
+ boolean isFirstCardOnHand = false;
|
|
|
|
+ switch (currentRateType) {
|
|
|
|
+ case PREFLOP: {
|
|
|
|
+ for (int i = 0; i < players.length; i++) {
|
|
|
|
+ int cardIndex = random.nextInt(52);
|
|
|
|
+ Card currentCard = deck.Cards[cardIndex];
|
|
|
|
+ if (!isFirstCardOnHand) {
|
|
|
|
+ if (currentCard.onHands) {
|
|
|
|
+ i--;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ currentCard.onHands = true;
|
|
|
|
+ players[i].setCards(PLAYER_CARD.FIRST, currentCard);
|
|
|
|
+ }
|
|
|
|
+ isFirstCardOnHand = true;
|
|
|
|
+ cardIndex = random.nextInt(52);
|
|
|
|
+ currentCard = deck.Cards[cardIndex];
|
|
|
|
+ if (currentCard.onHands) {
|
|
|
|
+ i--;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ currentCard.onHands = true;
|
|
|
|
+ players[i].setCards(PLAYER_CARD.SECOND, currentCard);
|
|
|
|
+ isFirstCardOnHand = false;
|
|
|
|
+ }
|
|
|
|
+ currentRateType = RATE_TYPE.FLOP;
|
|
|
|
+ } break;
|
|
|
|
+ case FLOP: {
|
|
|
|
+ PutOnDesk(3);
|
|
|
|
+ currentRateType = RATE_TYPE.TURN;
|
|
|
|
+ } break;
|
|
|
|
+ case TURN: {
|
|
|
|
+ PutOnDesk(1);
|
|
|
|
+ currentRateType = RATE_TYPE.RIVER;
|
|
|
|
+ } break;
|
|
|
|
+ case RIVER: {
|
|
|
|
+ PutOnDesk(1);
|
|
|
|
+ currentRateType = RATE_TYPE.OPENING;
|
|
|
|
+ } break;
|
|
|
|
+ case OPENING: {
|
|
|
|
+ OpeningCard();
|
|
|
|
+ CardOnDesk = 0;
|
|
|
|
+ currentRateType = RATE_TYPE.PREFLOP;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void PutOnDesk(int cardCount) {
|
|
|
|
+ for (int i = 0; i < cardCount; i++) {
|
|
|
|
+ int cardIndex = random.nextInt(52);
|
|
|
|
+ Card currentCard = deck.Cards[cardIndex];
|
|
|
|
+ if (currentCard.onHands) {
|
|
|
|
+ i--;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ table[CardOnDesk++] = currentCard;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+// ♦♣♥♠
|
|
|
|
+ public void OpeningCard() {
|
|
|
|
+ System.out.println("Карты на столе ");
|
|
|
|
+ for (Card card: table) {
|
|
|
|
+ System.out.print(
|
|
|
|
+ deck.CardName.get(card.getDenomination())
|
|
|
|
+ + Lear.SYMBOL[card.Lear.ordinal()] + " ");
|
|
|
|
+ }
|
|
|
|
+ System.out.println("\n\nКарты игроков");
|
|
|
|
+
|
|
|
|
+ for (Player player: players) {
|
|
|
|
+ Card []sharedCards = new Card[7];
|
|
|
|
+ int i = 0;
|
|
|
|
+ for (; i < table.length; i++) {
|
|
|
|
+ sharedCards[i] = table[i];
|
|
|
|
+ }
|
|
|
|
+ sharedCards[i++] = player.getCards(PLAYER_CARD.FIRST);
|
|
|
|
+ sharedCards[i] = player.getCards(PLAYER_CARD.SECOND);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Sorting(sharedCards);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < sharedCards.length; i++) {
|
|
|
|
+ System.out.print(
|
|
|
|
+ deck.CardName.get(sharedCards[i].getDenomination())
|
|
|
|
+ + Lear.SYMBOL[sharedCards[i].Lear.ordinal()] + " ");
|
|
|
|
+ }
|
|
|
|
+ System.out.println();
|
|
|
|
+
|
|
|
|
+// System.out.print(
|
|
|
|
+// deck.CardName.get(player.getCards(PLAYER_CARD.FIRST).getDenomination())
|
|
|
|
+// + Lear.SYMBOL[player.getCards(PLAYER_CARD.FIRST).Lear.ordinal()] + " "
|
|
|
|
+// );
|
|
|
|
+// System.out.println(
|
|
|
|
+// deck.CardName.get(player.getCards(PLAYER_CARD.SECOND).getDenomination())
|
|
|
|
+// + Lear.SYMBOL[player.getCards(PLAYER_CARD.SECOND).Lear.ordinal()] + " "
|
|
|
|
+// );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Сортировка массива карт по убыванию его номинала
|
|
|
|
+ * @param cards массив карт (7 штук)
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public void Sorting(Card[] cards) throws Exception {
|
|
|
|
+ if (cards.length != 7) {
|
|
|
|
+ throw new Exception("Что-то пошло не так");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < cards.length; i++) {
|
|
|
|
+ for (int j = 0; j < cards.length - 1; j++) {
|
|
|
|
+ if (cards[j].getDenomination() < cards[j + 1].getDenomination()) {
|
|
|
|
+ Card temp = cards[j];
|
|
|
|
+ cards[j] = cards[j + 1];
|
|
|
|
+ cards[j + 1] = temp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Проверяет есть ли в переданном массиве комбинация Стрит
|
|
|
|
+ * @param cards массив карт
|
|
|
|
+ * @return true, если есть
|
|
|
|
+ */
|
|
|
|
+ public boolean isStreet(Card []cards) {
|
|
|
|
+ if (cards.length != 7) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int counter = 0;
|
|
|
|
+ for (int i = 0; i < cards.length - 1; i++) {
|
|
|
|
+ if (counter == 5) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (cards[i].getDenomination() != cards[i + 1].getDenomination() + 1) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ counter++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean isFlash(Card []cards, int cardCount) {
|
|
|
|
+ Lear.NAME currentLear;
|
|
|
|
+ int learCount = 0;
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < cardCount; i++) {
|
|
|
|
+ currentLear = cards[i].Lear;
|
|
|
|
+
|
|
|
|
+ for (int j = 0; j < cardCount; j++) {
|
|
|
|
+ if (i == j) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (cards[j].Lear == currentLear) {
|
|
|
|
+ learCount++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return learCount >= 5;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean isRoyalFlash(Card []cards) {
|
|
|
|
+ if (cards[0].getDenomination() != 14) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return (isFlash(cards, 5) && isStreet(cards));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// A K Q J 10 все одной масти
|