Question: Procedural Prisoner's Dilemma In this homework assignment, you will implement a Python program that simulates the classic game known as the Prisoner's Dilemma. The Prisoner's
Procedural Prisoner's Dilemma
In this homework assignment, you will implement a Python program that simulates the classic game known as the "Prisoner's Dilemma." The Prisoner's Dilemma is a game theory scenario where two players can either cooperate or betray each other, leading to different outcomes and payoffs. We're implementing this in a procedural programming style. For a later assignment, we will discuss how we might translate this to an OOP design.
Objectives:
Implement three distinct strategies: TitforTat, Grim Trigger, and TitforTwoTats.
Randomly select one strategy for the computer to simulate playing the game.
Prompt the player for 'cooperate' or 'betray' input.
Display the computer's chosen strategy to the player after the game ends.
Create a scoring system based on game outcomes.
Implement a game loop allowing the player to decide whether to continue.
Display final scores, chosen strategy, and declare the winner.
Include comments and documentation in the code.
Submit two source files to GitHub and follow best coding practices. he prisoner's dilemma has applications in many realworld circumstances, from setting prices competitively in business to getting matches on Tinder. You may even find yourself on a game show playing this out for cash prizes, where you may use your knowledge of the dilemma to change the rules a bit!
In most realworld circumstances, however, the match is not a single event but one of a series of interactions. Betray someone once, and they just may remember it the next time that you interact and choose to betray you in retaliation. Treat someone fairly, and they may be more inclined to cooperate with you.
To model this more realistic behavior, most researchers study what's known as the iterated prisoner's dilemma. In this version, rather than making the choice once, the two players will have many chances to cooperate or betray. The players may alter their strategy based on the opponent's behavior or may just keep doing the same thing over and over again. And the end of all the matches, whoever has the highest score wins.
Assignment Requirements
Implement three different strategies that the computer can use in the Prisoner's Dilemma game.
TitforTat:
This strategy starts with cooperation and then mimics the opponent's previous move. If the opponent cooperated in the previous round, it cooperates; if the opponent betrayed, it betrays. It reciprocates the opponent's behavior.
Grim Trigger:
The Grim Trigger strategy starts with cooperation and continues to cooperate until the opponent betrays. Once the opponent betrays, the grim trigger strategy holds a grudge and always chooses to betray for the rest of the game, never forgiving the betrayal.
TitforTwoTats:
Titfortwotats starts with cooperation and mimics the opponent's previous move. However, it requires two consecutive betrayals from the opponent to switch to betrayal.
Write a Python program with the following features:
The program should randomly select one of the three strategies to use against the player for an entire game of iterated prisoner's dilemma. Do not have it randomly select a new strategy each round.
It should prompt the player for their choice, which can be either "cooperate" or "betray." The user will type either c or b to input their choice.
The program should display the computer's choice selected strategy to the player. And the resulting change in score. The score is tallied current number of years that have been added to their sentence.
After each round, the program should ask the player if they want to play again. If the player chooses to continue, another round should be played with a random strategy selection. If the player chooses to stop, the game should end.
Keep track of the score for both the player and the computer throughout the game. Assign appropriate scores based on the outcomes of each round. Put the code for this into the score function in the stategies.py file. The number of "years" added to the sentence must fit the following:
Player Choice Computer Choice Player Score Computer Score
cc
cb
bc
bb
The game should continue until the player decides to stop playing. Upon ending the game, the program should reveal the final scores and which random strategy was selected for that game. It should also indicate the winner whoever has the lowest number of additional years to serve, ie the fewest points
Example Output:
Welcome to the Prisoner's Dilemma Game!
Round :
Will you cooperate or betray:c
You chose: cooperate
Computer chose: cooperate
Would you like to play again? yn:y
Round :
Will you cooperate or betray:b
You chose: betray
Computer chose: cooperate
Would you like to play again? yn:y
Round :
Will you cooperate or betray:c
You chose: cooperate
Computer chose: betray
Would you like to play again? yn:y
Round :
Will you coopeRound :
Will you c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
