예제 #1
0
void dealDeck(Player& user, Computer& comp, Cards& deck, int count)
{
	if (count % EVEN_ODD == EMPTY)	// Deal to user first
	{
		unsigned int i = EMPTY;
		while (i < EVEN_ODD*CARDS_DEALT)
		{
			user.InsertIntoHand(deck.TopDeckCard());
			deck.PopOffCard();
			i++;
			comp.InsertIntoHand(deck.TopDeckCard());
			deck.PopOffCard();
			i++;
		}
		deck.AdjustPickPile();
	} else						// Deal to computer first
	{
		unsigned int j = EMPTY;
		while (j < EVEN_ODD*CARDS_DEALT)
		{
			comp.InsertIntoHand(deck.TopDeckCard());
			deck.PopOffCard();
			j++;
			user.InsertIntoHand(deck.TopDeckCard());
			deck.PopOffCard();
			j++;
		}
		deck.AdjustPickPile();
	}
}
예제 #2
0
파일: cards-db.cpp 프로젝트: Tayyib/uludag
void CardsDB::addCards(struct card_info *card_infos, ChipSet chipset)
{
    Cards *cards;
    struct Card card;
    struct pci_access *pacc;
    char devbuf[128];

    pacc = pci_alloc();

    for (int i = 0; card_infos[i].card_name != NULL; i++) {

	QString vendor = (card_infos[i].vendor_id == 0xffff ? i18n("Other") : 
			  pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_VENDOR, card_infos[i].vendor_id, 0));

	card.card_id = card_infos[i].card_id;
	card.card_name = card_infos[i].card_name;
	card.chipset = chipset;

	if (!m_vendors.contains(vendor)) {
	    cards = new Cards();
	    m_vendors[vendor] = cards;
	} else {
	    cards = m_vendors[vendor];
	}

	cards->push_back(card);
    }

    pci_cleanup(pacc);
}
예제 #3
0
파일: player.cpp 프로젝트: stpettersens/21
string Player::hit(Cards cards) {
	string card = cards.draw();
	this->cards.push_back(card);
	this->values.push_back(cards.getValue());
	cout << "Player hits." << endl;
	cout << "Player gets " << card << endl;
	return card;
}
예제 #4
0
/**
 * Get all the played cards for the round
 */
Cards Model::getCardsOnTable() const {
    Cards cards;

    for (int i = 0; i < NUM_PLAYERS; i++) {
        cards.insert(cards.end(), players_.at(i)->getPlayedCards().begin(), players_.at(i)->getPlayedCards().end());
    }

    return cards;
}
예제 #5
0
/**
 * Add all cards assigned to players to an array and return (in order)
 */
