Created
March 5, 2016 02:02
-
-
Save tongoclinh/07a869c4c7a6d1d286a0 to your computer and use it in GitHub Desktop.
Các hàm bổ sung cho việc gửi bài
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
| std::vector<std::pair<GBCardInfo, int> > GBRoomTala::getCardGui() { | |
| auto player = getLocalPlayer(); | |
| std::vector<std::pair<std::vector<GBCardInfo>, int> >listPhom; | |
| for (auto p : players) { | |
| for (auto h : p.cards_Phom) { | |
| listPhom.push_back(std::make_pair(h, p.id_inroom)); | |
| } | |
| } | |
| std::vector<std::pair<GBCardInfo, int> > listGui; | |
| do { | |
| auto pair = coTheGui(player->cards_hand, listPhom); | |
| if (pair.second == -1) { | |
| break; | |
| } | |
| listGui.push_back(pair); | |
| } while (true); | |
| return listGui; | |
| } | |
| std::pair<GBCardInfo, int> GBRoomTala::coTheGui(std::vector<GBCardInfo> cards, std::vector<std::pair<std::vector<GBCardInfo>, int> > &listPhom) { | |
| for (auto c : cards) { | |
| for (auto &p : listPhom) { | |
| if (matched(c, p.first)) { | |
| p.first.push_back(c); | |
| return std::make_pair(c, p.second); | |
| } | |
| } | |
| } | |
| return std::make_pair(GBCardInfo(), -1); | |
| } | |
| bool GBRoomTala::matched(GBCardInfo card, std::vector<GBCardInfo> hand) { | |
| if (std::find(hand.begin(), hand.end(), card) != hand.end()) { | |
| return false; | |
| } | |
| auto h = hand; | |
| h.push_back(card); | |
| std::sort(h.begin(), h.end()); | |
| auto same_rank = true; | |
| auto first_rank = h.begin()->rank; | |
| for (auto c : h) { | |
| if (c.rank != first_rank) { | |
| same_rank = false; | |
| break; | |
| } | |
| } | |
| if (same_rank) { | |
| return true; | |
| } | |
| auto first_suit = h.begin()->suit; | |
| auto same_suit = std::accumulate(h.begin(), h.end(), true, [first_suit](const bool &f, GBCardInfo c) { | |
| return f && (c.suit == first_suit); | |
| }); | |
| if (!same_suit) { | |
| return false; | |
| } | |
| for (auto i = 0; i < h.size() - 1; i++) { | |
| if (h[i].rank != h[i + 1].rank - 1) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trời owiiiiiiiii, làm ơn check các page social của bạn giùm đi cái, tìm bạn mệt đứt hơiiiiii