// Please use UTF-8 encoding so that the comments can be displayed correctly. // 标注TODO的是你需要完善的地方 #include #include #include #include #include #include #include #include #include using namespace std; #define joker 13 #define JOKER 14 class Card : public string { public: static const int N_CARD_VALUES; static const int N_CARD_SUITS; static const string CARD_VALUES[]; static const string CARD_SUITS[]; Card(const char* str) :string(str) {}; Card() :string() {}; Card(string str) :string(str) {}; static vector get_new_deck(); // 重载操作符,使得牌面可以比较大小 bool operator <(const Card &other) const; bool operator >(const Card &other) const; }; class NewData { public: int a[15]; struct M { int sum; int singlesum; int doublesum; int triplesum; int quatrasum; }A; NewData() { for (int i = 0; i < 15; i++) a[i] = 0; A = { 0,0,0,0,0 }; } void update(vector& v) { for (int i = 0; i <= 14; i++)a[i] = 0; for (vector::iterator i = v.begin(); i != v.end(); ++i) { for (int j = 0; j <= 14; j++) if (*i == Card::CARD_VALUES[j]) a[j]++; } A.sum = A.singlesum = A.doublesum = A.triplesum = A.quatrasum = 0; for (int i = 0; i <= 14; i++) { if (a[i] == 1) A.singlesum++; else if (a[i] == 2) A.doublesum++; else if (a[i] == 3) A.triplesum++; else if (a[i] == 4) A.quatrasum++; } A.sum = A.singlesum + 2 * A.doublesum + 3 * A.triplesum + 4 * A.quatrasum; } int find(int num, int min) {//在数组中找一个比min大的数字为num的下标 for (int i = 0; i <= 14; i++) if (a[i] == num && i > min) return i; return 0; } int find(int num, int min, int nolimited) {//在数组中找一个比min大的数字不小于num的下标 for (int i = 1; i <= 14; i++) if (a[i] >= num && i > min) return i; return 0; } void randomPlay(NewData& current, NewData& playCards); void processPlay(NewData& current, NewData& playCards, NewData& otherPlay); void transform(vector& v) { for (int i = 0; i <= 14; i++) while (a[i] > 0) { v.push_back(Card::CARD_VALUES[i]); a[i]--; } } void otherwise(NewData& playCards) { for (int i = 0; i <= 12; i++) if (a[i] == 4) { playCards.a[i] += 4; a[i] -= 4; return; } if (a[joker] && a[JOKER]) { playCards.a[joker] = 1, playCards.a[JOKER] = 1; } } }; class DDZPlayer { protected: string name; // 玩家名 int position; // 你的位置编号,0为地主,1为地主下家,2为地主上家 vector hand; // 手牌 int prePos; //上一个出牌的人位置编号,-1表示还没有人出过牌 vector prePlay; // 上一个出牌的人出了什么牌? bool legal(vector cards); // 判断当前打出cards是否合法 void substractFromHand(vector cards); // 从当前手牌中删去cards中的牌 public: DDZPlayer(string name); // 构造函数,初始化玩家名 string getName(); virtual void draw(Card card); // 将cards中的牌加入手牌 virtual void draw(vector cards); // 将cards中的牌加入手牌 virtual void setPosition(int pos); // 初始化用,决定地主后设置 virtual void showHand(); // 打印手牌 virtual void observed(int pos, vector cards); // 观测到玩家出牌 virtual vector play(); // 轮到自己时决定出什么牌 bool leftNoCard(); // 返回是否打完了牌? }; class DDZGame { private: static int my_random(int i); // 洗牌时用到的随机函数 vector players; // 保存三个玩家的指针 void showCards(vector cards); // 输出一组牌 public: DDZGame(DDZPlayer *p1, DDZPlayer *p2, DDZPlayer *p3); // 构造函数 void run(); // 执行游戏流程 }; class DDZHumanPlayer : public DDZPlayer { public: DDZHumanPlayer(string name) : DDZPlayer(name) {}; vector play(); }; // ---------------------------------------------------------------------------- int main() { cout << "input YAO BU QI to pass." << endl; string name; cout << "Please input your name:" << endl; getline(cin, name); srand(rand()%2333); DDZPlayer p1("Alice"), p2("Bob"); DDZHumanPlayer p3(name); DDZGame g(&p1, &p2, &p3); g.run(); system("pause"); return 0; } bool Card::operator <(const Card &other) const { int a = -1, b = -1; for (int i = 0; i < N_CARD_VALUES; ++i) { if (*this == CARD_VALUES[i]) a = i; if (other == CARD_VALUES[i]) b = i; } return a < b; } bool Card::operator >(const Card &other) const { return other < *this; } DDZPlayer::DDZPlayer(string name) : name(name) { // 玩家类的构造函数 prePos = -1; } string DDZPlayer::getName() { return name; } bool DDZPlayer::legal(vector cards) { // 通过上家打出的牌prePlay和手牌hand判断cards作为打出牌是否合法 // TODO:(第二题)请补全这个函数 NewData tmp; tmp.update(cards); NewData previous; previous.update(prePlay); NewData handpoker; handpoker.update(hand); bool flag = true; for (int i = 0; i <= 14; i++) flag = flag && (handpoker.a[i] >= tmp.a[i]); if (flag) { if (prePos == -1||prePos==position) { switch (tmp.A.sum) { case 0: case 1:return true; case 2: { if (tmp.A.doublesum || (tmp.a[joker] && tmp.a[JOKER])) return true; }break; case 3: { if (tmp.A.triplesum) return true; }break; case 4: { if (tmp.A.quatrasum || (tmp.A.triplesum&&tmp.A.singlesum)) return true; }break; default: { if (tmp.A.triplesum == 1 && tmp.A.doublesum == 1 && tmp.A.sum == 5) return true; if (tmp.A.sum == 6 && tmp.A.quatrasum == 1 && tmp.A.singlesum == 2) return true; if (tmp.A.sum == 6 && tmp.A.quatrasum == 1 && tmp.A.doublesum == 2) return true; if (tmp.A.sum >= 5 && tmp.A.singlesum == tmp.A.sum) { for (int m = 13; m >= 5; m--) { for (int i = 0; i <= 13 - m; i++) { flag = true; for (int j = i; j <= i + m - 1; j++) flag = flag && (tmp.a[j] == 1); if (flag) return true; } } } if (tmp.A.sum >= 6 && tmp.A.sum == 2 * tmp.A.doublesum) { for (int m = 13; m >= 3; m--) { for (int i = 0; i <= 13 - m; i++) { flag = true; for (int j = i; j <= i + m - 1; j++) flag = flag && (tmp.a[j] == 2); if (flag) return true; } } } if (tmp.A.sum >= 6 && tmp.A.triplesum >= 2) { for (int m = 13; m >= 3; m--) { for (int i = 0; i <= 13 - m; i++) { flag = true; for (int j = i; j <= i + m - 1; j++) flag = flag && (tmp.a[j] == 3); if (flag&&m == tmp.A.triplesum) { if (m * 3 == tmp.A.sum) return true; if (tmp.A.sum == 4 * m) return true; if (tmp.A.sum == 5 * m&&m == (tmp.A.doublesum + tmp.A.quatrasum * 2)) return true; } } } } } } } else { switch (previous.A.sum) { case 1: { if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == 1) { int current = tmp.find(1, -1); int pre = previous.find(1, -1); if (current > pre) return true; } }break; case 2: { if (previous.A.sum == 2 && previous.a[joker] && previous.a[JOKER]) return false; if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == 2) { int current = tmp.find(2, -1); int pre = previous.find(2, -1); if (current > pre) return true; } }break; case 3: { if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == 3) { int current = tmp.find(3, -1); int pre = previous.find(3, -1); if (current > pre) return true; } }break; case 4: { if (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER]) return true; if (previous.A.triplesum&&previous.A.singlesum) { if (tmp.A.quatrasum == 1 && tmp.A.sum == 4) return true; if (tmp.A.sum == 4 && tmp.A.triplesum) { int current = tmp.find(3, -1); int pre = previous.find(3, -1); if (current > pre) return true; } } if (previous.A.quatrasum&&tmp.A.quatrasum&&tmp.A.sum == 4) { int current = tmp.find(4, -1); int pre = previous.find(4, -1); if (current > pre) return true; } }break; default: { if (previous.A.sum == 5 && previous.A.triplesum&&previous.A.doublesum) { if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == 5 && tmp.A.triplesum&&tmp.A.doublesum) { int current = tmp.find(3, -1); int pre = previous.find(3, -1); if (current > pre) return true; } } if (previous.A.sum >= 5 && previous.A.sum == previous.A.singlesum) { if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == previous.A.sum&&tmp.A.sum == tmp.A.singlesum) { int current = tmp.find(1, -1); int pre = previous.find(1, -1); if (current > pre) { flag = true; for (int j = current; j <= current + previous.A.sum - 1; j++) flag = flag && (tmp.a[j] == 1); if (flag) return true; } } } if (previous.A.sum >= 6 && previous.A.sum == 2 * previous.A.doublesum) { if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == previous.A.sum&&tmp.A.sum == 2 * tmp.A.doublesum) { int current = tmp.find(2, -1); int pre = previous.find(2, -1); if (current > pre) { flag = true; for (int j = current; j <= current + previous.A.doublesum - 1; j++) flag = flag && (tmp.a[j] == 2); if (flag) return true; } } } if (previous.A.sum >= 6 && previous.A.triplesum + previous.A.quatrasum >= 2) { if ((tmp.A.quatrasum == 1 && tmp.A.sum == 4) || (tmp.A.sum == 2 && tmp.a[joker] && tmp.a[JOKER])) return true; if (tmp.A.sum == previous.A.sum&&tmp.A.triplesum + tmp.A.quatrasum >= 2) { int m = previous.A.triplesum + previous.A.quatrasum; int current = tmp.find(3, -1, 1); int pre = previous.find(3, -1, 1); if (current > pre) { flag = true; for (int j = current; j <= current + m - 1; j++) flag = flag && (tmp.a[j] >= 3); if (flag) { if (tmp.A.sum == 3 * m || tmp.A.sum == 4 * m) return true; else if (tmp.A.doublesum == previous.A.doublesum) return true; } } } } } } } } return false; } void DDZPlayer::substractFromHand(vector cards) { // 这个函数从hand中删除cards。假设cards中的牌hand可以拿得出来(否则会出错)。 sort(hand.begin(), hand.end(), greater()); sort(cards.begin(), cards.end(), greater()); vector::iterator i = hand.begin(), k = cards.begin(); for (vector::iterator j = hand.begin(); j != hand.end(); ++j) { if (k == cards.end() || *k != *j) *(i++) = *j; else if (k != cards.end()) ++k; } hand.erase(i, hand.end()); } void DDZPlayer::showHand() { // 输出玩家名和手牌。 cout << name << " holds: "; for (vector::iterator i = hand.begin(); i != hand.end(); ++i) { cout << *i << " "; } cout << endl; } void DDZPlayer::draw(Card card) { // 将card加入手牌 hand.push_back(card); sort(hand.begin(), hand.end(), greater()); } void DDZPlayer::draw(vector cards) { // 将cards中的牌加入手牌 hand.insert(hand.end(), cards.begin(), cards.end()); sort(hand.begin(), hand.end(), greater()); } void DDZPlayer::setPosition(int pos) { position = pos; } void DDZPlayer::observed(int pos, vector cards) { // 将上一个出牌的人和出了什么牌记录下来。 // 如果你想记录更多的信息供你的策略使用,可以改动这个函数。 // 例如,记录已经有哪些牌被打出(记牌器),以推测场上是否可能还存在炸弹。 if (cards.size() == 0)return; prePos = pos; prePlay = cards; } vector DDZPlayer::play() { // 轮到你出牌,返回打出的牌。 // TODO:(第一题)请完善这个函数 // 如果你使用不同的数据结构进行处理,你可以现将hand变量转换为你使用的结构, // 处理过后再将打出的牌转换为vector,存入card变量。 vector cards; if (prePos == position || prePos == -1) { // 出任意牌 NewData current; current.update(hand); NewData playCards; current.update(hand); current.randomPlay(current, playCards); playCards.transform(cards); } else { // 位于prePos的玩家打出了prePlay的牌,你需要出什么牌? NewData current; current.update(hand); NewData previous; previous.update(prePlay); NewData playCards; current.processPlay(current, playCards, previous); playCards.transform(cards); } // 你需要保证打出的牌是合法的 // assert函数在参数为false的时候会使程序报错退出。 // 这样做的好处是,如果你有没注意到的错误导致程序在此报错退出, // 你就知道是在出牌的合法性上出了问题,而不用排查程序的其他部分。 // assert(legal(cards)); // 将打出的牌从手牌中删去 substractFromHand(cards); return cards; } bool DDZPlayer::leftNoCard() { // 返回当前手牌为空 return hand.empty(); } const int Card::N_CARD_VALUES = 15; const int Card::N_CARD_SUITS = 4; const string Card::CARD_VALUES[] = { "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER" }; const string Card::CARD_SUITS[] = { "Spades", "Hearts", "Diamonds", "Clubs" }; vector Card::get_new_deck() { // 生成一副新牌 vector deck; for (int i = 0; i < N_CARD_VALUES - 2; ++i) { for (int j = 0; j < N_CARD_SUITS; ++j) { Card card(CARD_VALUES[i]); deck.push_back(card); } } deck.push_back(Card(CARD_VALUES[13])); deck.push_back(Card(CARD_VALUES[14])); return deck; } int DDZGame::my_random(int i) { return std::rand() % i; } DDZGame::DDZGame(DDZPlayer *p1, DDZPlayer *p2, DDZPlayer *p3) { // 牌局类的构造函数,需要接受三个玩家作为参数 players.push_back(p1); players.push_back(p2); players.push_back(p3); } void DDZGame::showCards(vector cards) { sort(cards.begin(), cards.end(), greater()); for (vector::iterator i = cards.begin(); i != cards.end(); ++i) { cout << *i << " "; } if (cards.size() == 0) cout << "YAO BU QI"; cout << endl; } void DDZGame::run() { // 斗地主游戏的主要流程 // 取一副新牌并洗牌 vector deck = Card::get_new_deck(); random_shuffle(deck.begin(), deck.end(), my_random); // 每个玩家抽17张牌,留下三张底牌 for (int i = 0; i < 54 - 3; ++i) players[i % 3]->draw(deck[i]); // 随机选取地主,发给地主最后三张牌 // * 你可以实现自己的叫地主流程, // * 你需要在DDZPlayer类里面加入相应的变量(存储其他玩家叫地主的情况) // * 和函数bool DDZPlayer::bid()(返回自己是否要叫地主)。 // * 请参阅play()函数和叫地主的规则设计这个流程。 int landlordPos = my_random(3); for (int i = 54 - 3; i < 54; ++i) players[landlordPos]->draw(deck[i]); for (int i = 0; i < 3; ++i) players[i]->setPosition((i + 3 - landlordPos) % 3); // 计算与地主的相对位置 cout << players[landlordPos]->getName() << " is the landlord." << endl; int currentPlayer = landlordPos; while (true) { // 当前玩家打牌 vector currentCards = players[currentPlayer]->play(); cout << players[currentPlayer]->getName() << " plays:"; //players[currentPlayer]->showHand(); showCards(currentCards); // 其他玩家看到了打出的牌。(并不是只有下家看到,上家也能看到) for (int i = 0; i < 3; ++i) { // 玩家看到的位置编号都是从地主为0开始的 int relativePos = (currentPlayer + 3 - landlordPos) % 3; players[i]->observed(relativePos, currentCards); } // 如果刚出完牌的玩家没有牌了游戏结束 if (players[currentPlayer]->leftNoCard()) { bool landlordwins = (currentPlayer == landlordPos); cout << (landlordwins ? "Landlord wins!" : "Farmers win!") << endl; break; } // 计算下一个玩家的下标 currentPlayer = (currentPlayer + 1) % 3; } } vector DDZHumanPlayer::play() { vector cards; string s, c; while (true) { showHand(); cout << "Please input the cards you want to play." << endl; getline(cin, s); if (s == "YAO BU QI") return cards; istringstream iss(s); while (iss >> c) { cards.push_back(Card(c)); } // 现在cards是一个vector,存储了用户输入的牌 // 你需要检测输入的牌是持有的牌,并且合法。请完成legal函数。 if (legal(cards)) { break; } else { cout << "Illegal cards. Input again." << endl; cards.clear(); } } substractFromHand(cards); return cards; } void NewData::randomPlay(NewData& current, NewData& playCards) { bool flag = true; if (current.A.triplesum > 1) { flag = true; for (int m = 13; m >= 2; m--) { for (int i = 0; i <= 13 - m; i++) { flag = true; for (int j = i; j <= i + m - 1; j++) flag = flag && (current.a[j] >= 3); if (flag) { for (int k = i; k <= i + m - 1; k++) { current.a[k] -= 3; playCards.a[k] += 3; } if (current.A.doublesum >= m) { for (int i = m; i >= 1; i--) { for (int j = 3; j <= 15; j++) { if (current.a[j] == 2) { current.a[j] -= 2; playCards.a[j] += 2; break; } } } } else if (current.A.sum >= 4 * m) { for (int i = m; i >= 1; i--) { for (int j = 3; j <= 17; j++) { if (current.a[j] >= 1) { current.a[j]--; playCards.a[j]++; break; } } } } return; } } } } if (current.A.triplesum) { int max = current.find(3, -1); current.a[max] -= 3; playCards.a[max] += 3; if (current.A.doublesum) { int min = current.find(2, -1); current.a[min] -= 2; playCards.a[min] += 2; } else if (current.A.singlesum) { int min = current.find(1, -1); current.a[min]--; playCards.a[min]++; } } else { for (int m = 13; m >= 5; m--) { for (int i = 0; i <= 13 - m; i++) { flag = true; for (int j = i; j <= i + m - 1; j++) flag = flag && (current.a[j] >= 1); if (flag) { for (int k = i; k <= i + m - 1; k++) { current.a[k]--; playCards.a[k]++; } return; } } } for (int m = 13; m >= 3; m--) { for (int i = 0; i <= 13 - m; i++) { flag = true; for (int j = i; j <= i + m - 1; j++) flag = flag && (current.a[j] >= 2); if (flag) { for (int k = i; k <= i + m - 1; k++) { current.a[k] -= 2; playCards.a[k] += 2; } return; } } } if (current.A.doublesum) { for (int i = 0; i <= 14; i++) { if (current.a[i] == 2) { current.a[i] -= 2; playCards.a[i] += 2; return; } } } if (current.A.quatrasum) { for (int i = 0; i <= 14; i++) { if (current.a[i] == 4) { current.a[i] -= 4; playCards.a[i] += 4; return; } } } if (current.a[joker] && current.a[JOKER]) { current.a[joker] = current.a[JOKER] = 0; playCards.a[joker] = playCards.a[JOKER] = 1; return; } else { for (int i = 0; i <= 14; i++) { if (current.a[i] == 1) { current.a[i]--; playCards.a[i]++; return; } } } } } void NewData::processPlay(NewData& current, NewData& playCards, NewData& otherPlay) { for (int i = 0; i <= 14; i++) playCards.a[i] = 0; int flag = true; switch (otherPlay.A.sum) { case 1: { int min = otherPlay.find(1, -1); int max = current.find(1, min, 1); if (max != 0) playCards.a[max]++; else current.otherwise(playCards); }break; case 2: { if (otherPlay.a[joker] && otherPlay.a[JOKER]); else { int min = otherPlay.find(2, -1); int max = current.find(2, min, 1); if (max != 0) playCards.a[max] += 2; else current.otherwise(playCards); } }break; case 3: { int min = otherPlay.find(3, -1); int max = current.find(3, min, 1); if (max != 0) playCards.a[max] += 3; else current.otherwise(playCards); }break; case 4: { if (otherPlay.A.triplesum&¤t.A.sum >= 4) { int min = otherPlay.find(3, -1); int max = current.find(3, min, 1); if (max != 0) { int max1 = current.find(1, -1, 1); playCards.a[max1]++; playCards.a[max] += 3; } } else if (!otherPlay.A.quatrasum) current.otherwise(playCards); else { int min = otherPlay.find(4, -1); int max = current.find(4, min); if (max != 0) playCards.a[max] += 4; else if (current.a[joker] && current.a[JOKER]) playCards.a[joker] = 1, playCards.a[JOKER] = 1; } }break; default: { if (otherPlay.A.triplesum == 1 && otherPlay.A.doublesum == 1) { int min = otherPlay.find(3, -1); int max = current.find(3, min, 1); if (max != 0 && (current.A.doublesum || current.A.quatrasum || current.A.triplesum - 1)) { int max1 = current.find(2, -1, 1); playCards.a[max1] += 2; playCards.a[max] += 3; } else current.otherwise(playCards); } else if (otherPlay.A.doublesum * 2 == otherPlay.A.sum) { int min = otherPlay.find(2, -1); int i; for (i = min + 1; i + otherPlay.A.doublesum - 1 <= 12; i++) { flag = true; for (int j = 0; j <= otherPlay.A.doublesum - 1; j++) flag = flag && (current.a[i + j] >= 2); if (flag) { for (int k = i; k - i <= otherPlay.A.doublesum - 1; k++) playCards.a[k] += 2; return; } } current.otherwise(playCards); } else if (otherPlay.A.singlesum == otherPlay.A.sum) { int min = otherPlay.find(1, -1); int i; for (i = min + 1; i + otherPlay.A.singlesum - 1 <= 12; i++) { flag = true; for (int j = 0; j <= otherPlay.A.singlesum - 1; j++) flag = flag && (current.a[i + j] >= 1); if (flag) { for (int k = i; k - i <= otherPlay.A.singlesum - 1; k++) playCards.a[k]++; return; } } current.otherwise(playCards); } else if (otherPlay.A.triplesum >= 2) { if (current.A.triplesum + current.A.quatrasum >= otherPlay.A.triplesum&¤t.A.sum >= otherPlay.A.sum) { int min = otherPlay.find(3, -1), i, remain = otherPlay.A.sum % 4, num = 0; for (i = min + 1; i + otherPlay.A.triplesum - 1 <= 12; i++) { flag = true; for (int j = 0; j <= otherPlay.A.triplesum - 1; j++) flag = flag && (current.a[i + j] >= 3); if (flag) { for (int k = i; k - i <= otherPlay.A.triplesum - 1; k++) { playCards.a[k] += 3; current.a[k] -= 3; } if (remain == 0) { for (int j = otherPlay.A.triplesum; j >= 1; j--) for (int i = 0; i <= 14; i++) if (current.a[i] >= 1) { playCards.a[i]++; current.a[i]--; break; } } else { for (int i = 0; i <= 12; i++) if (current.a[i] >= 2) num++; if (num >= otherPlay.A.triplesum) { for (int j = otherPlay.A.triplesum; j >= 1; j--) for (int i = 0; i <= 12; i++) if (current.a[i] >= 2) { current.a[i] -= 2; playCards.a[i] += 2; break; } } else { for (int k = i; k - i <= otherPlay.A.triplesum - 1; k++) { current.a[k] += 3; playCards.a[k] -= 3; } } } return; } } } current.otherwise(playCards); } else if (otherPlay.A.sum == 6 || otherPlay.A.sum == 8 && otherPlay.A.quatrasum >= 1) { int min = otherPlay.find(4, -1); int max = current.find(4, min); if (max == 0) current.otherwise(playCards); else { if (otherPlay.A.sum == 6 && current.A.sum >= otherPlay.A.sum) { playCards.a[max] += 4; for (int j = 2; j >= 1; j--) for (int i = 0; i <= 14; i++) if (current.a[i] >= 1) { playCards.a[i]++; break; } return; } else if (otherPlay.A.sum == 8 && current.A.doublesum + (current.A.quatrasum - 1) * 2 + current.A.triplesum >= 2) { playCards.a[max] += 4; for (int j = 2; j >= 1; j--) for (int i = 0; i <= 12; i++) if (current.a[i] >= 2) { playCards.a[i] += 2; break; } return; } } current.otherwise(playCards); } } } }