Created
May 14, 2019 11:58
-
-
Save kosbar/1eb531fadaa20f1bfd14d45c48df6b64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <ostream> | |
| #include <cmath> | |
| #include <set> | |
| #include <algorithm> | |
| #include <random> | |
| #include <iostream> | |
| enum suit {S = 2, H = 3, D = 5, C = 7 }; | |
| enum value { _2 = 2, _3 = 3, _4 = 5, _5 = 7, _6 = 11, _7 = 13, | |
| _8 = 17, _9 = 19, _T = 23, _J = 29, _Q = 31, _K = 37, _A = 41 }; | |
| //карта | |
| struct card { | |
| uint_fast8_t s; | |
| uint_fast8_t v; | |
| bool operator==(card c){ | |
| return (c.s == s) && (c.v == v); | |
| } | |
| bool operator>(card c){ | |
| return (c.s == s) && (c.v == v); | |
| } | |
| }; | |
| std::ostream& operator<<(std::ostream& os, card& c){ | |
| switch (c.v) { | |
| case _2: os << "2"; break; | |
| case _3: os << "3"; break; | |
| case _4: os << "4"; break; | |
| case _5: os << "5"; break; | |
| case _6: os << "6"; break; | |
| case _7: os << "7"; break; | |
| case _8: os << "8"; break; | |
| case _9: os << "9"; break; | |
| case _T: os << "T"; break; | |
| case _J: os << "J"; break; | |
| case _Q: os << "Q"; break; | |
| case _K: os << "K"; break; | |
| case _A: os << "A"; break; | |
| } | |
| switch (c.s) { | |
| case S: os << "s"; break; | |
| case H: os << "h"; break; | |
| case C: os << "c"; break; | |
| case D: os << "d"; break; | |
| } | |
| return os; | |
| } | |
| //Функция принта колоды | |
| template <class T> | |
| void pr(std::vector<T>& deck){ | |
| std::cout << "deck.size(): " << deck.size() << std::endl; | |
| std::cout << "deck.capacity(): " << deck.capacity() << std::endl; | |
| std::cout << "vector: " << '\n'; | |
| for(int i = 0; i < deck.size(); ++i) { | |
| //для разграничения колоды по мастям: | |
| if( i!=0 && deck[i].s != deck[i-1].s) {std::cout << std::endl;} | |
| std::cout << " " << deck[i] << ' '; | |
| } | |
| std::cout << '\n'; | |
| } | |
| //Функция вычета выданных карт из колоды, чтобы не продублировать их на доске. | |
| void deck_minus_hand(std::vector<card>& deck, std::vector<card>& hand) { | |
| for(auto c : hand) { deck.erase(std::remove(deck.begin(),deck.end(),c), deck.end()); } | |
| //pr(deck); | |
| } | |
| void oesd_multiplies(std::vector<uint64_t>& oesd, std::vector<card>& deck) { | |
| oesd.clear(); | |
| //we need one suit only: | |
| unsigned long s = deck.size()/4; | |
| uint64_t oesd_in_deck; | |
| //Начиная с двойки (нам нужны двухсторонние дро) идём до короля | |
| //и считаем произведение value по 4 карты в масти: | |
| for(int i = 0; i < s-3; ++i){ | |
| oesd_in_deck = deck[i].v * deck[i+1].v * deck[i+2].v * deck[i+3].v; | |
| oesd.push_back(oesd_in_deck); | |
| } | |
| } | |
| void straight_multiplies(std::vector<uint64_t>& straights, std::vector<card>& deck) { | |
| straights.clear(); | |
| //we need one suit only: | |
| unsigned long s = deck.size()/4 + 1; //размер масти для цицла | |
| uint64_t multuplies; | |
| // Начиная с туза (А1345) идём до T (TJQKA) | |
| // и считаем произведение value по 5 карт в масти: | |
| for(int i = 0; i < s; ++i) | |
| { | |
| multuplies = deck[(i+s)%s].v * deck[(i+s+1)%s].v * deck[(i+s+2)%s].v * deck[(i+s+3)%s].v * deck[(i+s+4)%s].v; | |
| //std::cout << multuplies << std::endl; | |
| straights.push_back(multuplies); | |
| } | |
| } | |
| void only_hand_oesd(std::vector<uint64_t>& oesd, std::vector<card>& hand, std::vector<uint64_t>& oesd_minus){ | |
| for(auto num : oesd) { | |
| if( !(num % hand[0].v) | !(num % hand[1].v) ){ | |
| oesd_minus.push_back(num); | |
| } | |
| } | |
| } | |
| void only_hand_straights(std::vector<uint64_t>& strights, std::vector<card>& hand, std::vector<uint64_t>& strights_minus){ | |
| for(auto num : strights) { | |
| if( !(num % hand[0].v) | !(num % hand[1].v) ){ | |
| strights_minus.push_back(num); | |
| } | |
| } | |
| } | |
| //комбинации карт как произведения простых чисел (основная теорема арифметики): | |
| long multiply_value(std::vector<card>& slice){ | |
| uint64_t value = 1; | |
| for(auto i : slice) { value *= i.v; } | |
| return value; | |
| } | |
| //тоже самое с маcтями: | |
| long multiply_suits(std::vector<card>& slice){ | |
| uint64_t suits = 1; | |
| for(auto i : slice) { suits *= i.s; } | |
| std::cout << suits; | |
| return suits; | |
| } | |
| int main() { | |
| std::vector<card> deck52 = {{S,_2}, {S,_3}, {S,_4}, {S,_5}, {S,_6}, {S,_7}, {S,_8}, {S,_9}, {S,_T}, {S,_J}, {S,_Q}, {S,_K}, {S,_A}, | |
| {H,_2}, {H,_3}, {H,_4}, {H,_5}, {H,_6}, {H,_7}, {H,_8}, {H,_9}, {H,_T}, {H,_J}, {H,_Q}, {H,_K}, {H,_A}, | |
| {C,_2}, {C,_3}, {C,_4}, {C,_5}, {C,_6}, {C,_7}, {C,_8}, {C,_9}, {C,_T}, {C,_J}, {C,_Q}, {C,_K}, {C,_A}, | |
| {D,_2}, {D,_3}, {D,_4}, {D,_5}, {D,_6}, {D,_7}, {D,_8}, {D,_9}, {D,_T}, {D,_J}, {D,_Q}, {D,_K}, {D,_A}}; | |
| std::vector<card> deck36 = {{S,_6}, {S,_7}, {S,_8}, {S,_9}, {S,_T}, {S,_J}, {S,_Q}, {S,_K}, {S,_A}, | |
| {H,_6}, {H,_7}, {H,_8}, {H,_9}, {H,_T}, {H,_J}, {H,_Q}, {H,_K}, {H,_A}, | |
| {C,_6}, {C,_7}, {C,_8}, {C,_9}, {C,_T}, {C,_J}, {C,_Q}, {C,_K}, {C,_A}, | |
| {D,_6}, {D,_7}, {D,_8}, {D,_9}, {D,_T}, {D,_J}, {D,_Q}, {D,_K}, {D,_A}}; | |
| std::vector<card> hand = {{D,_T}, {H,_J}}; | |
| std::vector<uint64_t> oesd; /// вектор со всеми возможными OESD в короде. | |
| oesd_multiplies(oesd, deck52); /// заполнили его | |
| std::vector<uint64_t> oesd_with_hand; ///отфилтровали OESD, оставив те, в которых есть сданные на руки карты | |
| only_hand_oesd(oesd,hand,oesd_with_hand); | |
| std::vector<uint64_t> strights; /// вектор со всеми возможными стритами в колоде. | |
| straight_multiplies(strights, deck52); | |
| std::vector<uint64_t> strights_with_hand; ///отфилтровали стриты, оставив те, в которых есть сданные на руки карты | |
| only_hand_straights(strights, hand, strights_with_hand); | |
| std::vector<card>flop; ///вектор с первыми тремя картами стола. | |
| deck_minus_hand(deck52, hand); ///раздали карты. | |
| ///генерация флопа: | |
| std::sample(deck52.begin(), deck52.end(), std::back_inserter(flop), 3, std::mt19937{std::random_device{}()}); | |
| pr(flop); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment