A game I learned many years ago is played as follows: There are three pegs that
ID: 3827269 • Letter: A
Question
A game I learned many years ago is played as follows:There are three pegs that have rings on them. The first peg has 3 rings. The second peg has 5 rings. The theird peg has 7 rings.
There are 2 players.
Each player takes turns removing some peg(s) from rings, until there are no more pegs left.
The player that removes the last ring(s) loses the game.
For each turn, the player whose turn it is can remove anywhere from 1 to all the rings on any peg that has rings. They cannot remove pegs from multiple rings at once. They cannot skip a move.
Write your c++ program such that each of the 2 players inputs a move each time, and show the results after each move.
Tell who wins at the end of a game.
At the start of each game, ask who will go first and start the game with that person.
Be sure to test input for a move to verify the peg and the number of rings given is valid.
The object should be the 3 pegs and their rings. You can decide what constructors and functions you will need -- probably a constructor to set the pegs up to start with, a function for a "game", a function for a "move", a function to output the pegs/rings to the screen, etc.
---------------------------------------------------------------
For extra credit:
Have a player be the machine.
Any time the machine is to make a move, have the machine make an optimal move. Note that this game can be won every time by whoever goes first.
If the machine goes first, have them randomly make a move of 1 peg that is "safe", and then their subsequent moves are dictated by the other player.
If the machine goes last, have them make an optimal move any time the other player screws up. If the other player doesn't screw up, have them make a move that is either minimal with respect to number of pegs removed, or is furthest away from a combination that is close to the other player winning.
(There are certain combinations you want to leave your opponent with after your move and any time you can get them into one of those, you can force a win from there -- look at simple situations and start working backwards and you can find them all -- load them into a table for the machine to search.) A game I learned many years ago is played as follows:
There are three pegs that have rings on them. The first peg has 3 rings. The second peg has 5 rings. The theird peg has 7 rings.
There are 2 players.
Each player takes turns removing some peg(s) from rings, until there are no more pegs left.
The player that removes the last ring(s) loses the game.
For each turn, the player whose turn it is can remove anywhere from 1 to all the rings on any peg that has rings. They cannot remove pegs from multiple rings at once. They cannot skip a move.
Write your c++ program such that each of the 2 players inputs a move each time, and show the results after each move.
Tell who wins at the end of a game.
At the start of each game, ask who will go first and start the game with that person.
Be sure to test input for a move to verify the peg and the number of rings given is valid.
The object should be the 3 pegs and their rings. You can decide what constructors and functions you will need -- probably a constructor to set the pegs up to start with, a function for a "game", a function for a "move", a function to output the pegs/rings to the screen, etc.
---------------------------------------------------------------
For extra credit:
Have a player be the machine.
Any time the machine is to make a move, have the machine make an optimal move. Note that this game can be won every time by whoever goes first.
If the machine goes first, have them randomly make a move of 1 peg that is "safe", and then their subsequent moves are dictated by the other player.
If the machine goes last, have them make an optimal move any time the other player screws up. If the other player doesn't screw up, have them make a move that is either minimal with respect to number of pegs removed, or is furthest away from a combination that is close to the other player winning.
(There are certain combinations you want to leave your opponent with after your move and any time you can get them into one of those, you can force a win from there -- look at simple situations and start working backwards and you can find them all -- load them into a table for the machine to search.) A game I learned many years ago is played as follows:
There are three pegs that have rings on them. The first peg has 3 rings. The second peg has 5 rings. The theird peg has 7 rings.
There are 2 players.
Each player takes turns removing some peg(s) from rings, until there are no more pegs left.
The player that removes the last ring(s) loses the game.
For each turn, the player whose turn it is can remove anywhere from 1 to all the rings on any peg that has rings. They cannot remove pegs from multiple rings at once. They cannot skip a move.
Write your c++ program such that each of the 2 players inputs a move each time, and show the results after each move.
Tell who wins at the end of a game.
At the start of each game, ask who will go first and start the game with that person.
Be sure to test input for a move to verify the peg and the number of rings given is valid.
The object should be the 3 pegs and their rings. You can decide what constructors and functions you will need -- probably a constructor to set the pegs up to start with, a function for a "game", a function for a "move", a function to output the pegs/rings to the screen, etc.
---------------------------------------------------------------
For extra credit:
Have a player be the machine.
Any time the machine is to make a move, have the machine make an optimal move. Note that this game can be won every time by whoever goes first.
If the machine goes first, have them randomly make a move of 1 peg that is "safe", and then their subsequent moves are dictated by the other player.
If the machine goes last, have them make an optimal move any time the other player screws up. If the other player doesn't screw up, have them make a move that is either minimal with respect to number of pegs removed, or is furthest away from a combination that is close to the other player winning.
(There are certain combinations you want to leave your opponent with after your move and any time you can get them into one of those, you can force a win from there -- look at simple situations and start working backwards and you can find them all -- load them into a table for the machine to search.)
Explanation / Answer
#include #include #include #include using namespace std; int main() { char cAgain; do { //Declaration of variable int x, PegTotal, PegOne = 3, PegTwo = 5, PegThree = 7, Player, y; bool switchRepeat = true; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.