// // zone.cpp // cards-proof // // Created by Ethan Miller on 4/6/12. // #include #include #include #include "zone.h" using namespace std; zone::zone() { is_public_ = true; } zone::zone(bool is_public) { is_public_ = is_public; } void zone::add(card c, int n) { for (int i = 0; i < n; ++i) { contents_.push_back(c); } } void zone::add_top(card c, int n) { for (int i = 0; i < n; ++i) { contents_.push_front(c); } } card zone::remove_card(string name) { card c; list::iterator itr = sequential_search_cards(name); if (itr == contents_.end()) { return c; } c = *itr; contents_.erase(itr); return c; } void zone::shuffle() { // Implementation: Copy to vector, shuffle vector, copy back from vector vector temp_deck; temp_deck.resize( contents_.size() ); list::iterator itr = contents_.begin(); int i = 0; while ( itr != contents_.end() && i < temp_deck.size() ) { temp_deck[i] = *itr; ++i; ++itr; } srand( unsigned (time(NULL)) ); // Seed the random number generator random_shuffle(temp_deck.begin(), temp_deck.end()); itr = contents_.begin(); i = 0; while ( itr != contents_.end() && i < temp_deck.size() ) { *itr = temp_deck[i]; ++i; ++itr; } } void zone::print() { for (list::iterator itr = contents_.begin(); itr != contents_.end(); ++itr) { cout << itr->name() << endl; } } list::iterator zone::sequential_search_cards(string name) { for (list::iterator itr = contents_.begin(); itr != contents_.end(); ++itr) { if (itr->name() == name) { return itr; } } return contents_.end(); }