Cards Model::getDeck() const {
    Cards cards;

    for (int i = 0; i < NUM_PLAYERS; i++) {
        cards.insert(cards.end(), players_.at(i)->getOriginalCards().begin(), players_.at(i)->getOriginalCards().end());
    }

    return cards;
}
예제 #6
0
파일: noddyai.cpp 프로젝트: jbytheway/konig
Card NoddyAi::play_card() {
  Cards legal = legal_plays();
  assert(!legal.empty());
  std::uniform_int_distribution<size_t> card_chooser(0, legal.size()-1);
  size_t which = card_chooser(random_engine_);
  Cards::iterator i = legal.begin();
  std::advance(i, which);
  return *i;
}
예제 #7
0
파일: deck.cpp 프로젝트: Ghotrix/Stone
void Deck::shuffleCards()
{
    Cards tmpDeck;

    for (int i = 0; i < CARDS_QUANTITY; i++) {
        tmpDeck.append(deck.takeAt(rand() % deck.size()));
    }

    deck = tmpDeck;
}
예제 #8
0
파일: Cards.cpp 프로젝트: zuffy/CCX_Test
Cards* Cards::CreateSprite(int num, Point pos){
    Cards* enemyCard = new Cards();
    if (enemyCard && enemyCard->init()) {
        enemyCard->autorelease();
        enemyCard->pos = pos;
        enemyCard->prevPos = Point(-1, -1);
        enemyCard->enemyInit(num, pos.x, pos.y);
        return enemyCard;
    }
    CC_SAFE_DELETE(enemyCard);
    return NULL;
}
예제 #9
0
void Deck::set(const Cards& all_cards, const std::vector<unsigned>& ids, const std::map<signed, char> &marks)
{
    commander = nullptr;
    strategy = DeckStrategy::random;
    for(auto id: ids)
    {
        const Card* card{all_cards.by_id(id)};
        if(card->m_type == CardType::commander)
        {
            if(commander == nullptr)
            {
                commander = card;
            }
            else
            {
                throw std::runtime_error("While constructing a deck: two commanders detected (" + card->m_name + " and " + commander->m_name + ")");
            }
        }
        else
        {
            cards.emplace_back(card);
        }
    }
    if(commander == nullptr)
    {
        throw std::runtime_error("While constructing a deck: no commander found");
    }
    card_marks = marks;
}
예제 #10
0
int Level::DefineLevel(Cards c)
{
    int i;
    int sameNumber1=0,sameCount1=2;
    int sameNumber2=0,sameCount2=2;
    c.sort();
	bool Straight=true,Flush=true;
   for (i=1;i<5;i++)
   if (c.element[i].color!=c.element[i-1].color)
   {
          Flush=false;
          break;
   }
   for (i=1;i<5;i++)
   if (!((c.element[i].num-1==c.element[i-1].num) || ((i==4) && c.element[i].num-9==c.element[i-1].num)))
   {
      Straight=false;
      break;
  }
  if (Straight && Flush)
  {
     if (c.element[0].num==1 && c.element[1].num==10) return 9;
     else return 8;
  }
  if (Straight) return 4;
  if (Flush) return 5;
  return 0;
}
예제 #11
0
/**
 * Get legal plays per straight game play. Needs played cards for the round.
 */
