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!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
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
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?