Question: Python This project is about a simple two-player game. In the game each player has only two choices: they can cooperate or cheat. They choose

 Python This project is about a simple two-player game. In thegame each player has only two choices: they can cooperate or cheat.They choose secretly, so they do not know what their opponent willdo. Each player gets a score (or "payoff") as follows: - if

both players cheat, they both get 0 points - if both playersPython

This project is about a simple two-player game. In the game each player has only two choices: they can cooperate or cheat. They choose secretly, so they do not know what their opponent will do. Each player gets a score (or "payoff") as follows: - if both players cheat, they both get 0 points - if both players cooperate, they both get 2 points - if one player cooperates and one player cheats, the one who cheats gets 3 points and the one who cooperates gets 1 points. The game is played several times and whoever has the most points at the end is the winner. cooperate =0 cheat =1 A playing strategy will be represented by a function which takes a single argument and outputs either cooperate or cheat . The argument to the function be a list history of the choices the opponent has made so far, starting with the first choice and ending with the most recent choice. For example, if no games have been played yet then history would be the empty list [], and if three games have been played and the opponent cooperated in the first game and then cheated in the next two games, history would be equal to Write functions implementing the following strategies. 1. Always cooperate. 2. ("tit for tat") On the first game, cooperate. After that do whatever the opponent did in the previous game. 3. ("random choice") In each game, cheat with probably 1/2, otherwise cooperate. 4. ("grudge") If your opponent has ever cheated, cheat. Otherwise cooperate. For part 3, it may be helpful to import random and investigate random. choice or use to use the function random. random() which generates a uniform random number between 0 and 1 . Write a function play_n_games (player1, player2, n ). The arguments player1 and player2 should be strategy functions like the ones you wrote in Exercise 1. The function should run n games between the two players, and should return a tuple (score1, score2) where score1 is player1 's score after n games and score2 is player2 's score after n games. You will need to keep lists history1 and history2 of the moves made by player1 and player2 to supply the arguments to the planerions, and upe these lists each time a game is played. Print the values of: - play_n_games(always_cooperate, tit_for_tat, 10) - play_n_games(always_cheat, tit_for_tat, 10) - play_n_games(grudge, tit_for_tat, 10) - play_n_games(grudge, always_cheat, 10) The output of play_n_games(always_cheat, always_cooperate, 10) should be (30,10) Write a function tournament (player_list). The argument player_list will be a list of strategy functions [player1, ..., playerN] . Every player should play every other player exactly ten times - that is, you need to call play_n_games once with n=10 for each pair of distinct players from player_list . The function should return a list [ score1, ...., scoreN] of the total scores of each player. Print the output of - tournament([always_cheat, always_cheat, always_cheat, always_cheat, tit_for_tat, tit_for_tat, tit_for_tat]) - tournament([always_cheat, always_cooperate, tit_for_tat, tit_for_tat]) - tournament([grudge, grudge, grudge, random_choice, always_cheat, always_cheat, tit_for_tat, tit_for_tat, tit_for_tat])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!