Cards Player::getLegalPlays(Cards cardsOnTable) const {
    Cards legalPlays;
    Card firstCard = Card(SPADE, SEVEN);

    // Outer loop: current cards in hand
    for (int i = 0; i < getCurrentCards().size(); i++) {
        bool isLegalPlay = false;

        // Only legal card is 7S if there is a 7S on your hand
        if (*getCurrentCards().at(i) == firstCard) {
            legalPlays.clear();
            legalPlays.push_back(getCurrentCards().at(i));
            return legalPlays;

        // Legal if card is a 7
        } else if (getCurrentCards().at(i)->getRank() == SEVEN) {
            isLegalPlay = true;

        // If card in hand has same suit and is +/- 1 rank of a played card, then it is legal
        } else {
            for (int j = 0; j < cardsOnTable.size(); j++) {
                if (cardsOnTable.at(j)->getSuit() == getCurrentCards().at(i)->getSuit()
                    && abs((int) cardsOnTable.at(j)->getRank() - (int) getCurrentCards().at(i)->getRank()) <= 1) {
                    isLegalPlay = true;
                }
            }
        }

        if (isLegalPlay) {
            legalPlays.push_back(getCurrentCards().at(i));
        }
    }

    return legalPlays;
}
예제 #12
0
int main()
{
    Cards cards;
    cards.printCards();
    std::cout << std::endl;
    cards.sort();
    cards.printCards();
    std::cout << std::endl;

    displayCard(cards.getCard(1, 4));
    std::cout << std::endl;
    displayCard(cards.getCard(1, 4));
    std::cout << std::endl;
    cards.printCards();
    std::cout << std::endl;
    return 0;
}
예제 #13
0
int Player::WhatDeckToPickFrom(const Cards& deck) const
{
	int choice;
	cout << "Would you like to pick up from the pick up pile? ";
	cin >> choice;

	// They want to use cards from the pick up pile to meld
	if (choice == YES)
	{
		int firstLocationFromDeck;
		
		cout << "\nWhat is the bottom card location you wish to pick up from the deck? ";
		cin >> firstLocationFromDeck;

		while (firstLocationFromDeck < 0 || firstLocationFromDeck >= deck.GetPickFromPileSize())
		{
			cout << "Invalid location. Try again: ";
			cin >> firstLocationFromDeck;
		}

		return firstLocationFromDeck;		// Must return the location that they want to initially pick from 
	} else
예제 #14
0
void Deck::deal(Cards& playerOne, Cards& playerTwo, Cards& playerThree, Cards& playerFour, Cards& kitty) {
    trace;
    srand(unsigned(time(0)));
    Card* joker = (Card*)&__cardspace[42*sizeof(Card)];
    joker->setJokerSuit(Suit::NONE);
    std::random_shuffle(begin(), end());
    std::vector<Card*>::iterator it = begin();
    playerOne.clear();
    playerTwo.clear();
    playerThree.clear();
    playerFour.clear();
    for(unsigned i = 0; i < 10; ++i) {
        playerOne.push_back(*it++);
        playerTwo.push_back(*it++);
        playerThree.push_back(*it++);
        playerFour.push_back(*it++);
    }
    kitty.clear();
    kitty.push_back(*it++);
    kitty.push_back(*it++);
    kitty.push_back(*it);
}
예제 #15
0
void main ()
{
	// Outputs the rules for the game
	outputIntro();

	string name;

	// Retrieve user's name and initialize the Player
	cout << "\nEnter your name: ";
	getline(cin, name);
	Player user(name);

	// Retrieve a name for the computer and initialize the computer
	cout << "\nEnter a name for the computer: ";
	getline(cin,name);
	Computer comp(name);
	cout << "\n";

	unsigned int roundCount = EMPTY;

	// Game continues as long as neither player has over WINNING_SCORE points
	while ( (user.GetScore() < WINNING_SCORE) && (comp.GetScore() < WINNING_SCORE) )
	{
		// Output scores
		ScoreOutput(user,comp,roundCount);

		// Initialize and shuffle up the deck
		Cards deck;
		deck.InitializeDeck();
		deck.ShuffleDeck();

		// Must clear up both the players and computers hands and melded card piles
		user.ClearHandAndMeldedCards();
		comp.ClearHandAndMeldedCards();

		// Deal the deck
		dealDeck(user,comp,deck,roundCount);
	
		// Reset count back to roundCount --> alternate who goes first
		unsigned int count = roundCount;

		// Commence the game, game continues as long as both players have cards
		while ( (user.GetHandSize() > EMPTY) && (comp.GetHandSize() > EMPTY) && (deck.GetDeckSize() > EMPTY) )
		{
			// Must call gameplay every play through the hand
			
			if (count % EVEN_ODD == EMPTY)	// Player is up
				user.GamePlay(deck,comp.ReturnVectorOfMyMeldedCards(),comp.GetName());
			else						// Computer is up
				comp.GamePlay(deck);

			count++;
		}
		// Round is over, must increment the round count
		roundCount++;

		int initialPlayerScore = user.GetScore();
		int initialCompScore = comp.GetScore();
		
		// Calculate scores
		user.CalculateScore();
		comp.CalculateScore();

		cout << "Points scored this round:\n" << user.GetName() << ": " << user.GetScore() - initialPlayerScore << "\n" <<
			comp.GetName() << ": " << comp.GetScore() - initialCompScore << "\n\n";
	}
	// Someone has won by now
	outputEnding(user,comp);

	system("pause");
}
예제 #16
0
/**
 * Assign cards to player (add to original and current)
 */
void Player::addCards(Cards &cards) {
    originalCards_.insert(originalCards_.end(), cards.begin(), cards.end());
    currentCards_.insert(currentCards_.end(), cards.begin(), cards.end());
}
예제 #17
0
Card DefenceAi::play_card(FateAi const& ai) {
    // TODO: Rethink this function for partnership contracts
    Trick const& trick = ai.tricks().back();
    //Cards const& hand = ai.hand();
    Cards const plays = ai.legal_plays();
    boost::optional<Card> bird = ai.relevant_bird();

    // If there's only one legal play, play it
    if (plays.size() == 1) {
        return *plays.begin();
    }

    if (trick.played() == 0) {
        // We're leading
        if (guess_master_defender_) {
            // Lead a long suit
            for (SuitProfiles::reverse_iterator it = suit_profiles_.rbegin();
                    it != suit_profiles_.rend(); ++it) {
                if (it->suit == Suit::trumps) continue;
                auto playable = plays.equal_range(it->suit);
                if (!boost::empty(playable)) {
                    return *playable.first;
                }
            }
        } else {
            // Lead a short suit
            for (SuitProfiles::iterator it = suit_profiles_.begin();
                    it != suit_profiles_.end(); ++it) {
                if (it->suit == Suit::trumps) continue;
                auto playable = plays.equal_range(it->suit);
                if (!boost::empty(playable)) {
                    return *playable.first;
                }
            }
        }
        // At this point we must be playing trumps; play low
        assert(plays.begin()->trump());
        auto candidate = plays.begin();
        // Avoid leading a bird that might cause us to lose game points
        if (bird && *candidate == *bird) ++candidate;
        return *candidate;
    } else {
        // We're following
        Suit s = trick.suit();
        bool const playing_trump = plays.begin()->trump();
        bool const roughing = playing_trump && s != Suit::trump;

        const int declarers_position_in_trick =
            (ai.declarer() - trick.leader() + 4)%4;
        const bool declarer_has_played =
            trick.played() > declarers_position_in_trick;

        if (declarer_has_played) {
            bool const declarer_is_winning =
                trick.winner() == ai.declarer();

            if (declarer_is_winning) {
                auto winning_play = plays.lower_bound(trick.winning_card());
                if (winning_play != plays.end() && !winning_play->trump() &&
                        winning_play->suit() != s) {
                    winning_play = plays.end();
                }

                if (roughing) {
                    // If I'm last to play then make an effort to win
                    if (trick.played() == 3 && winning_play != plays.end()) {
                        return *winning_play;
                    }
                    // Otherwise just play low
                    return *plays.begin();
                } else if (playing_trump) {
                    // Following in trumps
                    if (winning_play != plays.end()) {
                        // Win minimally
                        return *winning_play;
                    } else {
                        // Can't win; play low
                        return *plays.begin();
                    }
                } else {
                    // Declarer is winning and I'm following suit or discarding
                    if (winning_play != plays.end()) {
                        // We can win in a side suit; play card worth most points, or least
                        // valuable winning pip card
                        auto most_points = std::max_element(
                                               winning_play, plays.end(), Card::CompareRanksReversePips()
                                           );
                        return *most_points;
                    }

                    // Can't win, so play low
                    /** \bug Discarding something valuable sometimes under these
                     * circumstances is pretty vital */
                    auto smallest_rank = std::min_element(
                                             plays.begin(), plays.end(), Card::CompareSuitRanks()
                                         );
                    return *smallest_rank;
                }
            } else {
                if (roughing) {
                    // Play smallest trump
                    return *plays.begin();
                } else if (playing_trump) {
                    // I'm following in trumps, but the defense is already going to win,
                    // so just play low
                    /** \bug Really person before declarer should deliberately beat
                     * the other defenders sometimes */
                    return *plays.begin();
                } else {
                    // Play card worth most points, or least valuable pip card
                    auto most_points = std::max_element(
                                           plays.begin(), plays.end(), Card::CompareRanksReversePips()
                                       );
                    return *most_points;
                }
            }
        } else {
            // Declarer hasn't played yet.
            bool const defence_will_win =
                ai.guaranteed_to_win_against(trick.winning_card(), ai.declarer());
            if (defence_will_win) {
                if (playing_trump) {
                    // We're winning anyway, so play a low trump
                    return *plays.begin();
                } else {
                    // Play something worth points
                    auto most_points = std::max_element(
                                           plays.begin(), plays.end(), Card::CompareRanksReversePips()
                                       );
                    return *most_points;
                }
            } else {
                // Defence not guaranteed to win, so declarer probably will.  Play
                // something worthless
                if (playing_trump) {
                    return *plays.begin();
                } else {
                    return *boost::range::min_element(
                               plays, Card::CompareSuitRanks()
                           );
                }
            }
        }
    }

    KONIG_FATAL("unimplimented (" << ai.tricks().size() << "): " << trick);
}