I am having trouble implementing "play previous hand" in the Word Game problem. When the player enters "r" for "replay", the game displays, instead of the original hand, the hand with letters missing. I think there is a side-effect going on in my update_hand function, and i don't know how to identify or fix it. Here is the relevant code. Thanks! http://dpaste.com/1046521/
2008 or 2011? update_hand is not supposed to mutate hand - yours does however, the symptom you describe is is caused elsewhere - where does hand come from?
2011. I changed my update_hand first copying hand http://dpaste.com/1047548/ By not mutating the hand, I am able to use replay correctly. I am a little confused why this happened. Why is it that when I set hand = updated_hand inside play_hand it effects the hand in play_game() only when hand is mutated? Is it because when hand is created in play_game it points to the full hand. Then in play_hand, hand eventually points to a new value equal to updated_hand. Thus, when play_hand ends, hand points what it did originally in play_hand?
Join our real-time social learning platform and learn together with your friends!