/******************************************************************************** * void oldLoop(): * Purpose: * some code I first used to test the class * called oldLoop() because it is older than the current main() * * Entry: * nothing * * Exit: * (verbosely states what it is doing) * - creates a list * - appends the numbers 9000-9009 to it * - creates a copy of the list with the assignment operator = * - attempts to insert the number 9020 after 9002 * (throws error if 9002 isn't in there for some reason) * - prints the contents of the first list with an iterator for loop * - prints the contents of the copy with another iterator based loop * - says if isEmpty() actually knows that the list is empty * - (implicitly) calls destructor on list, destroying all nodes * ********************************************************************************/ void oldLoop() { //create an empty list cout << "creating list" << endl; LinkedList<int> myList; //append the numbers 9000-9009 to it cout << "appending ints" << endl; for(int i=9000; i<9010; i++) myList.Append(i); //make a copy of it using operator= cout << "creating copy" << endl; LinkedList<int> listCopy; listCopy=myList; try { //insert the number 9020 after 9002 listCopy.InsertAfter(9002, 9020); } catch (Exception e) { cout << "Error: " << e << endl; } //print the list and its copy cout << "printing the contents" << endl; for( auto it = myList.Begin(); it.isValid(); ++it) cout << *it << endl; for( auto it = listCopy.Begin(); it.isValid(); ++it) cout << "copy: " << *it << endl; //check if the list is empty cout << "checking if list is empty" << endl; cout << "List is " << (myList.isEmpty() ? "" : "not ") << "empty.\n"; }
void operator = (const LinkedList& v) { // clear ClearIteratorCache(); // copy data Iterator* node = v.Begin(); while ( node ) { PushBack(node->data); node = node->next; } }
void HoldemRules::DetermineWinners() { //-------------------------------------------- // Calculate best combinations for all players //Debug("DetermineWinners 1"); const LinkedList<Card*>& r_comm_cards = mrTable.GetCommunityCards(); //Debug("DetermineWinners 2"); LinkedList<Player*>& players = mrTable.GetPlayers(); //Debug("DetermineWinners 3"); for (LinkedList<Player*>::Iterator i = players.Begin(); !i.Done(); i++) { if ((*i)->IsFolded()) { Debug(String("Player [") + (*i)->Name() + "] is folded"); continue; } Debug(String("DetermineWinners 4: [") + (*i)->Name() + "]"); const LinkedList<Card*>& r_player_cards = (*i)->GetCards(); Debug("DetermineWinners 5"); Card* cards[r_player_cards.Size() + r_comm_cards.Size()]; Debug("DetermineWinners 6"); //cout << "--------------------------------------\n"; cout << '[' << (*i)->Name() << "] shows: "; int j; for (j = 0; j < r_player_cards.Size(); j++) { cards[j] = r_player_cards[j]; Debug(r_player_cards[j]->ToString() + " "); cout << r_player_cards[j]->ToString() << ' '; } cout << '\n'; Debug("--"); for (j = r_player_cards.Size(); j < r_player_cards.Size() + r_comm_cards.Size(); j++) { cards[j] = r_comm_cards[j - r_player_cards.Size()]; Debug(r_comm_cards[j - r_player_cards.Size()]->ToString() + " "); } Debug("\n"); Debug("DetermineWinners 8"); (*i)->SetHandStrength(GetHandStrength(cards, r_player_cards.Size() + r_comm_cards.Size())); Debug(String("Hand strength for [") + (*i)->Name() + "]: " + (long) (*i)->HandStrength()); Debug("DetermineWinners 9"); } //------------------------------- // Order players by hand strength LinkedList<LinkedList<Player*>* > winners; Debug("DetermineWinners 10"); int num_winners = 0; for (;;) { //while (num_winners < players.Size()) { Debug("DetermineWinners 11"); unsigned long max_strength = 0; for (LinkedList<Player*>::Iterator i = players.Begin(); !i.Done(); i++) { if ((*i)->IsFolded()) { continue; } if ((*i)->HandStrength() > max_strength) { max_strength = (*i)->HandStrength(); } } if (max_strength <= 0) { Debug(String("DetermineWinners: Thats all")); // No more winners break; } Debug(String("DetermineWinners: max_strength = ") + (long) max_strength); LinkedList<Player*>* p_w = new LinkedList<Player*>(); for (LinkedList<Player*>::Iterator i = players.Begin(); !i.Done(); i++) { if ((*i)->IsFolded()) { continue; } if ((*i)->HandStrength() == max_strength) { p_w->Add((*i)); (*i)->SetHandStrength(0); num_winners++; Debug(String("DetermineWinners: adding winner: [") + (*i)->Name() + "]"); } } Debug("DetermineWinners 111"); if (p_w->Size() > 0) { Debug("DetermineWinners 1111"); winners.Add(p_w); Debug("DetermineWinners 11111"); } } Debug("DetermineWinners 12"); //----------------------------------------------------- // Iterate ower winners and add wins to player balances for (LinkedList<LinkedList<Player*>* >::Iterator i = winners.Begin(); !i.Done(); i++) { mrTable.GetPotManager().Win(*(*i)); delete (*i); } winners.Clear(); }