Exemple #1
0
size_t Deck::get_list(card_list& list)
{
	for each(auto& val in m_Container)
	{
		list.push_back(const_cast<Card*>(val));
	}
	return list.size();
}
Exemple #2
0
size_t Deck::find( IN const Enum::Locate::Type val, card_list& list )
{
	static const indices::type n = indices::IDX_COMP_LOCATE;

	containter::nth_index<n>::type& indexBy = m_Container.get<n>();

	std::pair<
		containter::nth_index_iterator<n>::type, 
		containter::nth_index_iterator<n>::type
	> pair;

	containter::nth_index_iterator<n>::type iter;

	pair = indexBy.equal_range(val);
	for (iter = pair.first; iter != pair.second; iter++)
	{
		WEAK_CARD p = const_cast<Card*>(*iter);
		list.push_back(p);
	}
	return list.size();
}
Exemple #3
0
bool match(card_list::iterator &from, card_list::iterator &to)
{
    card_type a = (*from).top();
    card_type b = (*to).top();
    if (a.first == b.first || a.second == b.second) {
        (*from).pop();
        (*to).push(a);
        if ((*from).empty()) cards.erase(from);
        from = to;
        return true;
    }
    return false;
}
Exemple #4
0
int main()
{
    char v, s;
    while (cin >> v && '#' != v) {
        cards.clear();

        cin >> s;
        card_stack stk;
        stk.push(make_pair(v,s));
        cards.push_back(stk);
        for (int i = 0; i < 51; ++i) {
            cin >> v >> s;
            card_stack stk;
            stk.push(make_pair(v,s));
            cards.push_back(stk);
        }

        for (card_list::iterator beg = cards.begin(), i = cards.begin(); i != cards.end(); ) {
            if (distance(beg, i) >= 3) {
                card_list::iterator j = i;
                advance(i, -3);
                if (!match(j, i)) {
                    advance(i, 2);
                    if (!match(j, i)) i = ++j;
                }
            } else if (distance(beg, i) >= 1) {
                card_list::iterator j = i;
                advance(i, -1);
                if (!match(j, i)) i = ++j;
            } else ++i;
        }

        int n = cards.size();
        if (n > 1) cout << n << " piles remaining:";
        else cout << n << " pile remaining:";
        for (card_list::iterator i = cards.begin(); i != cards.end(); ++i)
            cout << " " << (*i).size();
        cout << endl;
    }
    return 0;
}