Hello everyone,
Here's a block of code I'm having trouble with.
string Game::tradeRandomPieces(Player & player)
{
string hand = player.getHand();
string piecesRemoved;
size_t index;
//Program crashes while calculating numberOfPiecesToTrade...
size_t numberOfPiecesToTrade = rand() % hand.size() + 1
for (; numberOfPiecesToTrade != 0; --numberOfPiecesToTrade)
{
index = rand() % hand.size();
piecesRemoved += hand[index];
hand.erase(index,1);
}
player.removePiecesFromHand(piecesRemoved);
player.fillHand(_deck);
return piecesRemoved;
}
I believe the code is pretty self explanatory.
fillhand
and removepiecesfromhand
are working fine, so that's not it.
I really can't get what's wrong with this :(
Thanks for your time
EDIT OK, I found out where the program crashes. Added a comment to the above source code.