|
@@ -1,208 +1,222 @@
|
|
-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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // ВОТ ТУТ ДЫРА В КОДЕ :)
|
|
|
|
- // Стрит не всегда может не с 0 элемента начинаться
|
|
|
|
- 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 все одной масти
|
|
|
|
|
|
+package com.company;
|
|
|
|
+
|
|
|
|
+import java.util.Random;
|
|
|
|
+
|
|
|
|
+public class Dealer {
|
|
|
|
+ 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 Dealer(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("Player-" + (i + 1));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ currentRateType = RATE_TYPE.PREFLOP;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Раздача карт
|
|
|
|
+ */
|
|
|
|
+ public void HandOut() {
|
|
|
|
+ switch (currentRateType) {
|
|
|
|
+ case PREFLOP: {
|
|
|
|
+ for (int i = 0; i < players.length; i++) {
|
|
|
|
+ int cardIndex1 = random.nextInt(52);
|
|
|
|
+ int cardIndex2 = random.nextInt(52);
|
|
|
|
+ Card card1 = deck.Cards[cardIndex1];
|
|
|
|
+ Card card2 = deck.Cards[cardIndex2];
|
|
|
|
+
|
|
|
|
+ if (card1.onHands || card2.onHands) {
|
|
|
|
+ i--;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ card1.onHands = true;
|
|
|
|
+ card2.onHands = true;
|
|
|
|
+ players[i].setCards(Player.CARD_SLOT.FIRST, card1);
|
|
|
|
+ players[i].setCards(Player.CARD_SLOT.SECOND, card2);
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Положить на стол cardCount карт
|
|
|
|
+ * @param cardCount количество карт для раздачи
|
|
|
|
+ */
|
|
|
|
+ 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;
|
|
|
|
+ currentCard.onHands = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // ♦♣♥♠
|
|
|
|
+ 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_SLOT.FIRST);
|
|
|
|
+ sharedCards[i] = player.getCards(Player.CARD_SLOT.SECOND);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ Sorting(sharedCards);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PrintCard(sharedCards);
|
|
|
|
+
|
|
|
|
+// 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()] + " "
|
|
|
|
+// );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void PrintCard(Card []cards) {
|
|
|
|
+ for (Card card : cards) {
|
|
|
|
+ System.out.print(
|
|
|
|
+ deck.CardName.get(card.getDenomination())
|
|
|
|
+ + Lear.SYMBOL[card.Lear.ordinal()] + " ");
|
|
|
|
+ }
|
|
|
|
+ System.out.println();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Сортировка массива карт по убыванию его номинала
|
|
|
|
+ *
|
|
|
|
+ * @param cards массив карт (7 штук)
|
|
|
|
+ */
|
|
|
|
+ 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 массив карт
|
|
|
|
+ */
|
|
|
|
+ public boolean isStreet(Card[] cards) {
|
|
|
|
+ int counter = 0;
|
|
|
|
+ for (int i = 0; i < cards.length - 1; i++) {
|
|
|
|
+
|
|
|
|
+ if (cards[i].getDenomination() == cards[i + 1].getDenomination()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (cards[i].getDenomination() != cards[i + 1].getDenomination() + 1) {
|
|
|
|
+ if (i < 2) {
|
|
|
|
+ counter = 0;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ counter++;
|
|
|
|
+
|
|
|
|
+ if (counter >= 4) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 все одной масти
|