Example #1
0
 Deck::Deck( const Deck& d ) :
     DeckView( d.begin(), d.begin() ),
     keywordList( d.keywordList ),
     defaultUnits( d.defaultUnits ),
     activeUnits( d.activeUnits ),
     m_dataFile( d.m_dataFile ),
     input_path( d.input_path ) {
     this->reinit(this->keywordList.begin(), this->keywordList.end());
 }
Example #2
0
bool Engine::setDeck(const Deck &deck)
{
    if (mDeck) {
        // already set
        return false;
    }

    if (deck.empty()) {
        // nothing to do with empty card set
        return false;
    }

    if (mPlayers.size() < 2) {
        // add more players
        return false;
    }

    mDeck = new Deck(deck);

    CardSet cards;

    cards.insert(deck.begin(), deck.end());

    std::for_each(mGameObservers.begin(), mGameObservers.end(), GameStartNotification(mDeck->trumpSuit(), mGeneratedIds, cards));

    return true;
}
Example #3
0
    static std::pair< DeckView::const_iterator, DeckView::const_iterator >
    find_section( const Deck& deck, const std::string& keyword ) {

        const auto fn = [&keyword]( const DeckKeyword& kw ) {
            return kw.name() == keyword;
        };

        auto first = std::find_if( deck.begin(), deck.end(), fn );
        if( first == deck.end() )
            throw std::invalid_argument( std::string( "Deck requires a '" ) + keyword + "' section" );

        auto last = std::find_if( first + 1, deck.end(), &isSectionDelimiter );

        if( last != deck.end() && last->name() == keyword )
            throw std::invalid_argument( std::string( "Deck contains the '" ) + keyword + "' section multiple times" );

        return { first, last };
    }
Example #4
0
void Player::generateShuffledDeck()
{
    std::clog << "Generating a shuffled deck for player\n";
    int randomStep;
    std::string cardId;
    // Pick a random card from activeDeckList
    Deck copy = activeDeck;
    while (!copy.empty())
    {
    	// This is needed only to be done once per game for each player, so it is fine to traverse the list (linear time).
        randomStep = RNG::rollInt(0, copy.size() - 1);
        auto itr = std::next(copy.begin(), randomStep);
        addCardToDeck(itr->data());
        copy.erase(itr);
    }
    std::clog << "\n";
    // a newly generated deck must have the max amount of cards
    assert(deck.size() == MAX_CARD_IN_DECK);
}
Example #5
0
 Stack(Deck& deck)
 {
     for(Deck::iterator i = deck.begin(); i != deck.end(); i++)
         this->push_back(&(*i));
 }