当前位置: 首页>>代码示例>>C++>>正文


C++ Hand类代码示例

本文整理汇总了C++中Hand的典型用法代码示例。如果您正苦于以下问题:C++ Hand类的具体用法?C++ Hand怎么用?C++ Hand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Hand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CardPoint

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;

//.........这里部分代码省略.........
开发者ID:seem-sky,项目名称:doudizhu,代码行数:101,代码来源:method.cpp

示例2: Method

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;
}
开发者ID:seem-sky,项目名称:doudizhu,代码行数:83,代码来源:method.cpp

示例3: main

int main(int argc, const char * argv[])
{
    Deck deck;
    Player *player = player_factory(argv[3]);
    Hand hand;
    
    cout << "Shuffling the deck\n";
    for (int counter = 0; counter < 7; counter++) {
        int num = get_cut();
        cout << "cut at " << num << endl;
        deck.shuffle(num);
        player->shuffled();
    }
    
    int minBet = 5;
    int bankroll = atoi(argv[1]);
    int totalHands = atoi(argv[2]);
    int handsPlayed = 1;
    
    while ((bankroll >= minBet) & (handsPlayed <= totalHands)) {
        cout << "Hand " << handsPlayed << " bankroll " << bankroll << endl;
        if (deck.cards_remaining() < 20) {
            int cutNum = get_cut();
            cout << "cut at " << cutNum << endl;
            deck.shuffle(cutNum);
            player->shuffled();
        }
        
        
        int wager = player->bet(bankroll, minBet);
        cout << "Player bets " << wager << endl;

        Hand dealerHand;
        
        Card p1;
        Card p2;
        Card d1;
        Card d2;
        p1 = deck.deal();
        d1 = deck.deal();
        p2 = deck.deal();
        d2 = deck.deal();
        hand.add_card(p1);
        hand.add_card(p2);
        dealerHand.add_card(d1);
        dealerHand.add_card(d2);
        
        cout << "Player dealt " << p1 << endl;
        player->expose(p1);
        cout << "Dealer dealt " << d1 << endl;
        player->expose(d1);
        cout << "Player dealt " << p2 << endl;
        player->expose(p2);
        
        if (hand.hand_value() == 21) {
            bankroll += (3/2)*wager;
            cout << "Player dealt natural 21\n";
            handsPlayed++;
            hand.discard_all();
        } else {
        
        cout << "Player's total is " << hand.hand_value() << endl;
        while (player->draw(d1, hand)) {
            Card c1 = deck.deal();
            hand.add_card(c1);
            player->expose(c1);
            cout << "Player dealt " << c1 << endl;
            cout << "Player's total is " << hand.hand_value() << endl;
        }
        
        if ((hand.hand_value() > 21) & (!hand.hand_is_soft())) {
            cout << "Player busts!" << endl;
            bankroll -= wager;
            handsPlayed++;
            hand.discard_all();
        } else {
            cout << "Dealer's hole card is " << d2 << endl;
            player->expose(d2);
            
            while (dealerHand.hand_value() < 17) {
                Card c1 = deck.deal();
                dealerHand.add_card(c1);
                player->expose(c1);
                cout << "Dealer dealt " << c1 << endl;
            }
            cout << "Dealer's total is " << dealerHand.hand_value() << endl;
        
            if ((dealerHand.hand_value() > 21) & (!dealerHand.hand_is_soft())) {
                cout << "Dealer busts!" << endl;
                bankroll += wager;
                handsPlayed++;
                hand.discard_all();
            } else {
        
                if (dealerHand.hand_value() > hand.hand_value()) {
                    cout << "Dealer wins\n";
                    bankroll -= wager;
                    handsPlayed++;
                    hand.discard_all();
                } else if (dealerHand.hand_value() < hand.hand_value()) {
//.........这里部分代码省略.........
开发者ID:amalstrom,项目名称:blackjack,代码行数:101,代码来源:blackjack.cpp

示例4: setPalm

static void setPalm(float deltaTime, int index) {
    MyAvatar* avatar = Application::getInstance()->getAvatar();
    Hand* hand = avatar->getHand();
    PalmData* palm;
    bool foundHand = false;
    for (size_t j = 0; j < hand->getNumPalms(); j++) {
        if (hand->getPalms()[j].getSixenseID() == index) {
            palm = &(hand->getPalms()[j]);
            foundHand = true;
        }
    }
    if (!foundHand) {
        PalmData newPalm(hand);
        hand->getPalms().push_back(newPalm);
        palm = &(hand->getPalms()[hand->getNumPalms() - 1]);
        palm->setSixenseID(index);
    }
    
    palm->setActive(true);
    
    // Read controller buttons and joystick into the hand
    const QString PRIO_JOYSTICK_NAME = "PrioVR";
    Joystick* prioJoystick = JoystickScriptingInterface::getInstance().joystickWithName(PRIO_JOYSTICK_NAME);
    if (prioJoystick) {
        const QVector<float> axes = prioJoystick->getAxes();
        const QVector<bool> buttons = prioJoystick->getButtons();
        
        if (axes.size() >= 4 && buttons.size() >= 4) {
            if (index == LEFT_HAND_INDEX) {
                palm->setControllerButtons(buttons[1] ? BUTTON_FWD : 0);
                palm->setTrigger(buttons[0] ? 1.0f : 0.0f);
                palm->setJoystick(axes[0], -axes[1]);
                
            } else {
                palm->setControllerButtons(buttons[3] ? BUTTON_FWD : 0);
                palm->setTrigger(buttons[2] ? 1.0f : 0.0f);
                palm->setJoystick(axes[2], -axes[3]);
            }
        }
    }
    
    // NOTE: this math is done in the worl-frame with unecessary complexity.
    // TODO: transfom this to stay in the model-frame.
    glm::vec3 position;
    glm::quat rotation;
    SkeletonModel* skeletonModel = &Application::getInstance()->getAvatar()->getSkeletonModel();
    int jointIndex;
    glm::quat inverseRotation = glm::inverse(Application::getInstance()->getAvatar()->getOrientation());
    if (index == LEFT_HAND_INDEX) {
        jointIndex = skeletonModel->getLeftHandJointIndex();
        skeletonModel->getJointRotationInWorldFrame(jointIndex, rotation);      
        rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, PI_OVER_TWO, 0.0f));
        
    } else {
        jointIndex = skeletonModel->getRightHandJointIndex();
        skeletonModel->getJointRotationInWorldFrame(jointIndex, rotation);
        rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, -PI_OVER_TWO, 0.0f));
    }
    skeletonModel->getJointPositionInWorldFrame(jointIndex, position);
    position = inverseRotation * (position - skeletonModel->getTranslation());
    
    palm->setRawRotation(rotation);
    
    //  Compute current velocity from position change
    glm::vec3 rawVelocity;
    if (deltaTime > 0.0f) {
        rawVelocity = (position - palm->getRawPosition()) / deltaTime; 
    } else {
        rawVelocity = glm::vec3(0.0f);
    }
    palm->setRawVelocity(rawVelocity);
    palm->setRawPosition(position);
    
    // Store the one fingertip in the palm structure so we can track velocity
    const float FINGER_LENGTH = 0.3f;   //  meters
    const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH);
    const glm::vec3 newTipPosition = position + rotation * FINGER_VECTOR;
    glm::vec3 oldTipPosition = palm->getTipRawPosition();
    if (deltaTime > 0.0f) {
        palm->setTipVelocity((newTipPosition - oldTipPosition) / deltaTime);
    } else {
        palm->setTipVelocity(glm::vec3(0.0f));
    }
    palm->setTipPosition(newTipPosition);
}
开发者ID:ey6es,项目名称:hifi,代码行数:85,代码来源:PrioVR.cpp

示例5: QHideEvent

void QTVS_Leap::HandLogic()
{
  //TODO: Fix this
  if (hands.count() == 1)
  {
    int iHandToFingerShift = hand.isLeft() ? 5 : 0;

    for (int iFingerCounter = iHandToFingerShift;
         iFingerCounter <= iHandToFingerShift + 4;
         iFingerCounter ++)
      QCoreApplication::postEvent(fingerTraces.at(iFingerCounter), new QHideEvent());

    iHandToFingerShift = hand.isLeft() ? 0 : 5;

if(ui.checkBox_ShowFingers->isChecked())
{
    for (int iFingerCounter = iHandToFingerShift;
         iFingerCounter <= iHandToFingerShift + 4;
         iFingerCounter ++)
      QCoreApplication::postEvent(fingerTraces.at(iFingerCounter), new QShowEvent());
}

  }
  else if (hands.isEmpty())
  {
    foreach (FingerTraceWindow * fTrace, fingerTraces)
      QCoreApplication::postEvent(fTrace, new QHideEvent());
    // QCoreApplication::postEvent(thumbTrace, new QHideEvent());
    // QCoreApplication::postEvent(indexTrace, new QHideEvent());
    // QCoreApplication::postEvent(middleTrace, new QHideEvent());
    // QCoreApplication::postEvent(ringTrace, new QHideEvent());
    // QCoreApplication::postEvent(pinkieTrace, new QHideEvent());
  }
  else
  {
    if(ui.checkBox_ShowFingers->isChecked())
    {
    foreach (FingerTraceWindow * fTrace, fingerTraces)
      QCoreApplication::postEvent(fTrace, new QShowEvent());      
    }
    // QCoreApplication::postEvent(thumbTrace, new QShowEvent());
    // QCoreApplication::postEvent(indexTrace, new QShowEvent());
    // QCoreApplication::postEvent(middleTrace, new QShowEvent());
    // QCoreApplication::postEvent(ringTrace, new QShowEvent());
    // QCoreApplication::postEvent(pinkieTrace, new QShowEvent());

  }

  for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
    // Get the first hand
    hand = *hl;

//TODO: Perhaps move this to gestures?
    if (ui.checkBox_Crunch->isChecked())
    {
      if (hands.count() == 2)
      {
        // we check if one hand's dragging and the other's closed
        if (hand.isLeft())
        {
          // if this hand is left, and the other hand (right) is dragging something..
          if (debugWindowDrag_Right.left != -1)
          {
            debugDisplayString = QString::number(hand.grabStrength());
            //pretty much closed
            if (hand.grabStrength() >= 0.7)
            {
              SendMessage(debugWindowHWND_Right, WM_SYSCOMMAND, SC_CLOSE, 0);
              // DestroyWindow();
            }
          }
        }
        else
        {
          // if this hand is left, and the other hand (right) is dragging something..
          if (debugWindowDrag_Left.left != -1)
          {
            //pretty much closed
            if (hand.grabStrength() >= 0.7)
            {
              // DestroyWindow(debugWindowHWND_Left);
              SendMessage(debugWindowHWND_Left, WM_SYSCOMMAND, SC_CLOSE, 0);
            }
          }
        }
      }
    }
    // std::string handType = hand.isLeft() ? "Left hand" : "Right hand";

    // std::cout << std::string(2, ' ') << handType << ", id: " << hand.id()
    //           << ", palm position: " << hand.palmPosition() << std::endl;
    // Get the hand's normal vector and direction
    const Vector normal = hand.palmNormal();
    const Vector direction = hand.direction();

    // Calculate the hand's pitch, roll, and yaw angles
    // debugDisplayString = QString(", palm position: " + QString(hand.palmPosition().toString().data() ));

    // debugDisplayString = QString::number(hand.palmPosition().x); //20
    // debugDisplayString.append("\n");
//.........这里部分代码省略.........
开发者ID:Inathero,项目名称:QTVS_Leap,代码行数:101,代码来源:qtvs_leap.cpp

示例6: constructorTest

 static void constructorTest(){
   Hand h = Hand();
   assert(h.getSize() == 0);
 }
开发者ID:smsukardi,项目名称:skip-bo,代码行数:4,代码来源:DeckTest.cpp

示例7: wam_main

int wam_main(int argc, char** argv, ProductManager& pm,
		systems::Wam<DOF>& wam) {
	BARRETT_UNITS_TEMPLATE_TYPEDEFS(DOF);

	typedef Hand::jp_type hjp_t;

	typedef boost::tuple<double, hjp_t> tuple_type;
	typedef systems::TupleGrouper<double, hjp_t> tg_type;
	tg_type tg;
	char tmpFile[] = "btXXXXXX";
	if (mkstemp(tmpFile) == -1) {
		printf("ERROR: Couldn't create temporary file!\n");
		return 1;
	}
	const double TRANSITION_DURATION = 0.5;

	wam.gravityCompensate();

//	printf("Press [Enter] to  go to given position");
//	waitForEnter();
//	jp_type startpos(0.0); // TODO : change here
//	wam.moveTo(startpos);

// Is an FTS attached?
	ForceTorqueSensor* fts = NULL;
	if (pm.foundForceTorqueSensor()) {
		fts = pm.getForceTorqueSensor();
		fts->tare();
	}

	// Is a Hand attached?
	Hand* hand = NULL;
	std::vector<TactilePuck*> tps;
	if (pm.foundHand()) {
		hand = pm.getHand();

		printf(
				">>> Press [Enter] to initialize Hand. (Make sure it has room!)");
		waitForEnter();
		hand->initialize();
		hand->trapezoidalMove(Hand::jp_type((1.0 / 3.0) * M_PI), Hand::SPREAD);
		hand->trapezoidalMove(Hand::jp_type((1.0 / 3.0) * M_PI), Hand::GRASP);
		hand->trapezoidalMove(Hand::jp_type((0.0) * M_PI), Hand::GRASP);

	}
	printf("Error 1 \n");
	tps = hand->getTactilePucks();
	// TODO write some error statement
	bool Release_Mode = 0;
	double delta_step = 0.002; //pm.getExecutionManager()->getPeriod();
	std::string input_angle_string;
	input_angle_string = argv[1];

	double input_angle = atoi(input_angle_string.c_str());
	double spread_angle = (input_angle / 180.0) * M_PI;
//	std::string threshold_impulse_str;
//	std::cout << "Enter the inpulse threshold limit: ";
//	std::cin >> threshold_impulse_str;
//	std::cout << "\n" << std::endl;
	std::string threshold_impulse_string;
	threshold_impulse_string = argv[2];

	double threshold_impulse = atof(threshold_impulse_string.c_str());

	printf("Press [Enter] to turn on the system");
	waitForEnter();
	printf("Error 2 \n");

	systems::Ramp time(pm.getExecutionManager(), 1.0);
//	const size_t PERIOD_MULTIPLIER = 1;
	const size_t PERIOD_MULTIPLIER = 1;
	systems::PeriodicDataLogger<tuple_type> logger(pm.getExecutionManager(),
			new log::RealTimeWriter<tuple_type>(tmpFile,
					PERIOD_MULTIPLIER * pm.getExecutionManager()->getPeriod()),
			PERIOD_MULTIPLIER);
	printf("Error 3 \n");

//	Hand_forcetorque_sense<DOF> hand_ft(hand, fts);
	Hand_tactile_sense hand_tact(hand, tps);
	main_processor<DOF> brain(hand, delta_step, spread_angle, threshold_impulse,
			Release_Mode);
	Hand_full_move hand_move(hand);

	systems::connect(tg.output, logger.input);
	systems::connect(time.output, brain.Current_time);
//	systems::connect(hand_ft.Force_hand, brain.Force_hand);
//	systems::connect(hand_ft.Torque_hand, brain.Torque_hand);
//	systems::connect(hand_ft.Acceleration_hand, brain.Acceleration_hand);
	systems::connect(hand_tact.Finger_Tactile_1, brain.Finger_Tactile_1);
	systems::connect(hand_tact.Finger_Tactile_2, brain.Finger_Tactile_2);
	systems::connect(hand_tact.Finger_Tactile_3, brain.Finger_Tactile_3);
	systems::connect(hand_tact.Finger_Tactile_4, brain.Finger_Tactile_4);
	systems::connect(brain.Desired_Finger_Angles, hand_move.Finger_Angles);

	systems::connect(time.output, tg.template getInput<0>());
	systems::connect(brain.Desired_Finger_Angles, tg.template getInput<1>());
//	systems::connect(hand_ft.Force_hand_cf, tg.template getInput<1>());


	printf("Error 4 \n");
//.........这里部分代码省略.........
开发者ID:ravipr009,项目名称:gwam-simulator,代码行数:101,代码来源:test_tact_finger.cpp

示例8: poker_type

int poker_type(const Hand & h)
{
	int handSize = h.size();
	const int quad = 4;			//number of cards in a four of a kind
	const int triplet = 3;		//number of cards in a three of a kind
	const int pair = 2;			//number of cards in a two of a kind
	if (handSize == 5)
	{
		//checks the overall hand for a flush or a straight
		bool flush = h.cards[0].cardSuit == h.cards[1].cardSuit && h.cards[0].cardSuit == h.cards[2].cardSuit && h.cards[0].cardSuit == h.cards[3].cardSuit && h.cards[0].cardSuit == h.cards[4].cardSuit;
		bool straight = (h.cards[0].cardRank + 1) == h.cards[1].cardRank && (h.cards[1].cardRank + 1) == h.cards[2].cardRank && (h.cards[2].cardRank + 1) == h.cards[3].cardRank && (h.cards[3].cardRank + 1) == h.cards[4].cardRank;

		//checks for any multiples of a rank
		int maxCount = 0;		//maximum number of cards of the same rank in hand
		int secondCount = 0;	//second best amount of cards of the same rank (for full house and two pairs)
		int j;
		for (j = 0; j < handSize; j++)		//go through all cards in hand beginning with first one
		{

			Card cardOne = h.cards[j];		//store card currently examined
			int crntCount = 1;				//there are one of that rank so far

			int k;
			for (k = j + 1; k < handSize; ++k)	//go through rest of cards finding the rest of that rank
			{

				Card cardTwo = h.cards[k];

				if (cardOne.cardRank == cardTwo.cardRank)	//check if ranks are the same
				{

					++j;		//increment j so we dont double count the matching card
					++crntCount;	//increment count of the rank seen

				}
				else		//since cards are sorted, we know we will not hit any more of that rank once we find the first that is not of that rank so we can break
				{

					break;

				}
			}

			if (crntCount > maxCount)		//if we found a new maximum set it as so
			{

				secondCount = maxCount;
				maxCount = crntCount;

			}
			else if (crntCount > secondCount)		//if we found a new second most cards set it as so
			{

				secondCount = crntCount;

			}
		}

		//go through all hand possibilities starting with the best down to the worst and declare which we match
		if (flush && straight)
		{

			return poker_ranks::straightFlush;

		}
		else if (maxCount == quad)
		{

			return poker_ranks::fourOfAKind;

		}
		else if (maxCount == triplet && secondCount == pair)
		{

			return poker_ranks::fullHouse;

		}
		else if (flush)
		{

			return poker_ranks::flush;

		}
		else if (straight)
		{

			return poker_ranks::striaght;

		}
		else if (maxCount == triplet)
		{

			return poker_ranks::threeOfAKind;

		}
		else if (maxCount == pair && secondCount == pair)
		{

			return poker_ranks::twoPairs;

//.........这里部分代码省略.........
开发者ID:hwills,项目名称:CardGames,代码行数:101,代码来源:Deck.cpp

示例9: srand

Bet ComputerPlayer::calculateBet(SmallDeck comm, int minBet, GameState state) {

	srand((unsigned) time(0));
	ifstream inputFile;
	inputFile.open("PocketRanking.txt");
	char temp[4];
	int rank;
	int card1;
	int card2;
	int suited;
	int cardsuits;
	int ComputerRank;

	Card temp1;
	Card temp2;
	Card temp3;
	Hand Current;
	SmallDeck d = *pocket;

	if (!comm.isEmpty()) {
		Current.evaluate(d, comm);
	}
	temp1 | d.getCard(0);
	temp2 | d.getCard(1);

	if (temp1.getSuit() == temp2.getSuit()) {
		cardsuits = 1;
	} else {
		cardsuits = 0;
	}
	if (temp2.getValue() > temp1.getValue()) {
		temp3 | temp1;
		temp1 | temp2;
		temp2 | temp3;
	}

	for (int i = 0; i < 169; i++) {

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		rank = atoi(temp);

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		card1 = atoi(temp);

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		card2 = atoi(temp);

		inputFile.getline(temp, 4, '	');
		inputFile >> temp;
		suited = atoi(temp);

		if (card1 == temp1.getValue() && card2 == temp2.getValue()
				&& suited == cardsuits)
			ComputerRank = rank;

	}

	int PC; //PocketConfidence
	int FP; //Flop Confidence
	if (ComputerRank <= 169 && ComputerRank >= 120)
		PC = 0;
	else if (ComputerRank <= 119 && ComputerRank >= 80)
		PC = 1;
	else if (ComputerRank <= 79 && ComputerRank >= 30)
		PC = 2;
	else if (ComputerRank <= 29 && ComputerRank >= 20)
		PC = 3;
	else if (ComputerRank <= 19 && ComputerRank >= 10)
		PC = 4;
	else if (ComputerRank <= 9 && ComputerRank >= 1)
		PC = 5;

	BetAction betAct = CALL;
	int betAmt = 0;
	int percent = rand() % 10;
	if (state == NEWROUND) {

		switch (PC) {
		case 0: {
			if (percent < 5) {
				if (minBet == 0) {
					betAct = CALL;
					betAmt = 0;
				} else {
					betAct = FOLD;
					betAmt = 0;
				}
				break;
			} else {
				betAct = CALL;
				betAmt = minBet;
			}
			break;
		}
		case 1: {
			if (percent < 3) {
				if (minBet == 0) {
//.........这里部分代码省略.........
开发者ID:bcspragu,项目名称:Casino,代码行数:101,代码来源:ComputerPlayer.cpp

示例10: frame

void LeapHander::frame(pugi::xml_node &frameNode){
	Leap::Frame currentFrame = m_sampleListener.frame();
	m_lock.lock();
	frameNode.append_attribute("id").set_value(currentFrame.id());
	pugi::xml_node handList = frameNode.append_child("hands");
	HandList hands = currentFrame.hands();
	
	for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
		// Get the first hand
		const Hand hand = *hl;
		pugi::xml_node handNode = handList.append_child("hand");
		handNode.append_attribute("id").set_value(hand.id());
		std::string handType;
		if (hand.isLeft()) {
			handType = "Left";
		}
		else {
			handType = "Right";
		}
		handNode.append_attribute("type").set_value(handType.c_str());
		
		pugi::xml_node positionNode = handNode.append_child("position");
		positionToXml(positionNode, hand.palmPosition());
		
		/*pugi::xml_node normalNode = handNode.append_child("normal");
		positionToXml(normalNode, hand.palmNormal());

		pugi::xml_node directionNode = handNode.append_child("direction");
		positionToXml(directionNode, hand.direction());

		pugi::xml_node rotationNode = handNode.append_child("basis");
		rotationToXml(rotationNode, hand.basis());*/
		//// Get fingers
		pugi::xml_node fingerList = handNode.append_child("fingers");
		const FingerList fingers = hand.fingers();
		for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
			const Finger finger = *fl;
			pugi::xml_node fingerNode = fingerList.append_child("finger");
			fingerNode.append_attribute("id").set_value(finger.id());
			fingerNode.append_attribute("name").set_value(fingerNames[finger.type()].c_str());
			pugi::xml_node boneList = fingerNode.append_child("bones");
			

			// Get finger bones
			for (int b = 0; b < 4; ++b) {
				Bone::Type boneType = static_cast<Bone::Type>(b);
				Bone bone = finger.bone(boneType);
				pugi::xml_node boneNode = boneList.append_child("bone");
				boneNode.append_attribute("length").set_value(bone.length());
				boneNode.append_attribute("name").set_value(boneNames[boneType].c_str());

				pugi::xml_node prevJoint = boneNode.append_child("prevJoint");
				positionToXml(prevJoint, bone.prevJoint());

				pugi::xml_node nextJoint = boneNode.append_child("nextJoint");
				positionToXml(nextJoint, bone.nextJoint());

				/*pugi::xml_node rotation = boneNode.append_child("basis");
				rotationToXml(rotation, bone.basis());*/
			}
		}
	}
	m_lock.unlock();
}
开发者ID:Lucklyric,项目名称:EM-Leap,代码行数:64,代码来源:leaphander.cpp

示例11: onFrame

void AirwritingListener::onFrame(const Controller& controller) {
    // Get the most recent frame and report some basic information
    const Frame frame = controller.frame();
    unsigned long long timestamp = frame.timestamp();
    
    /*
    std::cout << "Frame id: " << frame.id()
    << ", timestamp: " << frame.timestamp()
    << ", hands: " << frame.hands().count()
    << ", extended fingers: " << frame.fingers().extended().count()
    << ", tools: " << frame.tools().count()
    << ", gestures: " << frame.gestures().count() << std::endl;
    */

    
    HandList hands = frame.hands();
    for (HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl) {
        // Get the first hand
        const Hand hand = *hl;
        std::string handType = hand.isLeft() ? "Left hand" : "Right hand";
        
        /*
        std::cout << std::string(2, ' ') << handType << ", id: " << hand.id()
        << ", palm position: " << hand.palmPosition() << std::endl;
        */
        
        /*
        // Get the hand's normal vector and direction
        const Vector normal = hand.palmNormal();
        const Vector direction = hand.direction();
        */
        
        /*
        // Calculate the hand's pitch, roll, and yaw angles
        std::cout << std::string(2, ' ') <<  "pitch: " << direction.pitch() * RAD_TO_DEG << " degrees, "
        << "roll: " << normal.roll() * RAD_TO_DEG << " degrees, "
        << "yaw: " << direction.yaw() * RAD_TO_DEG << " degrees" << std::endl;
        */
        
        /*
        // Get the Arm bone
        Arm arm = hand.arm();
        std::cout << std::string(2, ' ') <<  "Arm direction: " << arm.direction()
        << " wrist position: " << arm.wristPosition()
        << " elbow position: " << arm.elbowPosition() << std::endl;
        */
        
        // Get fingers
        const FingerList fingers = hand.fingers();
        for (FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl) {
            const Finger finger = *fl;
            sample(finger, timestamp);
            
            /*
            std::cout << std::string(4, ' ') <<  fingerNames[finger.type()]
            << " finger, id: " << finger.id()
            << ", length: " << finger.length()
            << "mm, width: " << finger.width() << std::endl;
            */
            
            /*
            // Get finger bones
            for (int b = 0; b < 4; ++b) {
                Bone::Type boneType = static_cast<Bone::Type>(b);
                Bone bone = finger.bone(boneType);
                std::cout << std::string(6, ' ') <<  boneNames[boneType]
                << " bone, start: " << bone.prevJoint()
                << ", end: " << bone.nextJoint()
                << ", direction: " << bone.direction() << std::endl;
            }
            */
        }
    }
    
    
    /*
    // Get tools
    const ToolList tools = frame.tools();
    for (ToolList::const_iterator tl = tools.begin(); tl != tools.end(); ++tl) {
        const Tool tool = *tl;
        std::cout << std::string(2, ' ') <<  "Tool, id: " << tool.id()
        << ", position: " << tool.tipPosition()
        << ", direction: " << tool.direction() << std::endl;
    }
    */
    

    // Get gestures
    const GestureList gestures = frame.gestures();
    for (int g = 0; g < gestures.count(); ++g) {
        Gesture gesture = gestures[g];
        
        switch (gesture.type()) {
            case Gesture::TYPE_CIRCLE:
            {
                CircleGesture circle = gesture;
                std::string clockwiseness;
                
                if (circle.pointable().direction().angleTo(circle.normal()) <= PI/2) {
                    clockwiseness = "clockwise";
//.........这里部分代码省略.........
开发者ID:xwj95,项目名称:Airwriting,代码行数:101,代码来源:AirwritingListener.cpp

示例12: update

void LeapController::update() {   
    hands = leap.getLeapHands();
    
    if(leap.isFrameNew() && hands.size()){
        
        for(int i = 0; i < hands.size(); i++){
            
            Hand hand = hands[i];
            
            if (handsPrevious.size() == hands.size() && hand.fingers().count() == 3){
                
                float dx =  hand.palmPosition().x - handsPrevious[i].palmPosition().x;
                float dy =  hand.palmPosition().z - handsPrevious[i].palmPosition().z;
                float dz = -hand.palmPosition().y + handsPrevious[i].palmPosition().y;
                int numFingers = hands[i].fingers().count();
                
//                horizontalPan = (numFingers == 2);
                horizontalPan = false;
                verticalPan = true;
                
                pan(dx,dy,dz);
            }
        }
    }
    
    Frame frame = controller.frame();
    GestureList gestures =  framePrevious.isValid()       ?
    frame.gestures(framePrevious) :
    frame.gestures();
    framePrevious = frame;
    
    for (size_t i=0; i < gestures.count(); i++) {
        if (gestures[i].type() == Gesture::TYPE_SCREEN_TAP) {
            ScreenTapGesture tap = gestures[i];
            static GestureEventArgs args;
            args.pos = ofVec3f(tap.position().x, tap.position().y, tap.position().z);
            ofNotifyEvent(onTapScreen, args, this);
        } else if (gestures[i].type() == Gesture::TYPE_KEY_TAP) {
            KeyTapGesture tap = gestures[i];
            static GestureEventArgs args;
            args.pos = ofVec3f(tap.position().x, tap.position().y, tap.position().z);
            ofNotifyEvent(onTapDown, args, this);
            
            //cout << "LEAP TAP GESTURE AT: " << pos << endl;
        
        } else if (gestures[i].type() == Gesture::TYPE_SWIPE) {
            SwipeGesture swipe = gestures[i];
            Vector diff = 0.004f*(swipe.position() - swipe.startPosition());
            static GestureEventArgs args;
            args.pos = ofVec3f(swipe.position().x, swipe.position().y, swipe.position().z);
            args.startPos = ofVec3f(swipe.startPosition().x, swipe.startPosition().y, swipe.startPosition().z);
            args.state = swipe.state();
            ofNotifyEvent(onSwipe, args, this);
            
            //cout << "LEAP SWIPE GESTURE" << endl;
        
        } else if (gestures[i].type() == Gesture::TYPE_CIRCLE) {
            CircleGesture circle = gestures[i];
            float progress = circle.progress();
            
            if (progress >= 1.0f) {
                double curAngle = 6.5;
                
                //cout << "LEAP CIRCLE GESTURE" << endl;
            }
            static GestureEventArgs args;
            args.pos = ofVec3f(circle.center().x, circle.center().y, circle.center().z);
            args.normal = ofVec3f(circle.normal().x, circle.normal().y, circle.normal().z);
            args.progress = circle.progress();
            ofNotifyEvent(onCircle, args, this);
        }
    }
    
    handsPrevious = hands;
    
	leap.markFrameAsOld();
    
    SceneController::update();
}
开发者ID:samluescher,项目名称:GeoSenseReliefClient,代码行数:79,代码来源:LeapController.cpp

示例13: glMatrixMode

void LeapBrowser::drawHands()
{
	Frame frame = leap_controller.frame();

	math::vector trans = leap_transform.translation;
	math::quater rot_quat = leap_transform.rotation;
	math::vector rot_vect = math::ln( rot_quat );
	
	double angle = rot_vect.length() * 2.0;
	math::vector axis = ( angle != 0 ? rot_vect / angle : rot_vect );

	glMatrixMode( GL_MODELVIEW );
	glPushMatrix();
	glTranslatef( trans.x(), trans.y(), trans.z() );
	if( angle != 0 )
	{
		glRotatef( angle * 180.0 / M_PI, axis.x(), axis.y(), axis.z() );
	}

	HandList hands = frame.hands();
	for( HandList::const_iterator hl = hands.begin(); hl != hands.end(); ++hl )
	{
		const Hand hand = *hl;

		float joint_radius = 5.0f;
		float bone_radius = 4.5f;

		Vector prev_palm_start(0,0,0);
		Vector prev_palm_end(0,0,0);

		int f = 0;
		const FingerList fingers = hand.fingers();
		for( FingerList::const_iterator fl = fingers.begin(); fl != fingers.end(); ++fl, ++f )
		{
			const Finger finger = *fl;

			Vector curr_palm_start(0,0,0);
			Vector curr_palm_end(0,0,0);

			for( int b=0; b < 4; b++ )
			{
				Bone::Type bone_type = static_cast<Bone::Type>( b );
				Bone bone = finger.bone( bone_type );

				Vector start = bone.prevJoint();
				Vector end = bone.nextJoint();

				math::position p0( start.x, start.y, start.z );
				math::position p1( end.x, end.y, end.z );

				if( is_tracking_pose == true && finger.type() == Finger::Type::TYPE_INDEX && b==3 )
				{
					drawing_tool.setColor( 1, 0, 0, 1 );
				}
				else
				{
					drawing_tool.setColor( 0.5, 0.7, 0.5, 1 );
				}
				drawing_tool.drawSphere( p1, joint_radius );
				
				drawing_tool.setColor( 0.5, 0.7, 0.5, 1 );
				drawing_tool.drawSphere( p0, joint_radius );
				drawing_tool.drawCylinder( p0, p1, bone_radius );

				//
				if( b == 0 && fl != fingers.begin() || b == 1 && fl == fingers.begin() )
				{
					curr_palm_start = start;
					curr_palm_end = end;
				}
			}

			if( f > 1 )	//fl != fingers.begin() )
			{
				drawing_tool.setColor( 0.5, 0.7, 0.5, 1 );
				drawing_tool.applyColor();

				glBegin( GL_QUADS );
				glVertex3f( prev_palm_start.x, prev_palm_start.y, prev_palm_start.z );
				glVertex3f( prev_palm_end.x, prev_palm_end.y, prev_palm_end.z );
				glVertex3f( curr_palm_end.x, curr_palm_end.y, curr_palm_end.z );
				glVertex3f( curr_palm_start.x, curr_palm_start.y, curr_palm_start.z );
				glEnd();
			}

			prev_palm_start = curr_palm_start;
			prev_palm_end = curr_palm_end;
		}
	}

	glPopMatrix();
}
开发者ID:lumigraph,项目名称:MotionOrbits,代码行数:92,代码来源:LeapBrowser.cpp

示例14: AI

void Game::AI()
{
	//AI works by:
	//1. using a killing move (if any)
	//2. giving the largest number of digits/points to opponent
	Hand *usePtr = m_gameWorld->tLeft();
	Hand *tarPtr = m_gameWorld->bLeft();
	int largestSum = 0;
	if (m_gameWorld->OFOn())
	{
		int sum = 0;
		if (!usePtr->isDead())
		{
			if (!tarPtr->isDead())
			{
				largestSum = m_gameWorld->tLeft()->numDigits() + m_gameWorld->bLeft()->numDigits() % 5;
				if (largestSum == 0) 
				{
					m_gameWorld->attack(usePtr,tarPtr); return;
				}
			}
			if (!m_gameWorld->bRight()->isDead())
			{
				sum = m_gameWorld->tLeft()->numDigits() + m_gameWorld->bRight()->numDigits() % 5;
				if (sum == 0) 
				{
					m_gameWorld->attack(usePtr,m_gameWorld->bRight()); return;
				}
				if (sum > largestSum)
				{
					largestSum = sum;
					tarPtr = m_gameWorld->bRight();
				}
			}
		}
		if (!m_gameWorld->tRight()->isDead())
		{
			if (!m_gameWorld->bLeft()->isDead())
			{
				sum = m_gameWorld->tRight()->numDigits() + m_gameWorld->bLeft()->numDigits() % 5;
				if (sum == 0) 
				{
					m_gameWorld->attack(m_gameWorld->tRight(),m_gameWorld->bLeft()); return;
				}
				if (sum > largestSum)
				{
					largestSum = sum; 
					usePtr = m_gameWorld->tRight();
					tarPtr = m_gameWorld->bLeft();
				}
			}
			if (!m_gameWorld->bRight()->isDead())
			{
				sum = m_gameWorld->tRight()->numDigits() + m_gameWorld->bRight()->numDigits() % 5;
				if (sum == 0) 
				{
					m_gameWorld->attack(m_gameWorld->tRight(),m_gameWorld->bRight()); return;
				}
				if (sum > largestSum)
				{
					largestSum = sum;
					usePtr = m_gameWorld->tRight();
					tarPtr = m_gameWorld->bRight();
				}
			}
		}
	}
	else
	{
		int sum = 0;
		if (!usePtr->isDead())
		{
			if (!tarPtr->isDead())
				largestSum = m_gameWorld->tLeft()->numDigits() + m_gameWorld->bLeft()->numDigits();
			if (!m_gameWorld->bRight()->isDead())
			{
				sum = m_gameWorld->tLeft()->numDigits() + m_gameWorld->bRight()->numDigits();
				if (sum > largestSum)
				{
					largestSum = sum;
					tarPtr = m_gameWorld->bRight();
				}
			}
		}
		if (!m_gameWorld->tRight()->isDead())
		{
			if (!m_gameWorld->bLeft()->isDead())
			{
				sum = m_gameWorld->tRight()->numDigits() + m_gameWorld->bLeft()->numDigits();
				if (sum > largestSum)
				{
					largestSum = sum; 
					usePtr = m_gameWorld->tRight();
					tarPtr = m_gameWorld->bLeft();
				}
			}
			if (!m_gameWorld->bRight()->isDead())
			{
				sum = m_gameWorld->tRight()->numDigits() + m_gameWorld->bRight()->numDigits();
				if (sum > largestSum)
//.........这里部分代码省略.........
开发者ID:ayrc,项目名称:chopsticks_game,代码行数:101,代码来源:Game.cpp

示例15: perfTimer

void SixenseManager::update(float deltaTime) {
#ifdef HAVE_SIXENSE
    Hand* hand = DependencyManager::get<AvatarManager>()->getMyAvatar()->getHand();
    if (_isInitialized && _isEnabled) {
#ifdef __APPLE__
        SixenseBaseFunction sixenseGetNumActiveControllers =
        (SixenseBaseFunction) _sixenseLibrary->resolve("sixenseGetNumActiveControllers");
#endif
        
        if (sixenseGetNumActiveControllers() == 0) {
            _hydrasConnected = false;
            return;
        }
        
        PerformanceTimer perfTimer("sixense");
        if (!_hydrasConnected) {
            _hydrasConnected = true;
            UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra");
        }
        
#ifdef __APPLE__
        SixenseBaseFunction sixenseGetMaxControllers =
        (SixenseBaseFunction) _sixenseLibrary->resolve("sixenseGetMaxControllers");
#endif
        
        int maxControllers = sixenseGetMaxControllers();
        
        // we only support two controllers
        sixenseControllerData controllers[2];
        
#ifdef __APPLE__
        SixenseTakeIntFunction sixenseIsControllerEnabled =
        (SixenseTakeIntFunction) _sixenseLibrary->resolve("sixenseIsControllerEnabled");
        
        SixenseTakeIntAndSixenseControllerData sixenseGetNewestData =
        (SixenseTakeIntAndSixenseControllerData) _sixenseLibrary->resolve("sixenseGetNewestData");
#endif
        int numControllersAtBase = 0;
        int numActiveControllers = 0;
        for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) {
            if (!sixenseIsControllerEnabled(i)) {
                continue;
            }
            sixenseControllerData* data = controllers + numActiveControllers;
            ++numActiveControllers;
            sixenseGetNewestData(i, data);
            
            //  Set palm position and normal based on Hydra position/orientation
            
            // Either find a palm matching the sixense controller, or make a new one
            PalmData* palm;
            bool foundHand = false;
            for (size_t j = 0; j < hand->getNumPalms(); j++) {
                if (hand->getPalms()[j].getSixenseID() == data->controller_index) {
                    palm = &(hand->getPalms()[j]);
                    foundHand = true;
                }
            }
            if (!foundHand) {
                PalmData newPalm(hand);
                hand->getPalms().push_back(newPalm);
                palm = &(hand->getPalms()[hand->getNumPalms() - 1]);
                palm->setSixenseID(data->controller_index);
                qCDebug(interfaceapp, "Found new Sixense controller, ID %i", data->controller_index);
            }
            
            // Disable the hands (and return to default pose) if both controllers are at base station
            if (foundHand) {
                palm->setActive(!_controllersAtBase);
            } else {
                palm->setActive(false); // if this isn't a Sixsense ID palm, always make it inactive
            }
            
            
            //  Read controller buttons and joystick into the hand
            palm->setControllerButtons(data->buttons);
            palm->setTrigger(data->trigger);
            palm->setJoystick(data->joystick_x, data->joystick_y);
            
            // Emulate the mouse so we can use scripts
            if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput) && !_controllersAtBase) {
                emulateMouse(palm, numActiveControllers - 1);
            }
            
            // NOTE: Sixense API returns pos data in millimeters but we IMMEDIATELY convert to meters.
            glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]);
            position *= METERS_PER_MILLIMETER;
            
            // Check to see if this hand/controller is on the base
            const float CONTROLLER_AT_BASE_DISTANCE = 0.075f;
            if (glm::length(position) < CONTROLLER_AT_BASE_DISTANCE) {
                numControllersAtBase++;
            }
            
            // Transform the measured position into body frame.
            glm::vec3 neck = _neckBase;
            // Zeroing y component of the "neck" effectively raises the measured position a little bit.
            neck.y = 0.0f;
            position = _orbRotation * (position - neck);
            
//.........这里部分代码省略.........
开发者ID:Ian-Mills,项目名称:hifi,代码行数:101,代码来源:SixenseManager.cpp


注:本文中的Hand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。