Hand k00pa::AskMove(GameState state) { Hand table = state.table; Hand myHand; if(table.value == CARDS::PASS) { int highest = GetHighestCard(); int amount = CountCard(highest); myHand.value = highest; myHand.amount = amount; myHand.jesters = 0; return myHand; } else if(table.value == CARDS::DALMUTI) { return Hand(); } else { //myHand.value = i; ei toimi //myHand.amount = CountCard(i); myHand.jesters = 0; return myHand; } return Hand(); }
Card* PlayerUser::PassPlayBreakSuit(int card, int leadingSuit, bool& heartsBroken) { //if the player CAN still follow suit for (int i = 0; i < Hand()->Size() -1; i++) if (Hand()->Read(i)->GetSuit() == leadingSuit) return NULL; if (Hand()->Read(card)->GetSuit() == Card::HEARTS) heartsBroken = true; return Hand()->Pass(card); }
Player::Player(int money) { if (money < 0) throw new exception("Invalid amount of money"); this->money = money; this->hands.push_back(Hand()); }
Card* PlayerUser::PassPlayCard(int mouseX, int mouseY, int leadingSuit, int trickCount, bool& heartsBroken) { //find the selected card int card = -1; for (int index = 0; index < Hand()->Size();index++) { if (mouseX < Hand()->Read(index)->GetX()) continue; if (mouseY < Hand()->Read(index)->GetY()) continue; if (mouseX > Hand()->Read(index)->GetX() + Hand()->Read(index)->GetWidth()) continue; if (mouseY > Hand()->Read(index)->GetY() + Hand()->Read(index)->GetHeight()) continue; card = index; } if (card == -1) return NULL; //rules if (trickCount == 0) return PassPlayFirstTrick(card,leadingSuit); Card* c = PassPlayFollowSuit(card, leadingSuit, heartsBroken); if (c != NULL) return c; /* Cannot lead a heart exception, from PassPlayFollowSuit() */ if (leadingSuit == -1) return NULL; return PassPlayBreakSuit(card,leadingSuit,heartsBroken); }
void PlayerUser::SelectSwapCard(int mouseX, int mouseY) { //get the index of the card at (x,y) int card = -1; for (int index = 0; index < Hand()->Size();index++) { if (mouseX < Hand()->Read(index)->GetX()) continue; if (mouseY < Hand()->Read(index)->GetY()) continue; if (mouseX > Hand()->Read(index)->GetX() + Hand()->Read(index)->GetWidth()) continue; if (mouseY > Hand()->Read(index)->GetY() + Hand()->Read(index)->GetHeight()) continue; card = index; } //select or deselect the card found if (card != -1 && !CheckSwapCards(card) && CountSwapCards() < 3) { AddSwapCards(card); ShiftCard(card,0,-20); } else if (card != -1 && CheckSwapCards(card)) { RemoveSwapCards(card); ShiftCard(card,0,20); } }
Player::Player( uint playerNum ) : m_chips( 1000 ), m_playerNum( playerNum ) { // Create the default hand m_hands.push_back( Hand( m_hands.size() + 1 ) ); // Create the default bet placeholder m_currentBets.push_back( 0 ); // Create the default handstatus placeholder m_handStatuses.push_back( Hit ); }
// Get the visible part of the hand as a new hand Hand Hand::GetVisible() { Hand vis_hand = Hand(); for (auto & card : hand) { if (card.m_isFaceUp) vis_hand.AddCard(card); } return vis_hand; }
void botmeld(){ sortcard(&Hand(player_who_play),1); addressCard T = First(Hand(player_who_play)); addressCard X = NULL; while(T != NULL){ int t = trees(Hand(player_who_play),Card(T)); int i = 1; if(t>2){ while(i <= t){ X = T; T = Next(T); doMeld(Card(X)); i++; } }else{ T = Next(T); } } }
/////////// // Reset // /////////// void Player::Reset() { // Clear hands & bets & handstatuses m_hands.clear(); m_hands.push_back( Hand( m_hands.size() + 1 ) ); m_currentBets.clear(); m_currentBets.push_back( 0 ); m_handStatuses.clear(); m_handStatuses.push_back( Hit ); }
/////////////// // SplitHand // /////////////// void Player::SplitHand( uint handIndex ) { Card topCard = m_hands[ handIndex ].RemoveTopCard(); m_hands.push_back( Hand( topCard, m_hands.size() + 1 ) ); // Copy bet from hand being split to new partial hand m_currentBets.push_back( m_currentBets[ handIndex ] ); m_chips -= m_currentBets[ handIndex ]; // Create the default handstatus placeholder for the new partial hand m_handStatuses.push_back( Hit ); }
infoCard whichcardoff(){ addressCard O = First(Hand(player_who_play)); addressCard R = O; int tree = trees(Hand(player_who_play),Card(O)); int poin = point(Card(O)); while(O != NULL){ int t = trees(Hand(player_who_play),Card(O)); int p = point(Card(O)); if(t<tree){ R = O; tree = t; poin = p; }else if(t==tree && p>poin){ R = O; poin = p; } O = Next(O); } return Card(R); }
Card* PlayerUser::PassPlayFollowSuit(int card, int leadingSuit, bool heartsBroken) { //The Queen of spades CAN be played first, and CAN follow suit without breaking hearts //leading the suit if (leadingSuit == -1) { if (heartsBroken) return Hand()->Pass(card); else { if (Hand()->Read(card)->GetSuit() != Card::HEARTS) return Hand()->Pass(card); else return NULL; } } //if the player is following suit if (Hand()->Read(card)->GetSuit() == leadingSuit) return Hand()->Pass(card); //when the card does not follow suit return NULL; }
bool Method::WhetherToBeat(QList<card> &myCards) { if (myCards.isEmpty()) return true; Player* hitPlayer = m_player->getHitPlayer(); QList<card> hitCards = m_player->getHitCards(); if (m_player->getRole() == hitPlayer->getRole()) // punch的是同家 { QList<card> left = m_cards; for(int i=0;i<myCards.size();i++) left.removeOne(myCards[i]); if (Hand(left).getHandType() != Hand_Unknown) return true; CardPoint basePoint = CardPoint(Hand(myCards).getBasePoint()); if (basePoint == Card_2 || basePoint == Card_SJ || basePoint == Card_BJ) { return false; } } else // punch的是对家 { Hand myHand(myCards); if ( (myHand.getHandType() == Hand_Triple_Single || myHand.getHandType() == Hand_Triple_Pair) && (myHand.getBasePoint() == Card_2) ) // 三个2就不打出去了 { return false; } if (myHand.getHandType() == Hand_Pair && myHand.getBasePoint() == Card_2 && hitPlayer->getCards().size() >= 10 && m_player->getCards().size() >= 5) { return false; } } return true; }
Card* PlayerUser::PassPlayFirstTrick(int card, int leadingSuit) { //2 of clubs if ( ISCARD(Hand()->Read(),TWO,CLUBS) ) { //if I have the two of clubs if ( ISCARD(Hand()->Read(card),TWO,CLUBS) ) //and I've selected the two of clubs return Hand()->Pass(); else return NULL; } //follow suit if (Hand()->Read(card)->GetSuit() == leadingSuit) //if I've selected the correct suit return Hand()->Pass(card); //if I haven't selected the correct suit for (int i = 0; i < Hand()->Size() -1; i++) if (Hand()->Read(i)->GetSuit() == leadingSuit) //The correct suit is in my hand return NULL; //can't follow suit, no penalty cards if (Hand()->Read(card)->GetSuit() != Card::HEARTS && !ISCARD(Hand()->Read(card),QUEEN,SPADES)) return Hand()->Pass(card); return NULL; }
/************************** 函数名称:setWifi 函数作用:发送wifi的一些指令 函数参数:cmd发送的参数 str需要匹配的数据 函数备注: ***************************/ bit setWifi(int cmd,unsigned char *str) { int i=0; while(!Hand(str)) { CLR_Buf(); sendCmd(cmd); DelayMS(5000); U1SendString(Rec_Buf); if(Hand("no change")|Hand("CONNECT")) //如果是no change 或者是Linked就直接返回 { break; } if(++i == 5) { goto out; } } CLR_Buf(); return true; out: CLR_Buf(); return false; }
int main(int argc, const char * argv[]) { ifstream file("../instr/prog3.dat"); if (!file.is_open()) { cerr << "Error opening file please ensure the data file is in the proper location.\n"; return -2; } string line; while (!file.eof()) { getline(file, line); Hand currentHand = Hand(line); } file.close(); cout<<"No more hands, File is closed"<<endl; return 0; }
void Listener::onFrame( const Leap::Controller& controller ) { lock_guard<mutex> lock( *mMutex ); if ( !mNewFrame ) { const Leap::Frame& controllerFrame = controller.frame(); const Leap::HandList& hands = controllerFrame.hands(); HandMap handMap; for ( const Leap::Hand& hand : hands ) { FingerMap fingerMap; ToolMap toolMap; const Leap::PointableList& pointables = hand.pointables(); for ( const Leap::Pointable& pt : pointables ) { if ( pt.isValid() ) { Pointable pointable( pt ); if ( pt.isFinger() ) { fingerMap[ pt.id() ] = Finger( pointable ); } else if ( pt.isTool() ) { toolMap[ pt.id() ] = Tool( pointable ); } } } float rotAngle = (float)hand.rotationAngle( mFirstFrame.mFrame ); Vec3f rotAxis = toVec3f( hand.rotationAxis( mFirstFrame.mFrame ) ); Matrix44f rotMatrix = toMatrix44f( hand.rotationMatrix( mFirstFrame.mFrame ) ); float scale = (float)hand.scaleFactor( mFirstFrame.mFrame ); Vec3f translation = toVec3f( hand.translation( mFirstFrame.mFrame ) ); handMap[ hand.id() ] = Hand( hand, fingerMap, toolMap, rotAngle, rotAxis, rotMatrix, scale, translation ); } mFrame = Frame( controllerFrame, handMap ); if ( !mFirstFrameReceived ) { mFirstFrame = Frame( controllerFrame, handMap ); mFirstFrameReceived = true; } mNewFrame = true; } }
addressCard whichcardtake(){ int i = 1; int biggest = 0; addressCard T = First(card_on_off); addressCard B = NULL; while(T != NULL && i<=7){ ClearListCard(&temp_card); addressCard C = First(Hand(player_who_play)); while(C != NULL){ AddCard(&temp_card,Card(C)); C = Next(C); } if(trees(temp_card,Card(T))>2){ addressCard O = First(card_on_off); while(O != NULL){ AddCard(&temp_card,Card(O)); if((SameCard(Card(O),Card(T))==1)){ break; } O = Next(O); } } if(B == NULL){ B = T; biggest = trees(temp_card,Card(T)); }else{ if(biggest<trees(temp_card,Card(T))){ B = T; biggest = trees(temp_card,Card(T)); } } T = Next(T); i++; } if(biggest<3){ B = NULL; } return B; }
void Method::PickSeqSingles(QList<QList<QList<card> > >& allSeqRecord, const QList<QList<card> >& seqInherited, QList<card> cards) { QList<QList<card> > allSeqScheme = Method(m_player, cards).FindHand(Hand(Hand_Seq_Single, Card_Begin, 0), false); if (allSeqScheme.isEmpty()) { allSeqRecord << seqInherited; } else { QList<card> savedCards = cards; for (int i = 0; i < allSeqScheme.size(); i++) { QList<card> aScheme = allSeqScheme[i]; QList<card> leftCards = savedCards; for(int j=0;j<aScheme.size();j++) leftCards.removeOne(aScheme[j]); QList<QList<card> > seqArray = seqInherited; seqArray.append(aScheme); PickSeqSingles(allSeqRecord, seqArray, leftCards); } } }
//-------------------------------------------------------------- void JiveScreen::draw() { currentPlayerPos = player.getPositionMS(); if(player.getPosition() < 1.0) { currentPlayerPos = roundUp(currentPlayerPos/100); cout << currentPlayerPos << endl; // INDIVIDUAL PRACTICE ------------------------------------ if(currentPlayerPos >= startPlayerPos_R1 && currentPlayerPos <= stopPlayerPos_R1) { updateChoreoPosition(role, currentStep, true, true, false, false); if(role[currentStep][4] == 1){ intervall = intervall1/2; }else{ intervall = intervall1; } if(prevPlayerPos+intervall >= currentPlayerPos-4 && prevPlayerPos+intervall <= currentPlayerPos) { currentStep++; if(currentStep > 7) currentStep = 0; isStart = false; prevPlayerPos = currentPlayerPos; // reset history footPositions.clear(); } // WAIT FOR NEXT PART ------------------------------------- }else if (currentPlayerPos >= stopPlayerPos_R1 && currentPlayerPos <= startPlayerPos_R2) { standardPosition(role, 7, cX1, cY1, cX2, cY2); } // MOVE FORWARDS ------------------------------------------ else if (currentPlayerPos >= startPlayerPos_R2 && currentPlayerPos <= stopPlayerPos_R2) { if(currentPlayerPos >= startPlayerPos_R2 && currentPlayerPos <= startPlayerPos_R2+4) { standardPosition(role, 7, cX1, cY1, cX2, cY2); footPositions.clear(); } // recalculate intervall if(role[currentStep][4] == 1){ intervall = intervall1/2; }else{ intervall = intervall1; } // FOOT 1 // animate 1st if(currentPlayerPos >= startPlayerPos_R2 && currentPlayerPos < startPlayerPos_R2+intervall) { mStepA = 7; mStepB = 6; // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); mFootA = moveForwardsMaster(role, mStepA, 'm'); ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2, cY1); ofRotateZ(config.rotateZ); moveForwardsSlave(mFootA, role, mStepA, 'f'); ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX3, cY2); ofRotateZ(config.rotateZ-180); moveForwardsSlave(mFootA, role, mStepA, 'm'); ofPopMatrix(); // follower 2 ofPushMatrix(); ofTranslate(cX4, cY2); ofRotateZ(config.rotateZ-180); moveForwardsSlave(mFootA, role, mStepA, 'f'); ofPopMatrix(); } // FOOT 2 // reset for next foot if(currentPlayerPos >= startPlayerPos_R2+intervall && currentPlayerPos <= startPlayerPos_R2+intervall+4) { footPositions.clear(); } // display 1st and animate 2nd if(currentPlayerPos >= startPlayerPos_R2+intervall && currentPlayerPos < startPlayerPos_R2+intervall+intervall) { // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), 'm', config.iconSize); // right foot ofTranslate(-boxWidth*2/7, 0); mFootB = moveForwardsMaster(role, mStepB, 'm'); // left foot ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2, cY1); ofRotateZ(config.rotateZ); Foot(mFootA.x, mFootA.y-2*config.distanceMoveJive, getStepSide(role, mStepA), 'f', config.iconSize); // left ofTranslate(-boxWidth*2/7, 0); moveForwardsSlave(mFootB, role, mStepB, 'f'); // right ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX3, cY2); ofRotateZ(config.rotateZ-180); Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), 'm', config.iconSize); // right foot ofTranslate(-boxWidth*2/7, 0); moveForwardsSlave(mFootB, role, mStepB, 'm'); // left foot ofPopMatrix(); // follower 2 ofPushMatrix(); ofTranslate(cX4, cY2); ofRotateZ(config.rotateZ-180); Foot(mFootA.x, mFootA.y-2*config.distanceMoveJive, getStepSide(role, mStepA), 'f', config.iconSize); // left ofTranslate(-boxWidth*2/7, 0); moveForwardsSlave(mFootB, role, mStepB, 'f'); // right ofPopMatrix(); } // FINAL MOVE FORWARD FEET // display if(currentPlayerPos >= startPlayerPos_R2+intervall+intervall) { // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); mGender = 'm'; Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y+65, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-160, mFootB.y+50, 'l', mGender, config.iconSize); ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2, cY1); ofRotateZ(config.rotateZ); mGender = 'f'; Foot(mFootA.x, mFootA.y-2*config.distanceMoveJive, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y-2*config.distanceMoveJive-55, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y-2*config.distanceMoveJive, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-130, mFootB.y-2*config.distanceMoveJive-80, 'l', mGender, config.iconSize); ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX3, cY2); ofRotateZ(config.rotateZ-180); mGender = 'm'; Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y+70, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-160, mFootB.y+50, 'l', mGender, config.iconSize); ofPopMatrix(); // follower 2 ofPushMatrix(); ofTranslate(cX4, cY2); ofRotateZ(config.rotateZ-180); mGender = 'f'; Foot(mFootA.x, mFootA.y-2*config.distanceMoveJive, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y-2*config.distanceMoveJive-55, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y-2*config.distanceMoveJive, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-130, mFootB.y-2*config.distanceMoveJive-80, 'l', mGender, config.iconSize); ofPopMatrix(); } } // PARTNER PRACTICE --------------------------------------- else if(currentPlayerPos >= startPlayerPos_R3 && currentPlayerPos <= stopPlayerPos_R3) { if(currentPlayerPos >= startPlayerPos_R3 && currentPlayerPos <= startPlayerPos_R3+4) { prevPlayerPos = currentPlayerPos; currentStep = 0; footPositions.clear(); } if(role[currentStep][4] == 1){ intervall = intervall2/2 - 1; }else{ intervall = intervall2; } //cout << currentPlayerPos << " -> do " << currentStep << " :: prev " << positionPrev << " - curr " << positionCurr << " :: prevStep of side: " << previousSideStep << endl; updateChoreoPosition(role, currentStep, true, false, true, false); //cout << prevPlayerPos << " + " << intervall << " >=< " << currentPlayerPos << endl; if(prevPlayerPos+intervall >= currentPlayerPos-4 && prevPlayerPos+intervall <= currentPlayerPos) { currentStep++; if(currentStep > 7) currentStep = 0; isStart = false; prevPlayerPos = currentPlayerPos; // reset history footPositions.clear(); } // BRIDGE TO FAST PART ------------------------------------ }else if (currentPlayerPos >= stopPlayerPos_R3 && currentPlayerPos <= startPlayerPos_R4) { // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); mGender = 'm'; Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y+65, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-160, mFootB.y+50, 'l', mGender, config.iconSize); ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2, cY1); ofRotateZ(config.rotateZ); mGender = 'f'; Foot(mFootA.x, mFootA.y-2*config.distanceMoveJive, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y-2*config.distanceMoveJive-55, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y-2*config.distanceMoveJive, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-130, mFootB.y-2*config.distanceMoveJive-80, 'l', mGender, config.iconSize); ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX3, cY2); ofRotateZ(config.rotateZ-180); mGender = 'm'; Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y+70, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-160, mFootB.y+50, 'l', mGender, config.iconSize); ofPopMatrix(); // follower 2 ofPushMatrix(); ofTranslate(cX4, cY2); ofRotateZ(config.rotateZ-180); mGender = 'f'; Foot(mFootA.x, mFootA.y-2*config.distanceMoveJive, getStepSide(role, mStepA), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y-2*config.distanceMoveJive-55, 'r', mGender, config.iconSize); ofTranslate(-boxWidth*2/7, 0); Foot(mFootB.x, mFootB.y-2*config.distanceMoveJive, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootB.x-130, mFootB.y-2*config.distanceMoveJive-80, 'l', mGender, config.iconSize); ofPopMatrix(); } // PARTNER PRACTICE - FAST -------------------------------- else if(currentPlayerPos >= startPlayerPos_R4 && currentPlayerPos <= stopPlayerPos_R4) { if(currentPlayerPos >= startPlayerPos_R4 && currentPlayerPos <= startPlayerPos_R4+4) { prevPlayerPos = currentPlayerPos; currentStep = 0; footPositions.clear(); } if(role[currentStep][4] == 1){ intervall = intervall3/2; }else{ intervall = intervall3; } //cout << currentPlayerPos << " -> do " << currentStep << " :: prev " << positionPrev << " - curr " << positionCurr << " :: prevStep of side: " << previousSideStep << endl; updateChoreoPosition(role, currentStep, true, false, true, false); //cout << prevPlayerPos << " + " << intervall << " >=< " << currentPlayerPos << endl; if(prevPlayerPos+intervall >= currentPlayerPos-4 && prevPlayerPos+intervall <= currentPlayerPos) { currentStep++; if(currentStep > 7) currentStep = 0; isStart = false; prevPlayerPos = currentPlayerPos; // reset history footPositions.clear(); } } // WAIT FOR NEXT PART ------------------------------------- else if(currentPlayerPos <= stopPlayerPos_R4 && currentPlayerPos != 0) { standardPosition(role, 7, cX1, cY1, cX2, cY2); } } }
QList<QList<card> > Method::FindHand(Hand hand, bool beat) { HandType handType = hand.getHandType(); CardPoint basePoint = CardPoint(hand.getBasePoint()); int extra = hand.getExtra(); if (handType == Hand_Pass) {} else if (handType == Hand_Single) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point < Card_End; point = CardPoint(point + 1)) { QList<card> findCards = FindSamePointCards(point, 1); if (!findCards.isEmpty()) { findCardsArray.append(findCards); } } return findCardsArray; } else if (handType == Hand_Pair) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point < Card_End; point = CardPoint(point + 1)) { QList<card> findCards = FindSamePointCards(point, 2); if (!findCards.isEmpty()) { findCardsArray.append(findCards); } } return findCardsArray; } else if (handType == Hand_Triple) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point < Card_End; point = CardPoint(point + 1)) { QList<card> findCards = FindSamePointCards(point, 3); if (!findCards.isEmpty()) { findCardsArray.append(findCards); } } return findCardsArray; } else if (handType == Hand_Triple_Single) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point < Card_End; point = CardPoint(point + 1)) { QList<card> findCards = FindSamePointCards(point, 3); if (!findCards.isEmpty()) { findCardsArray.append(findCards); } } if (!findCardsArray.isEmpty()) { QList<card> remainCards = m_cards; for(int i=0;i<findCardsArray.size();i++) { for(int j=0;j<findCardsArray[i].size();j++) remainCards.removeOne((findCardsArray[i])[j]); } //remainCards.Remove(findCardsArray); Method st(m_player, remainCards); QList<QList<card> > oneCardsArray = st.FindHand(Hand(Hand_Single, Card_Begin, 0), false); if (!oneCardsArray.isEmpty()) { for (int i = 0; i < findCardsArray.size(); i++) { findCardsArray[i] .append(oneCardsArray[0]); } } else { findCardsArray.clear(); } } return findCardsArray; } else if (handType == Hand_Triple_Pair) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point < Card_End; point = CardPoint(point + 1)) { QList<card> findCards = FindSamePointCards(point, 3); if (!findCards.isEmpty()) { findCardsArray << findCards; } } if (!findCardsArray.isEmpty()) { QList<card> remainCards = m_cards; for(int i=0;i<findCardsArray.size();i++) for(int j=0;j<findCardsArray[i].size();j++) remainCards.removeOne(findCardsArray[i][j]); // remainCards.Remove(findCardsArray); Method st(m_player, remainCards); QList<QList<card> > pairCardsArray = st.FindHand(Hand(Hand_Pair, Card_Begin, 0), false); if (!pairCardsArray.isEmpty()) { for (int i = 0; i < findCardsArray.size(); i++) { findCardsArray[i].append(pairCardsArray[0]); } } else { findCardsArray.clear(); } } return findCardsArray; } else if (handType == Hand_Plane) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point <= Card_K; point = CardPoint(point + 1)) { QList<card> prevCards = FindSamePointCards(point, 3); QList<card> nextCards = FindSamePointCards(CardPoint(point+1), 3); if (!prevCards.isEmpty() && !nextCards.isEmpty()) { findCardsArray.append(prevCards); findCardsArray.append(nextCards); } } } else if (handType == Hand_Plane_Two_Single) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point <= Card_K; point = CardPoint(point + 1)) { QList<card> prevCards = FindSamePointCards(point, 3); QList<card> nextCards = FindSamePointCards(CardPoint(point+1), 3); if (!prevCards.isEmpty() && !nextCards.isEmpty()) { QList<card> findCards; findCards.append(prevCards); findCards.append(nextCards); findCardsArray.append(findCards); } } if (!findCardsArray.isEmpty()) { QList<card> remainCards = m_cards; for(int i=0;i<findCardsArray.size();i++) { for(int j=0;j<findCardsArray[i].size();j++) remainCards.removeOne((findCardsArray[i])[j]); } Method st(m_player, remainCards); QList<QList<card> > oneCardsArray = st.FindHand(Hand(Hand_Single, Card_Begin, 0), false); if (oneCardsArray.size() >= 2) { for (int i = 0; i < findCardsArray.size(); i++) { QList<card> oneCards; oneCards.append(oneCardsArray[0]); oneCards.append(oneCardsArray[1]); findCardsArray[i] << oneCards; } } else { findCardsArray.clear(); } } return findCardsArray; } else if (handType == Hand_Plane_Two_Pair) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point <= Card_K; point = CardPoint(point + 1)) { QList<card> prevCards = FindSamePointCards(point, 3); QList<card> nextCards = FindSamePointCards(CardPoint(point+1), 3); if (!prevCards.isEmpty() && !nextCards.isEmpty()) { QList<card> findCards; findCards << prevCards << nextCards; findCardsArray << findCards; } } if (!findCardsArray.isEmpty()) { QList<card> remainCards = m_cards; for(int i=0;i<findCardsArray.size();i++) { for(int j=0;j<findCardsArray[i].size();j++) remainCards.removeOne((findCardsArray[i])[j]); } Method st(m_player, remainCards); QList<QList<card> > pairCardsArray = st.FindHand(Hand(Hand_Pair, Card_Begin, 0), false); if (pairCardsArray.size() >= 2) { for (int i = 0; i < findCardsArray.size(); i++) { QList<card> pairCards; pairCards << pairCardsArray[0] << pairCardsArray[1]; findCardsArray[i] << pairCards; } } else { findCardsArray.clear(); } } return findCardsArray; } else if (handType == Hand_Seq_Pair) { if (beat) { QList<QList<card> > findCardsArray; for (CardPoint point = CardPoint(basePoint + 1); point <= Card_Q; point = CardPoint(point + 1)) { bool seqPairFound = true; QList<card> seqPair; for (int i = 0; i < extra; i++) { QList<card> cards = FindSamePointCards(CardPoint(point + i), 2); if (cards.isEmpty() || (point + i >= Card_2)) // 连对中断,或顶到2了 { seqPairFound = false; seqPair.clear(); break; } else { seqPair << cards; } } if (seqPairFound) { findCardsArray << seqPair; return findCardsArray; } } return findCardsArray; } else { QList<QList<card> > findCardsArray; for (CardPoint point = Card_3; point <= Card_Q; point = CardPoint(point + 1)) { QList<card> cards0 = FindSamePointCards(point, 2); QList<card> cards1 = FindSamePointCards(CardPoint(point + 1), 2); QList<card> cards2 = FindSamePointCards(CardPoint(point + 2), 2); if (cards0.isEmpty() || cards1.isEmpty() || cards2.isEmpty()) continue; QList<card> baseSeq; baseSeq << cards0 << cards1 << cards2; findCardsArray << baseSeq; int followed = 3; QList<card> alreadyFollowedCards; while (true) { CardPoint followedPoint = CardPoint(point + followed); if (followedPoint >= Card_2) { break; } QList<card> followedCards = FindSamePointCards(followedPoint, 2); if (followedCards.isEmpty()) { break; } else { alreadyFollowedCards << followedCards; QList<card> newSeq = baseSeq; newSeq << alreadyFollowedCards; findCardsArray << newSeq; followed++; } } } return findCardsArray; } } else if (handType == Hand_Seq_Single) { if (beat) { QList<QList<card> > findCardsArray; for (CardPoint point = CardPoint(basePoint + 1); point <= Card_10; point = CardPoint(point + 1)) { bool seqSingleFound = true; QList<card> seqSingle; for (int i = 0; i < extra; i++) { QList<card> cards = FindSamePointCards(CardPoint(point + i), 1); if (cards.isEmpty() || (point + extra >= Card_2)) { seqSingleFound = false; seqSingle.clear(); break; } else { seqSingle << cards; } } if (seqSingleFound) { findCardsArray << seqSingle; return findCardsArray; } } } else { QList<QList<card> > findCardsArray; for (CardPoint point = Card_3; point <= Card_10; point = CardPoint(point + 1)) { QList<card> cards0 = FindSamePointCards(point, 1); QList<card> cards1 = FindSamePointCards(CardPoint(point + 1), 1); QList<card> cards2 = FindSamePointCards(CardPoint(point + 2), 1); QList<card> cards3 = FindSamePointCards(CardPoint(point + 3), 1); QList<card> cards4 = FindSamePointCards(CardPoint(point + 4), 1); if (cards0.isEmpty() || cards1.isEmpty() || cards2.isEmpty() || cards3.isEmpty() || cards4.isEmpty()) { continue; } QList<card> baseSeq; baseSeq << cards0 << cards1 << cards2 << cards3 << cards4; findCardsArray << baseSeq; int followed = 5; QList<card> alreadyFollowedCards; while (true) { CardPoint followedPoint = CardPoint(point + followed); if (followedPoint >= Card_2) { break; } QList<card> followedCards = FindSamePointCards(followedPoint, 1); if (followedCards.isEmpty()) { break; } else { alreadyFollowedCards << followedCards; QList<card> newSeq = baseSeq; newSeq << alreadyFollowedCards; findCardsArray << newSeq; followed++; } } } return findCardsArray; } } else if (handType == Hand_Bomb) { QList<QList<card> > findCardsArray; CardPoint beginPoint = beat ? CardPoint(basePoint + 1) : CardPoint(Card_Begin + 1); for (CardPoint point = beginPoint; point < Card_End; point = CardPoint(point + 1)) { QList<card> findCards = FindSamePointCards(point, 4); if (!findCards.isEmpty()) { findCardsArray << findCards; } } return findCardsArray; } QList<QList<card> > c; c.clear(); return c; }
QList<card> Method::PlayFirst() { Hand hand(m_cards); if (hand.getHandType() != Hand_Unknown) // 只剩一手牌,直接出完 { return m_cards; } QList<card> seqSingleRange = GetFirstSeqSingleRange(); if (!seqSingleRange.isEmpty()) { QList<card> left = seqSingleRange; //清除炸弹和三个 QList<QList<card> > cards4=Method(m_player,left).FindCardsByCount(4); for(int i=0;i<cards4.size();i++) for(int j=0;j<cards4[i].size();j++) left.removeOne(cards4[i][j]); QList<QList<card> > cards3=Method(m_player,left).FindCardsByCount(3); for(int i=0;i<cards3.size();i++) for(int j=0;j<cards3[i].size();j++) left.removeOne(cards3[i][j]); // left.Remove(Method(m_player, left).FindCardsByCount(4)); // left.Remove(Strategy(m_player, left).FindCardsByCount(3)); QList<QList<card> > optimalSeq = Method(m_player, left).PickOptimalSeqSingles(); if (!optimalSeq.isEmpty()) { int oriSingleCount = Method(m_player, left).FindCardsByCount(1).size(); //left.Remove(optimalSeq); for(int i=0;i<optimalSeq.size();i++) for(int j=0;j<optimalSeq[i].size();j++) left.removeOne(optimalSeq[i][j]); int leftSingleCount = Method(m_player, left).FindCardsByCount(1).size(); if (leftSingleCount < oriSingleCount) { return optimalSeq[0]; } } } bool hasPlane, hasTriple, hasSeqPair; hasPlane = hasTriple = hasSeqPair = false; QList<card> leftCards = m_cards; QList<QList<card> > bombArray = Method(m_player, leftCards).FindHand(Hand(Hand_Bomb, Card_Begin, 0), false); //leftCards.Remove(bombArray); for(int i=0;i<bombArray.size();i++) for(int j=0;j<bombArray[i].size();j++) leftCards.removeOne(bombArray[i][j]); QList<QList<card> > planeArray = Method(m_player, leftCards).FindHand(Hand(Hand_Plane, Card_Begin, 0), false); if (!planeArray.isEmpty()) { hasPlane = true; for(int i=0;i<planeArray.size();i++) for(int j=0;j<planeArray[i].size();j++) leftCards.removeOne(planeArray[i][j]); //leftCards.Remove(planeArray); } QList<QList<card> > tripleArray = Method(m_player, leftCards).FindHand(Hand(Hand_Triple, Card_Begin, 0), false); if (!tripleArray.isEmpty()) { hasTriple = true; for(int i=0;i<tripleArray.size();i++) for(int j=0;j<tripleArray[i].size();j++) leftCards.removeOne(tripleArray[i][j]); // leftCards.Remove(tripleArray); } QList<QList<card> > seqPairArray = Method(m_player, leftCards).FindHand(Hand(Hand_Seq_Pair, Card_Begin, 0), false); if (!seqPairArray.isEmpty()) { hasSeqPair = true; for(int i=0;i<seqPairArray.size();i++) for(int j=0;j<seqPairArray[i].size();j++) leftCards.removeOne(seqPairArray[i][j]); //leftCards.Remove(seqPairArray); } if (hasPlane) { bool twoPairFound = false; QList<QList<card> > pairArray; for (CardPoint point = Card_3; point <= Card_A; point = CardPoint(point + 1)) { QList<card> pair = Method(m_player, leftCards).FindSamePointCards(point, 2); if (!pair.isEmpty()) { pairArray << pair; if (pairArray.size() == 2) { twoPairFound = true; break; } } } if (twoPairFound) { QList<card> playCards = planeArray[0]; for(int i=0;i<pairArray.size();i++) for(int j=0;j<pairArray[i].size();j++) playCards.append(pairArray[i][j]); // playCards.Add(pairArray); return playCards; } else { bool twoSingleFound = false; QList<QList<card> > singleArray; for (CardPoint point = Card_3; point <= Card_A; point = CardPoint(point + 1)) { if (CountOfPoint(leftCards,point)==1) //(leftCards.PointCount(point) == 1) { QList<card> single = Method(m_player, leftCards).FindSamePointCards(point, 1); if (!single.isEmpty()) { singleArray << single; if (singleArray.size() == 2) { twoSingleFound = true; break; } } } } if (twoSingleFound) { QList<card> playCards = planeArray[0]; for(int i=0;i<singleArray.size();i++) for(int j=0;j<singleArray[i].size();j++) playCards.append(singleArray[i][j]); // playCards.Add(singleArray); return playCards; } else { return planeArray[0]; } } } if (hasTriple) { if (Hand(tripleArray[0]).getBasePoint() < Card_A) { for (CardPoint point = Card_3; point <= Card_A; point = CardPoint(point + 1)) { int pointCount = CountOfPoint(leftCards,point);//leftCards.PointCount(point); if (pointCount == 1) { QList<card> single = Method(m_player, leftCards).FindSamePointCards(point, 1); if (!single.isEmpty()) { QList<card> playCards = tripleArray[0]; //playCards.Add(single); for(int i=0;i<single.size();i++) playCards.append(single[i]); return playCards; } } else if (pointCount == 2) { QList<card> pair = Method(m_player, leftCards).FindSamePointCards(point, 2); if (!pair.isEmpty()) { QList<card> playCards = tripleArray[0]; // playCards.Add(pair); for(int i=0;i<pair.size();i++) playCards.append(pair[i]); return playCards; } } } return tripleArray[0]; // 找不到合适的带牌,直接出3个 } } if (hasSeqPair) // 打出最长的连对 { QList<card> maxSeqPair; for (int i = 0; i < seqPairArray.size(); i++) { if (seqPairArray[i].size() > maxSeqPair.size()) { maxSeqPair = seqPairArray[i]; } } return maxSeqPair; } Player* nextPlayer = m_player->getNextPlayer(); if (m_player->getRole() != nextPlayer->getRole() && nextPlayer->getCards().size() == 1) { for (CardPoint point = CardPoint(Card_End - 1); point >= Card_3; point = CardPoint(point - 1)) { int pointCount = CountOfPoint(leftCards,point);//leftCards.PointCount(point); if (pointCount == 1) { QList<card> single = Method(m_player, leftCards).FindSamePointCards(point, 1); return single; } else if (pointCount == 2) { QList<card> pair = Method(m_player, leftCards).FindSamePointCards(point, 2); return pair; } } } else { for (CardPoint point = Card_3; point < Card_End; point = CardPoint(point + 1)) { int pointCount = CountOfPoint(leftCards,point);//leftCards.PointCount(point); if (pointCount == 1) { QList<card> single = Method(m_player, leftCards).FindSamePointCards(point, 1); return single; } else if (pointCount == 2) { QList<card> pair = Method(m_player, leftCards).FindSamePointCards(point, 2); return pair; } } } return QList<card> (); }
QList<card> Method::PlayBeatHand(Hand hand) { // 先固定住最优顺子,从余下牌中打出 QList<card> left = m_cards; QList<QList<card> > cardlll=Method(m_player,left).PickOptimalSeqSingles(); for(int i=0;i<cardlll.size();i++) for(int j=0;j<cardlll[i].size();j++ ) left.removeOne(cardlll[i][j]); //left.Remove(Method(m_player, left).PickOptimalSeqSingles()); if (hand.getHandType() == Hand_Single) // 如果压单牌,尽量从单张牌中挑 { QList<QList<card> > singleArray = Method(m_player, left).FindCardsByCount(1); for (int i = 0; i < singleArray.size(); i++) { if (Hand(singleArray[i]).Defeat(hand)) { return singleArray[i]; } } } else if (hand.getHandType() == Hand_Pair) // 如果压双牌,尽量从双牌中挑 { QList<QList<card> > pairArray = Method(m_player, left).FindCardsByCount(2); for (int i = 0; i < pairArray.size(); i++) { if (Hand(pairArray[i]).Defeat(hand)) { return pairArray[i]; } } } Player* nextPlayer = m_player->getNextPlayer(); QList<QList<card> > beatCardsArray = Method(m_player, left).FindHand(hand, true); if (!beatCardsArray.isEmpty()) { if (m_player->getRole() != nextPlayer->getRole() && nextPlayer->getCards().size() <= 2) { return beatCardsArray.back(); } else { return beatCardsArray.front(); } } else // 余下牌没法打时,只好从顺子中挑牌 { beatCardsArray = Method(m_player, m_cards).FindHand(hand, true); if (!beatCardsArray.isEmpty()) { if (m_player->getRole() != nextPlayer->getRole() && nextPlayer->getCards().size() <= 2) { return beatCardsArray.back(); } else { return beatCardsArray.front(); } } } // 对家剩牌小于3张,有炸则炸 Player* hitPlayer = m_player->getHitPlayer(); if (m_player->getRole() != hitPlayer->getRole()) { if (hitPlayer->getCards().size() <= 3) { QList<QList<card> > bombs = FindCardsByCount(4); if (!bombs.isEmpty()) { return bombs[0]; } } } QList<card> empty; empty.clear(); return empty; }
// Detect and Identify the hand gesture present in the image std::vector<Hand> GestureDetector::detect(cv::Mat &image, cv::Mat &filtered) { std::vector<Hand> hands; // find contours in the filtered image std::vector< std::vector<cv::Point> > contours; std::vector<cv::Vec4i> hierarchy; cv::findContours(filtered, contours, // a vector of contours hierarchy, // a hierarchy of contours if there are parent //child relations in the image CV_RETR_EXTERNAL, // retrieve the external contours CV_CHAIN_APPROX_TC89_L1); // an approximation algorithm //------------------Find Face---------------- //preprocess for face recognition std::vector< cv::Rect > faces; cv::Mat gray; //shrink the image for speed cv::resize(image, gray, cv::Size2i(image.cols/4, image.rows/4)); cv::cvtColor(gray, gray, CV_BGR2GRAY); cv::equalizeHist(gray, gray); cascadeFace.detectMultiScale(gray, faces); // draw bounds for faces for (unsigned int i = 0; i < faces.size(); i++ ) { //resize the rectangle to match the image faces[i] += cv::Point(faces[i].x * 3,faces[i].y * 3); faces[i] += faces[i].size() +faces[i].size() +faces[i].size(); rectangle(image, faces[i], cv::Scalar(0,0,204), 3); } //----------------End Face-------------------- //------------Find all skin regions----------- QString join(""); int massMin = 5000, massMax = 24000; // minimum contour mass cv::Scalar color( 100, 150, 255 ); //random color int idx = 0; // iterate through all the top-level contours for( ; idx >= 0; idx = hierarchy[idx][0] ) { // compute all moments and mass cv::Moments mom = cv::moments(cv::Mat(contours[idx])); cv::Point center = cv::Point(mom.m10/mom.m00,mom.m01/mom.m00); int cMass = mom.m00; //calculate the rotated and bounding rectangles of the blobs cv::RotatedRect rotRect = cv::minAreaRect( cv::Mat(contours[idx]) ); cv::Rect bRect = rotRect.boundingRect(); // find intersections of detected faces and blobs bool faceOverlap = false; for(unsigned int i = 0; i < faces.size(); i++) { cv::Rect intersect = faces[i] & bRect; if(intersect.width > 30 || intersect.height > 30) faceOverlap = true; } // Eliminate contours that are too small, // and ones that coincide with one of the found faces if(cMass > massMin && cMass < massMax && !faceOverlap) { Hand curHand(rotRect, mom); hands.push_back(curHand); //push the detected hand onto the list // draw each connected component cv::Mat contourImg(image.size(), image.type(), cv::Scalar(0)); cv::drawContours( contourImg, contours, idx, color, CV_FILLED, 8, hierarchy ); cv::GaussianBlur(contourImg, contourImg, cv::Size(5,5), 0); image += contourImg; // draw bounding rotated rectangles for( int j = 0; j < 4; j++ ) line( image, curHand.rotPoints[j], curHand.rotPoints[(j+1)%4], cv::Scalar(0,102,204), 3, 8 ); rectangle(image, curHand.boxRect, cv::Scalar(0,204,102), 3); } } if(hands.size() == 0) { //if no hands were found create a 'NONE' hand hands.push_back(Hand()); } return hands; }
void MainInterface::PlayingHand(Player* player,QList<card> cards) { HandType type=Hand(cards).getHandType(); switch(type) { case Hand_Pass: handtype=new QSound(":/sound/res/passMusic.wav",this); player->passLabel->show(); break; case Hand_Triple: handtype=new QSound(":/sound/res/sange.wav",this); break; case Hand_Triple_Single: handtype=new QSound(":/sound/res/sandaiyi.wav",this); break; case Hand_Triple_Pair: handtype=new QSound(":/sound/res/sandaiyidui.wav",this); break; case Hand_Plane: case Hand_Plane_Two_Single: case Hand_Plane_Two_Pair: handtype=new QSound(":/sound/res/planeMusic.wav",this); break; case Hand_Bomb: handtype=new QSound(":/sound/res/zhadan.wav",this); break; case Hand_Bomb_Jokers: handtype=new QSound(":/sound/res/bombJokerMusic.wav",this); break; case Hand_Seq_Single: handtype=new QSound(":/sound/res/shunzi.wav",this); break; case Hand_Seq_Pair: handtype=new QSound(":/sound/res/liandui.wav",this); break; case Hand_Single: { switch(cards[0].point) { case Card_A: handtype=new QSound(":/sound/res/1.wav",this); break; case Card_2: handtype=new QSound(":/sound/res/2.wav",this); break; case Card_3: handtype=new QSound(":/sound/res/3.wav",this); break; case Card_4: handtype=new QSound(":/sound/res/4.wav",this); break; case Card_5: handtype=new QSound(":/sound/res/5.wav",this); break; case Card_6: handtype=new QSound(":/sound/res/6.wav",this); break; case Card_7: handtype=new QSound(":/sound/res/7.wav",this); break; case Card_8: handtype=new QSound(":/sound/res/8.wav",this); break; case Card_9: handtype=new QSound(":/sound/res/9.wav",this); break; case Card_10: handtype=new QSound(":/sound/res/10.wav",this); break; case Card_J: handtype=new QSound(":/sound/res/11.wav",this); break; case Card_Q: handtype=new QSound(":/sound/res/12.wav",this); break; case Card_K: handtype=new QSound(":/sound/res/13.wav",this); break; case Card_SJ: handtype=new QSound(":/sound/res/14.wav",this); break; case Card_BJ: handtype=new QSound(":/sound/res/15.wav",this); break; } break; } case Hand_Pair: { switch((int)cards[0].point) { case Card_A: handtype=new QSound(":/sound/res/dui1.wav",this); break; case Card_2: handtype=new QSound(":/sound/res/dui2.wav",this); break; case Card_3: handtype=new QSound(":/sound/res/dui3.wav",this); break; case Card_4: handtype=new QSound(":/sound/res/dui4.wav",this); break; case Card_5: handtype=new QSound(":/sound/res/dui5.wav",this); break; case Card_6: handtype=new QSound(":/sound/res/dui6.wav",this); break; case Card_7: handtype=new QSound(":/sound/res/dui7.wav",this); break; case Card_8: handtype=new QSound(":/sound/res/dui8.wav",this); break; case Card_9: handtype=new QSound(":/sound/res/dui9.wav",this); break; case Card_10: handtype=new QSound(":/sound/res/dui10.wav",this); break; case Card_J: handtype=new QSound(":/sound/res/dui11.wav",this); break; case Card_Q: handtype=new QSound(":/sound/res/dui12.wav",this); break; case Card_K: handtype=new QSound(":/sound/res/dui13.wav",this); break; } break; } } handtype->play(); player->getCardsToPlay()=cards; //写入本次出的牌 UpdateCards(player); //出牌显示效果 }
int main (int argc, char * const argv[]) { // insert code here...this is the main function, it creates a shuffled deck and begin the story srand(time(NULL)); Deck deck1=Deck(); deck1.shuffle(); char ch='y'; int money=100; int moneyevolve[100]={money}; int moneycount=0; cout << "Welcome to BlackJack!\n"; while ((ch=='y' || ch=='Y') && (money>0)) { Hand gnomehand=Hand(); Hand omehand=Hand(); gnomehand.takeacard(deck1); omehand.takeacard(deck1); gnomehand.takeacard(deck1); omehand.takeacard(deck1); cout << "You have $"<< money; cout << endl; int bet=money+10; while (bet>money) { cout << "Please input your bet as a multiple of 10: \n"; cin >> bet; } money-=bet; cout << "Now you have $"<<money<<endl; omehand.display(1); cout << "Your hand: "; gnomehand.display(2); int gnomesum,black=0; gnomesum=gnomehand.sumup(); if (gnomesum==BLACKJACK) { black=1; } else{ cout << "Double down?y/n?\n"; char d; cin >> d; if (d=='y' || d=='Y') { money-=bet; bet*=2; gnomehand.takeacard(deck1); gnomehand.displaynew(); } else { cout << "hit me? y/n?\n"; char c; cin >> c; while (c=='y' || c=='Y') { gnomehand.takeacard(deck1); gnomehand.displaynew(); if (gnomehand.sumup()>=BLACKJACK) { c='n'; } else {cin >>c;} } } } gnomesum=gnomehand.sumup(); cout << "Your sum is :"<< gnomesum<<endl; if (black==1) { cout << "Congratulations! You have blackjack!\n"; } else if (gnomesum>BLACKJACK) { cout << "Busted! ChouChou!\n"; } cout << "Dealers full hand: "; omehand.display(2); int omesum,omeblack=0; omesum=omehand.sumup(); if (omesum==BLACKJACK) { omeblack=1; } else {while (omesum<=16) { omehand.takeacard(deck1); omehand.displaynew(); omesum=omehand.sumup(); } } cout << "Dealer's sum: "<< omesum<<endl; if (omeblack==1) { cout << "Dealer has blackjack!\n"; } else if (omesum>BLACKJACK) { cout << "Dealer busted!\n"; } if (black==1 && omeblack==1 ) { money+=bet; cout << "Both blackjack! Money back!\n"; } else if (black==1) { money+=bet*5/2; cout << "Awesome! Blackjack money!\n"; } else if (gnomesum<=BLACKJACK && omesum>BLACKJACK) { money+=bet*2; cout << "I win!\n"; } else if (gnomesum<=BLACKJACK && gnomesum>omesum) { money+=bet*2; cout << "I win!\n"; } cout << "Now you have $"<< money<< endl; moneycount++; moneyevolve[moneycount]=money; cout << "Continue?y/n\n"; cin >> ch; deck1.needtoshuffle(); } cout << "Thanks for playing! \n"; for (int i=0; i<=moneycount; i++) { cout << moneyevolve[i]<<" "; } cout << endl; return 0; }
// Run a Monte-Carlo simulation of a game with 6 players. // Simulate 1,000,000 games. // Record the winning hole cards of each game. // Then count the winning frequency of each hole cards. void simulate(int num_players, int num_simulations) { std::mt19937 engine; //std::uniform_int_distribution<int> d(0, 51); auto gen = [&](int n) -> int { return std::uniform_int_distribution<int>(0, n - 1)(engine); }; // Keep track of the number of occurrences and winning of each combination // of hole cards. struct hole_stat_t { char type[4]; // e.g. "AKs" int num_occur[MAX_PLAYERS]; // number of occurrence given n opponents int num_win[MAX_PLAYERS]; // number of winning given n opponents double odds(int num_players) const { return (double)(num_occur[num_players] - num_win[num_players]) / num_win[num_players]; } }; hole_stat_t stat[HOLE_CARD_COMBINATIONS]; for (int i = 0; i < HOLE_CARD_COMBINATIONS; i++) { format_hole_index(stat[i].type, i); memset(stat[i].num_occur, 0, sizeof(stat[i].num_occur)); memset(stat[i].num_win, 0, sizeof(stat[i].num_win)); } // Initialize a deck of cards. Hand deck[52]; for (int i = 0; i < 52; i++) { Card card((Rank)(i / 4), (Suit)(i % 4)); deck[i] = Hand(card); } for (int i = 0; i < num_simulations; i++) { // Shuffle the deck. std::random_shuffle(deck + 0, deck + 52, gen); // Store the winning hand and hole cards. HandStrength win_strength; // Use the first five cards as community cards. Hand community(deck, 5); // Use each of the next two cards as hole cards for the players. for (int j = 0; j < num_players; j++) { Hand hole; hole += deck[5 + j * 2]; hole += deck[5 + j * 2 + 1]; // Update the occurrence of this combination of hole cards. stat[compute_hole_index(hole)].num_occur[j]++; // Find the best 5-card combination from these 7 cards. HandStrength strength = EvaluateHand(community + hole); // Update the winning hand statistics for a game with j+1 players. if (j == 0 || strength > win_strength) { win_strength = strength; stat[compute_hole_index(hole)].num_win[j]++; } } // Note that we do not process tie here. This needs to be fixed. } #if 1 printf("r1 r2 s Hole"); for (int n = 2; n <= num_players; n++) { printf(" %6d", n); } printf("\n"); for (int hole = 0; hole < 169; hole++) { char t = stat[hole].type[2]; printf("%2d %2d %c %s ", hole / 13, hole % 13, (t == ' ')? 'p' : t, stat[hole].type); for (int n = 2; n <= num_players; n++) { double prob = (double)stat[hole].num_win[n-1] / stat[hole].num_occur[n-1]; printf(" %.4lf", prob); } printf("\n"); } //printf("----------------\n"); #endif #if 0 // Display a rectangular table. printf("O\\S"); for (int r2 = Rank_Ace; r2 >= Rank_Duce; r2--) { printf("%5c", format_rank((Rank)r2)); } printf("\n"); for (int r1 = Rank_Ace; r1 >= Rank_Duce; r1--) { // Label printf("%c: ", format_rank((Rank)r1)); // Off suit (r1, r2) for r1 <= r2. for (int r2 = Rank_Ace; r2 >= Rank_Duce; r2--) { int index = r1 * 13 + r2; printf((r1 == r2)? " *%3.1lf" : "%5.1lf", stat[index].odds()); } // Pair (r1, r1). // Same-suit (r1, r2) for r1 > r2. printf("\n"); } #endif #if 0 // Sort the statistics by winning count (strongest hand first). std::sort(stat, stat + HOLE_CARD_COMBINATIONS, [](const hole_stat_t &s1, const hole_stat_t &s2) -> bool { double p1 = (double)s1.num_win / (s1.num_occur + 0.0001); double p2 = (double)s2.num_win / (s2.num_occur + 0.0001); return p1 > p2; }); // Display statistics. for (int i = 0; i < HOLE_CARD_COMBINATIONS; i++) { double percentage = 100.0 * stat[i].num_win / (stat[i].num_occur + 0.0001); // printf("%s %.2lf%%\n", stat[i].type, percentage); printf("%s %.1lf\n", stat[i].type, (100-percentage)/percentage); } #endif }
Player::Player(char _secretAnimal) { d_secretAnimal = _secretAnimal; hand = Hand(); }
//-------------------------------------------------------------- void SalsaScreen::draw() { currentPlayerPos = player.getPositionMS(); if(player.getPosition() < 1.0) { currentPlayerPos = roundUp(currentPlayerPos/100); cout << currentPlayerPos << endl; if(currentPlayerPos >= startPlayerPos_R1 && currentPlayerPos <= stopPlayerPos_R1) { updateChoreoPosition(role, currentStep, true, true, false, false); if(prevPlayerPos+intervall1 >= currentPlayerPos-4 && prevPlayerPos+intervall1 <= currentPlayerPos) { currentStep++; if(currentStep > 5) currentStep = 0; isStart = false; prevPlayerPos = currentPlayerPos; // reset history footPositions.clear(); } }else if (currentPlayerPos >= stopPlayerPos_R1 && currentPlayerPos <= startPlayerPos_R2) { standardPosition(role, 5, cX1, cY1, cX2, cY2); } else if (currentPlayerPos >= startPlayerPos_R2 && currentPlayerPos <= stopPlayerPos_R2) { if(currentPlayerPos >= startPlayerPos_R2 && currentPlayerPos <= startPlayerPos_R2+4) { standardPosition(role, 5, cX1, cY1, cX2, cY2); footPositions.clear(); } if(currentPlayerPos >= startPlayerPos_R2 && currentPlayerPos < startPlayerPos_R2+intervall1) { mStepA = 5; mStepB = 4; // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); mFootA = moveForwardsMaster(role, mStepA, 'm'); ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2+boxHeight, cY1); ofRotateZ(config.rotateZ); moveForwardsSlave(mFootA, role, mStepA, 'f'); ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX1, cY2); ofRotateZ(config.rotateZ); moveForwardsSlave(mFootA, role, mStepA, 'm'); ofPopMatrix(); // follower 2 ofPushMatrix(); ofRotateZ(config.rotateZ); ofTranslate(cX2+boxHeight, cY2); moveForwardsSlave(mFootA, role, mStepA, 'f'); ofPopMatrix(); } if(currentPlayerPos >= startPlayerPos_R2+intervall1 && currentPlayerPos <= startPlayerPos_R2+intervall1+4) { footPositions.clear(); } if(currentPlayerPos >= startPlayerPos_R2+intervall1 && currentPlayerPos < startPlayerPos_R2+intervall1+intervall1) { // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), 'm', config.iconSize); // right foot mFootB = moveForwardsMaster(role, mStepB, 'm'); // left foot ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2, cY1); ofRotateZ(config.rotateZ); Foot(mFootA.x, mFootA.y-2*config.distanceMoveSalsa, getStepSide(role, mStepA), 'f', config.iconSize); // left ofTranslate(0, boxHeight); moveForwardsSlave(mFootB, role, mStepB, 'f'); // right ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX1, cY2); ofRotateZ(config.rotateZ); Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), 'm', config.iconSize); // right foot moveForwardsSlave(mFootB, role, mStepB, 'm'); // left foot ofPopMatrix(); // follower 2 ofPushMatrix(); ofTranslate(cX2, cY2); ofRotateZ(config.rotateZ); Foot(mFootA.x, mFootA.y-2*config.distanceMoveSalsa, getStepSide(role, mStepA), 'f', config.iconSize); // left ofTranslate(0, boxHeight); moveForwardsSlave(mFootB, role, mStepB, 'f'); // right ofPopMatrix(); } if(currentPlayerPos >= startPlayerPos_R2+intervall1+intervall1) { // leader 1 ofPushMatrix(); ofTranslate(cX1, cY1); ofRotateZ(config.rotateZ); mGender = 'm'; Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), mGender, config.iconSize); Foot(mFootB.x, mFootB.y, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y+65, 'r', mGender, config.iconSize); Hand(mFootB.x-160, mFootB.y+50, 'l', mGender, config.iconSize); ofPopMatrix(); // follower 1 ofPushMatrix(); ofTranslate(cX2, cY1); ofRotateZ(config.rotateZ); mGender = 'f'; Foot(mFootA.x, mFootA.y-2*config.distanceMoveSalsa, getStepSide(role, mStepA), mGender, config.iconSize); Foot(mFootB.x, mFootB.y-2*config.distanceMoveSalsa, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y-2*config.distanceMoveSalsa-55, 'r', mGender, config.iconSize); Hand(mFootB.x-130, mFootB.y-2*config.distanceMoveSalsa-80, 'l', mGender, config.iconSize); ofPopMatrix(); // leader 2 ofPushMatrix(); ofTranslate(cX1, cY2); ofRotateZ(config.rotateZ); mGender = 'm'; Foot(mFootA.x, mFootA.y, getStepSide(role, mStepA), mGender, config.iconSize); Foot(mFootB.x, mFootB.y, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y+70, 'r', mGender, config.iconSize); Hand(mFootB.x-160, mFootB.y+50, 'l', mGender, config.iconSize); ofPopMatrix(); // follower 2 ofPushMatrix(); ofTranslate(cX2, cY2); ofRotateZ(config.rotateZ); mGender = 'f'; Foot(mFootA.x, mFootA.y-2*config.distanceMoveSalsa, getStepSide(role, mStepA), mGender, config.iconSize); Foot(mFootB.x, mFootB.y-2*config.distanceMoveSalsa, getStepSide(role, mStepB), mGender, config.iconSize); Hand(mFootA.x+180, mFootA.y-2*config.distanceMoveSalsa-55, 'r', mGender, config.iconSize); Hand(mFootB.x-130, mFootB.y-2*config.distanceMoveSalsa-80, 'l', mGender, config.iconSize); ofPopMatrix(); } } else if(currentPlayerPos >= startPlayerPos_R3 && currentPlayerPos <= stopPlayerPos_R3) { if(currentPlayerPos >= startPlayerPos_R3 && currentPlayerPos <= startPlayerPos_R3+4) { prevPlayerPos = currentPlayerPos; currentStep = 0; footPositions.clear(); } //cout << currentPlayerPos << " -> do " << currentStep << " :: prev " << positionPrev << " - curr " << positionCurr << " :: prevStep of side: " << previousSideStep << endl; updateChoreoPosition(role, currentStep, true, false, true, false); //cout << prevPlayerPos << " + " << intervall << " >=< " << currentPlayerPos << endl; if(prevPlayerPos+intervall1 >= currentPlayerPos-4 && prevPlayerPos+intervall1 <= currentPlayerPos) { currentStep++; if(currentStep > 5) currentStep = 0; isStart = false; prevPlayerPos = currentPlayerPos; // reset history footPositions.clear(); } } else if(currentPlayerPos >= startPlayerPos_R4 && currentPlayerPos <= stopPlayerPos_R4) { if(currentPlayerPos >= startPlayerPos_R4 && currentPlayerPos <= startPlayerPos_R4+4) { prevPlayerPos = currentPlayerPos; currentStep = 0; footPositions.clear(); } //cout << currentPlayerPos << " -> do " << currentStep << " :: prev " << positionPrev << " - curr " << positionCurr << " :: prevStep of side: " << previousSideStep << endl; updateChoreoPosition(role, currentStep, true, false, true, false); //cout << prevPlayerPos << " + " << intervall << " >=< " << currentPlayerPos << endl; if(prevPlayerPos+intervall2 >= currentPlayerPos-4 && prevPlayerPos+intervall2 <= currentPlayerPos) { currentStep++; if(currentStep > 5) currentStep = 0; isStart = false; prevPlayerPos = currentPlayerPos; // reset history footPositions.clear(); } } else if(currentPlayerPos <= stopPlayerPos_R4 && currentPlayerPos != 0) { standardPosition(role, 5, cX1, cY1, cX2, cY2); } } }