Question: For Part C, you will be creating an interface for two people to play a simple game of Pick-Up Sticks. Heres how the game is
For Part C, you will be creating an interface for two people to play a simple game of Pick-Up Sticks. Heres how the game is to be played.
The game begins with a number of sticks on a tablebetween 10 and 100.
Each player, in turn, picks up 13 sticks off the table.
The player to take the last stick loses.
Your job is to build a virtual version of the game using Python. The program is broken into a series of parts to help you understand how to put together a game with several different components. Each part builds on the previous one so you should complete them in order and only turn in the final part (the two-player version) as your solution.
Single-Player Game
Begin by asking the user for a number of sticks to be used in the game. Only accept numbers between 10 and 100if the user supplies a number outside of this range you should prompt them to re-enter the number.
Next, continually announce to the user how many sticks are on the table and ask the user to enter a number of sticks to take away. Only accept choices of 1, 2, or 3 sticksanything else should cause an error message to be displayed. Once a valid number of sticks has been entered, you should deduct that number from the total number of sticks in the game. When you reach 0 sticks left, the game is over.
Here is a sample running of the program.
How many sticks to start with (10-100)? 999 Sorry, that's too many sticks. Try again. How many sticks to start with (10-100)? -10 Sorry, that's too few sticks. Try again. How many sticks to start with (10-100)? 10 Great, let's play . . . There are 10 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 999 Sorry, that's not a valid number. There are 10 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 0 Sorry, that's not a valid number. There are 10 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 3 There are 7 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 2 There are 5 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 3 There are 2 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 2 There are no sticks left on the table. Game over.
Two-Player Game
As you can see, the single-player version of this game isnt very fun. To make things more interesting we are now going to add an element of competition. For this part you will be implementing a two-player game where players take turns picking up sticks from the table. The same rules applyeach player can only take 1, 2, or 3 sticks per turn. The player who takes the last stick off of the table loses.
Here is a sample running of the game.
How many sticks to start with (10-100)? 250 Sorry, that's too many sticks. Try again. How many sticks to start with (10-100)? 10 Great, let's play . . . Turn: Player 1 There are 10 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 999 Sorry, that's not a valid number. Turn: Player 1 There are 10 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 0 Sorry, that's not a valid number. Turn: Player 1 There are 10 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 3 Turn: Player 2 There are 7 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 2 Turn: Player 1 There are 5 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 3 Turn: Player 2 There are 2 sticks on the table. How many sticks do you want to take (1, 2 or 3)? 1 Turn: Player 1 There is 1 stick on the table. How many sticks do you want to take (1, 2 or 3)? 0 Sorry, that's not a valid number. Turn: Player 1 There is 1 stick on the table. How many sticks do you want to take (1, 2 or 3)? 1 There are no sticks left on the table. Game over. Player 2 wins!
Here are some hints to get you started.
You may want to use a variable to keep track of the players and whos turn it is.
You only want to switch turns when the player takes a valid number of sticks.
Dont allow players to take more than the total number of sticks on the table. For example, if there are two sticks left the player should not be able to take three sticks.
The player who does not take the last stick is the winner.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
