Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Runtime.Remoting.Metadata;
- using System.Runtime.Versioning;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.VisualStyles;
- using Poker.Properties;
- namespace Poker
- {
- public partial class Room : Form
- {
- public Room()
- {
- InitializeComponent();
- }
- private string[] players = new string[7] { "Dankula", "FoKy", "Fereal", "Reaper", "rokmen", "gogo", "nevim" };
- //Všechny hodnoty karet
- public int[] cards_values = new int[13] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
- //Všechny barvy karet
- public readonly int[] cards_colors = new int[4] { 1, 2, 3, 4 };
- //public List<string> cards_colors = new List<string>() { "s", "k", "t", "p" };
- public List<int[]> UsedCards = new List<int[]>();
- public float pravdepodobnost = 0;
- public List<int[]> Cards = new List<int[]>();
- private void Room_Load(object sender, EventArgs e)
- {
- for (int i = 0; i < cards_values.Count(); i++)
- {
- for (int j = 0; j < cards_colors.Count(); j++)
- {
- Cards.Add(new int[2] { cards_values[i], cards_colors[j] });
- }
- }
- timer1.Start();
- }
- private string getCardVal(int number, int color)
- {
- List<string> colors = new List<string>() { "s", "k", "t", "p" };
- List<string> values = new List<string>() { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
- return values[number - 1] + colors[color - 1];
- }
- private void raise_trackbar_Scroll(object sender, EventArgs e)
- {
- int value = raise_trackbar.Value;
- trackbar_value.Text = "$" + Player.convertBalance(Math.Round(Player.balance / 100, 0) * value);
- }
- public int CountStringOccurrences(string text, string pattern)
- {
- // Loop through all instances of the string 'text'.
- int count = 0;
- int i = 0;
- while ((i = text.IndexOf(pattern, i)) != -1)
- {
- i += pattern.Length;
- count++;
- }
- return count;
- }
- //Seřadit karty od nejnižší po nejvyšší
- public List<int[]> SerializeCards(List<int[]> input)
- {
- for (int j = 0; j < input.Count(); j++)
- {
- for (int i = 0; i < input.Count() - 1; i++)
- {
- if (input[i][0] > input[i + 1][0])
- {
- var pom = input[i][0];
- var pom2 = input[i][1];
- input[i][0] = input[i + 1][0];
- input[i][1] = input[i + 1][1];
- input[i + 1][0] = pom;
- input[i + 1][1] = pom2;
- }
- }
- }
- return input;
- }
- //Vyčistí karty od duplikátů
- public int[] ClearCards(int[] input)
- {
- return input.Distinct().ToArray();
- }
- public bool IsStraight(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- // Postupka //
- int count = 0;
- List<int[]> serializedcards = SerializeCards(input);
- if (serializedcards.Count >= 5)
- {
- int firstcardindex = 0;
- for (int i = 0; i < 2; i++)
- {
- if (serializedcards[i][0] == (serializedcards[i + 1][0] - 1))
- {
- if (serializedcards[i + 2][0] == (serializedcards[i + 3][0] - 1))
- {
- if (serializedcards[i + 3][0] == (serializedcards[i + 4][0] - 1))
- {
- if (serializedcards[i + 4][0] == (serializedcards[i + 5][0] - 1))
- {
- count++;
- }
- }
- }
- }
- }
- if (count >= 1)
- {
- return true;
- }
- else return false;
- }
- else return false;
- /////////////////////////////////////////////////////////////////
- }
- public bool IsFlush(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- // Barva //
- bool color = false;
- for (int i = 0; i < cards_colors.Count(); i++)
- {
- int points = 0;
- if (input[0][1] == cards_colors[i]) points++;
- if (input[1][1] == cards_colors[i]) points++;
- if (input[2][1] == cards_colors[i]) points++;
- if (input[3][1] == cards_colors[i]) points++;
- if (input[4][1] == cards_colors[i]) points++;
- if (input[5][1] == cards_colors[i]) points++;
- if (input[6][1] == cards_colors[i]) points++;
- if (points >= 5) color = true;
- }
- if (color) return true;
- else return false;
- //////////////////////////////////////////////////////////////////
- }
- public bool IsPair(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- // Pár //
- int count = 0;
- List<int[]> serializedcards = SerializeCards(input);
- for (int i = 0; i < serializedcards.Count - 1; i++)
- {
- if (serializedcards[i][0] == (serializedcards[i + 1][0]))
- {
- count++;
- }
- }
- if (count == 1) return true;
- else return false;
- //////////////////////////////////////////////////////////////////
- }
- public bool IsTwoPair(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- // Dva páry //
- int count = 0;
- List<int[]> serializedcards = SerializeCards(input);
- for (int i = 0; i < serializedcards.Count - 1; i++)
- {
- if (serializedcards[i][0] == (serializedcards[i + 1][0]))
- {
- count++;
- }
- }
- if (count >= 2) return true;
- else return false;
- //////////////////////////////////////////////////////////////////
- }
- public bool IsThreeOfAKind(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- // Trojička //
- int count = 0;
- List<int[]> serializedcards = SerializeCards(input);
- for (int i = 0; i < serializedcards.Count - 2; i++)
- {
- if (serializedcards[i][0] == serializedcards[i + 1][0] &&
- serializedcards[i + 1][0] == serializedcards[i + 2][0])
- {
- count++;
- }
- }
- if (count != 0) return true;
- else return false;
- //////////////////////////////////////////////////////////////////
- }
- public bool IsFullHouse(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- /// FullHouse //
- int count = 0, count2 = 0;
- int toakcard = 0;
- List<int[]> serializedcards = SerializeCards(input);
- for (int i = 0; i < serializedcards.Count - 2; i++)
- {
- if (serializedcards[i] == serializedcards[i + 1] && serializedcards[i + 1] == serializedcards[i + 2])
- {
- toakcard = serializedcards[i][0];
- count++;
- }
- }
- if (count != 0)
- {
- int[] remaining = serializedcards[0].Where(val => val != toakcard).ToArray();
- for (int i = 0; i < remaining.Length - 1; i++)
- {
- if (remaining[i] == remaining[i + 1])
- {
- count2++;
- }
- }
- if (count2 != 0) return true;
- else return false;
- }
- else return false;
- //////////////////////////////////////////////////////////////////
- }
- public bool IsFourOfAKind(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- /// Čtyřka //
- int count = 0;
- List<int[]> serializedcards = SerializeCards(input);
- for (int i = 0; i < serializedcards.Count - 3; i++)
- {
- if (serializedcards[i][0] == serializedcards[i + 1][0] &&
- serializedcards[i + 1][0] == serializedcards[i + 2][0] &&
- serializedcards[i + 2][0] == serializedcards[i + 3][0])
- {
- count++;
- }
- }
- if (count != 0) return true;
- else return false;
- //////////////////////////////////////////////////////////////////
- }
- public bool IsStraightFlush(List<int[]> input)
- {
- /////////////////////////////////////////////////////////////////
- // Barevná postupka //
- int count = 0;
- List<int[]> serializedcards = SerializeCards(input);
- bool first = false;
- int firstcardinrow = 0;
- int firstcardindex = 0;
- for (int i = 0; i < 3; i++)
- {
- if (serializedcards[i][0] == (serializedcards[i + 1][0] - 1))
- {
- if (serializedcards[i + 1][0] == (serializedcards[i + 2][0] - 1))
- {
- if (serializedcards[i + 2][0] == (serializedcards[i + 3][0] - 1))
- {
- if (serializedcards[i + 3][0] == (serializedcards[i + 4][0] - 1))
- {
- if (!first)
- {
- firstcardindex = i;
- firstcardinrow = serializedcards[i][0];
- first = true;
- }
- count++;
- }
- }
- }
- }
- }
- if (count >= 1)
- {
- bool color = false;
- for (int i = 0; i < cards_colors.Count(); i++)
- {
- int points = 0;
- if (serializedcards[firstcardindex][1] == cards_colors[i]) points++;
- if (serializedcards[firstcardindex + 1][1] == cards_colors[i]) points++;
- if (serializedcards[firstcardindex + 2][1] == cards_colors[i]) points++;
- if (serializedcards[firstcardindex + 3][1] == cards_colors[i]) points++;
- if (serializedcards[firstcardindex + 4][1] == cards_colors[i]) points++;
- if (points == 5) color = true;
- }
- if (color) return true;
- return false;
- }
- return false;
- //////////////////////////////////////////////////////////////////
- }
- public int[] UniqeRandom(int size, int Min, int Max)
- {
- int[] UniqueArray = new int[size];
- Random rnd = new Random();
- for (int i = 0; i < size; i++)
- {
- var random = rnd.Next(Min, Max);
- for (int j = i; j >= 0; j--)
- {
- if (UniqueArray[j] == random)
- {
- random = rnd.Next(Min, Max);
- j = i;
- }
- }
- UniqueArray[i] = random;
- }
- return UniqueArray;
- }
- public List<T> Randomize<T>(List<T> list)
- {
- List<T> randomizedList = new List<T>();
- Random rnd = new Random();
- while (list.Count > 0)
- {
- int index = rnd.Next(0, list.Count); //pick a random item from the master list
- randomizedList.Add(list[index]); //place it at the end of the randomized list
- list.RemoveAt(index);
- }
- return randomizedList;
- }
- private List<int[]> GenerateCardsForPlayer(List<int[]> usedCards1)
- {
- List<int[]> remainingCards = new List<int[]>(Cards);
- for (int i = 0; i < usedCards1.Count(); i++)
- {
- remainingCards.Remove(usedCards1[i]);
- }
- remainingCards = Randomize(remainingCards);
- int remainingCardsCount = remainingCards.Count();
- int[] twoCards = UniqeRandom(2, 0, remainingCardsCount);
- UsedCards.Add(remainingCards[twoCards[0]]);
- UsedCards.Add(remainingCards[twoCards[1]]);
- List<int[]> playerCards = new List<int[]>() { remainingCards[twoCards[0]], remainingCards[twoCards[1]] };
- return playerCards;
- }
- private List<int[]> GenerateLandCards(List<int[]> usedCards1)
- {
- List<int[]> remainingCards = new List<int[]>(Cards);
- for (int i = 0; i < usedCards1.Count(); i++)
- {
- remainingCards.Remove(usedCards1[i]);
- }
- remainingCards = Randomize(remainingCards);
- int remainingCardsCount = remainingCards.Count();
- int[] twoCards = UniqeRandom(5, 0, remainingCardsCount);
- UsedCards.Add(remainingCards[twoCards[0]]);
- UsedCards.Add(remainingCards[twoCards[1]]);
- UsedCards.Add(remainingCards[twoCards[2]]);
- UsedCards.Add(remainingCards[twoCards[3]]);
- UsedCards.Add(remainingCards[twoCards[4]]);
- List<int[]> landCards = new List<int[]>()
- {
- remainingCards[twoCards[0]],
- remainingCards[twoCards[1]],
- remainingCards[twoCards[2]],
- remainingCards[twoCards[3]],
- remainingCards[twoCards[4]]
- };
- return landCards;
- }
- public int solveCards(string player, List<int[]> cards, List<int[]> lands)
- {
- cards.AddRange(lands);
- /////////////////////////////////////////////////////////////////
- /// Zjišťování kombinací ///
- /////////////////////////////////////////////////////////////////
- int rank = 0;
- if (IsPair(cards) && rank == 0 ) rank = 1;
- /*
- if (IsTwoPair(cards1) && rank < 2) rank = 2;
- if (IsThreeOfAKind(cards1) && rank < 3) rank = 3;
- if (IsStraight(cards1) && rank < 4) rank = 4;
- if (IsFlush(cards1) && rank < 5) rank = 5;
- if (IsFullHouse(cards1) && rank < 6) rank = 6;
- if (IsFourOfAKind(cards1) && rank < 7) rank = 7;
- if (IsStraightFlush(cards1) && rank < 8) rank = 8;
- */
- return rank;
- }
- public void Generating()
- {
- List<int[]> playerCards1 = GenerateCardsForPlayer(UsedCards);
- player0Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards1[0][0], playerCards1[0][1]));
- player0Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards1[1][0], playerCards1[1][1]));
- player0Card1l.Text = getCardVal(playerCards1[0][0], playerCards1[0][1]);
- player0Card2l.Text = getCardVal(playerCards1[1][0], playerCards1[1][1]);
- List<int[]> playerCards2 = GenerateCardsForPlayer(UsedCards);
- player1Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards2[0][0], playerCards2[0][1]));
- player1Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards2[1][0], playerCards2[1][1]));
- //player1Card1l.Text = getCardVal(playerCards2[0][0], playerCards2[0][1]);
- //player1Card2l.Text = getCardVal(playerCards2[1][0], playerCards2[1][1]);
- List<int[]> playerCards3 = GenerateCardsForPlayer(UsedCards);
- player2Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards3[0][0], playerCards3[0][1]));
- player2Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards3[1][0], playerCards3[1][1]));
- //player2Card1l.Text = getCardVal(playerCards3[0][0], playerCards3[0][1]);
- //player2Card2l.Text = getCardVal(playerCards3[1][0], playerCards3[1][1]);
- List<int[]> playerCards4 = GenerateCardsForPlayer(UsedCards);
- player3Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards4[0][0], playerCards4[0][1]));
- player3Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards4[1][0], playerCards4[1][1]));
- List<int[]> playerCards5 = GenerateCardsForPlayer(UsedCards);
- player4Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards5[0][0], playerCards5[0][1]));
- player4Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards5[1][0], playerCards5[1][1]));
- List<int[]> playerCards6 = GenerateCardsForPlayer(UsedCards);
- player5Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards6[0][0], playerCards6[0][1]));
- player5Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards6[1][0], playerCards6[1][1]));
- List<int[]> playerCards7 = GenerateCardsForPlayer(UsedCards);
- player6Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards7[0][0], playerCards7[0][1]));
- player6Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards7[1][0], playerCards7[1][1]));
- List<int[]> playerCards8 = GenerateCardsForPlayer(UsedCards);
- player7Card1.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards8[0][0], playerCards8[0][1]));
- player7Card2.Image = (Image)Resources.ResourceManager.GetObject(getCardVal(playerCards8[1][0], playerCards8[1][1]));
- //Vyložit pět karet na stůl
- List<int[]> landCards = GenerateLandCards(UsedCards);
- landCard1.Image =
- (Image)Resources.ResourceManager.GetObject(getCardVal(landCards[0][0], landCards[0][1]));
- landCard2.Image =
- (Image)Resources.ResourceManager.GetObject(getCardVal(landCards[1][0], landCards[1][1]));
- landCard3.Image =
- (Image)Resources.ResourceManager.GetObject(getCardVal(landCards[2][0], landCards[2][1]));
- landCard4.Image =
- (Image)Resources.ResourceManager.GetObject(getCardVal(landCards[3][0], landCards[3][1]));
- landCard5.Image =
- (Image)Resources.ResourceManager.GetObject(getCardVal(landCards[4][0], landCards[4][1]));
- List<int[]> landCards1 = new List<int[]>(landCards);
- solveCards("player0", playerCards1, landCards);
- //solveCards("player1", playerCards2[0], playerCards2[1], landCards[0], landCards[1], landCards[2], landCards[3], landCards[4]);
- label3.Text = getCardVal(playerCards1[0][0], playerCards1[0][1]);
- label4.Text = getCardVal(playerCards1[1][0], playerCards1[1][1]);
- label5.Text = getCardVal(playerCards2[0][0], playerCards2[0][1]);
- label6.Text = getCardVal(playerCards2[1][0], playerCards2[1][1]);
- land_card_1l.Text = getCardVal(landCards1[0][0], landCards1[0][1]);
- land_card_2l.Text = getCardVal(landCards1[1][0], landCards1[1][1]);
- land_card_3l.Text = getCardVal(landCards1[2][0], landCards1[0][1]);
- land_card_4l.Text = getCardVal(landCards1[3][0], landCards1[3][1]);
- land_card_5l.Text = getCardVal(landCards1[4][0], landCards1[4][1]);
- UsedCards.Clear();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- //Generating();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //timer1.Start();
- Generating();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement