int Table::addPlayer(Player const& player, int position)
{
if (position > 0 || position < 11) {
deque<Player>::iterator it = playerList.begin()+position;
deque<Player>::iterator itStart = playerList.begin()+postion;
while(*it != "(empty seat)") {
it++;
if (it == playerList.end()) {
it = playerList.begin();
}
if (it == itStart) {
cout << "Table full" << endl;
return -1;
}
}
//TODO overload Player assignment, << operator
*it = player;
cout << "Player " << player << " sits at position " << it - playerList.begin() << endl;
return it - playerList.begin();
} else {
cout << "Position not a valid position, must be 1-10" << endl;
return -1;
}
}
int Table::removePlayer(Player const& player)
{
for (deque<Player>::iterator it = playerList.begin();it != playerList.end(); it++) {
//TODO Do I need to overload == in Player?
if(*it == player) {
*it = "(empty seat)";
int pos = it - playerList.begin();
cout << "Player " << player << " stands up from position " << pos << endl;
return pos;
}
}
cout << "Player " << player << " not found" << endl;
return -1;
}
Would like some feedback on these two member functions of a Table class for Texas Hold Em Poker simulation. Any information syntax, efficiency or even common practices would be much appreciated.