During your latest trek through the dense undergrowth of Cedar Pines, you stumble upon a curious arrangement of small gemstones on a stone tablet in a clearing near the legendary Sasquatch sighting hotspot. Intrigued by the precision and care with which these gems are laid out, you recall tales from the local folklore—stories that speak of Sasquatch not only as a creature of the woods but also as one fond of testing the intellect of those who dare to tread into its territory.
Arranged in a neat pile, the gemstones number exactly 23—a figure that resonates with ancient cryptological lore associated with Sasquatch, suggesting a game of wit and strategy. Recalling the rules from an old cryptologist’s journal housed within the Cedar Pines Cryptological Society’s archives, you recognize this setup as a traditional challenge known locally as the “Gemstone Conundrum.”
During your first encounter, intrigued and eager to engage with the unknown, you decide to remove 3 stones, reducing the pile to 20. The following morning, upon your return, you find that the pile has dwindled to 17 stones, indicating that Sasquatch, having understood your challenge, has taken its turn by removing 3 stones as well.
Gem Game on a Stone tablet/table. Image generated by Microsoft Copilot.
Rules of the game:
The game starts with a pile of 23 gemstones.
Each player, on their turn, may remove 1, 2, or 3 gemstones from the pile.
The player who takes the last 1, 2, or 3 gemstones wins the game.
For the CTF portion of this challenge:
Given a pile containing x stones and the rules listed above, return whether or not you're in a winning position:
winningPosition(23) --> True
winningPosition(8) --> False
Build the game:
Get the # of stones the game will start with from the user (doesn't always have to be 23)
Ask the user if they would like to go first.
As long as there are stones
If it's the player's turn
Get the player's # of stones to take (user input)
If it's the computer's turn
Get the computer's # of stones to take (random #... kindof - see notes below)
Remove the # of stones
switch turns
Determine the winner (whoever took the last stones)
Additional requirements:
Smart Sasquatch
Your opponent should play smart.
If they can get a winning position, they should always take the winning option.
If they can't, they should choose a random # (between 1-3 inclusive)
Input validation
Every response from the user has to be validated (you can assume the user will correctly type words when asked for words and #'s when asked for #'s).
If you're asking for "yes" or "no" and you get something else, you should force the user to try again until they give a "yes" or "no" response
If you're asking for the # of stones to take, the user shouldn't be able to pick less than 1
If you're asking for the # of stones to take, the user shouldn't be able to pick more than 3
If you're asking for the # of stones to take, the user shouldn't be able to take more than are in the pile.
Suggestions:
Make a playerChoice function to validate user input and return the valid response. As long as it's not valid, they should keep asking.
Make a computerChoice function to get the computer's choice, using the smart sasquatch logic.
Extra Credit:
Allow the user to decide the maximum # of sticks each person can grab - the default is 3, but you can change that. If you do this, everything that previously restricted things to 3 should now be adjusted to the new value.
Allow the user to choose an easy or hard mode.
Hard most is as described with Smart Sasquatch
Easy mode is always random (though you can improve this by adding something that says "if you can take the winning amount, take it"
Allow the user to choose to play another user instead of the computer. (for this, you have to allow both options)