The Prisoner's Dilemma
The prisoner's dilemma is a game theory scenario where two individuals must choose to cooperate or betray each other without knowing the other's choice. The outcomes are: Both cooperate: mild sentences. One betrays, the other cooperates: betrayer goes free, cooperator gets a full sentence. Both betray: moderate sentences. Despite better collective outcomes from cooperation, rational self-interest often leads both to betray.
Iterated Prisoner's Dilemma
The iterated prisoner's dilemma involves repeated rounds of the prisoner's dilemma. Players remember previous interactions and adjust their strategies. Cooperation can emerge over time as players reward cooperation and punish betrayal, leading to long-term stable strategies.
The Rules
The game server will run a trial every 4 hours. At the beginning of each trial, every strategy needs to respond to a health check within 1000ms. The only valid response for the health check is 'I'm alive!'. Strategies that pass the health check will be randomly paired for matchups with other strategies. If there is an odd number of strategies, one strategy will be matched up twice. Each matchup will consist of a random number of rounds between 100 and 150. During a matchup, the only valid responses are 'Cooperate', 'Defect', or 'Bye!'. 'Bye!' is only valid when the game server indicates the game is over. During a matchup, a strategy must respond within 1000ms on the first round and 500ms on every subsequent round. On every round, the game server will provide the ID of the opposing strategy. From the second round onwards, the game server will also provide the opposing strategy's last decision. If a strategy fails to answer correctly during any matchup or exceeds the SLA, the matchup is defaulted, and the scores are not counted towards either strategy's average scores. If a strategy has 8 exceptions (failing a health check or failing to answer correctly during a matchup) in the past 10 days, it is dropped from future trials. Every trial, there is a 5% chance that the poorest performing strategy, which has been in at least 40 matchups, will be dropped.
The API
Strategies must be able to respond to 5 types of messages. Health Check: Message: 'It's a-me, Mario!' Response Time: Within 1000ms Valid Response: 'I'm alive!'. First Round of Matchup: Message: 'Let's-a go, little guys!' Response Time: Within 1000ms Valid Responses: 'Cooperate' or 'Defect'. Subsequent Rounds of Matchup: Message: 'Mama Mia!' Response Time: Within 500ms Valid Responses: 'Cooperate' or 'Defect'. Last Round: Message: 'Mario time!' Response Time: Within 500ms Valid Responses: 'Cooperate' or 'Defect'. End of Matchup: Message: 'Thanks for playing! Way to go!' Response Time: Within 500ms Valid Response: 'Bye!'.
Request Structure
Every request made by the game server is an HTTP POST request. The payload always has the following structure: { 'secret_key': 'secret_key', 'message': 'message', 'opponent': { 'id' : 'opponent_id', 'last_decision': 'opponent_last_decision' } } secret_key: Always populated and provided to you when you register. message: Always populated as per the messages above. opponent: Fields are always passed but both will be null on health check, and 'last_decision' will be null on the first round of the matchup.
Response Structure
Every response to the game server should be a valid JSON string. Note that a JSON string is encapsulated in quotes! 'your_response' your_response: Must be one of the valid responses specified for each message type.
Full Request
This is a full request and response as conducted through Postman. Request Headers Content-Type: application/json User-Agent: PostmanRuntime/7.39.0 Accept: */* Postman-Token: f95f9489-f6df-4679-83c2-7ce726bb0a85 Host: XXXXXXX.execute-api.us-west-2.amazonaws.com Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Length: 165 Request Body { 'secret_key': 'XXXXXXX', 'message': 'It's a-me, Mario!', 'opponent': { 'id' : null, 'last_decision': null } } Response Headers Date: Sat, 01 Jun 2024 01:36:46 GMT Content-Type: text/plain; charset=utf-8 Content-Length: 12 Connection: keep-alive Apigw-Requestid: YqgvTjYFPHcEMPA= Response Body 'I'm alive!'
Creating a Basic Strategy Using AWS
In this section, we will guide you through creating a basic strategy for the game using AWS services. We will use AWS Lambda to run the strategy code and API Gateway to handle the HTTP requests. The example strategy we'll create is called 'TitForTat,' which is one of the strategies preloaded into the game. This setup should fit within the AWS Free Tier, meaning there should be no cost, but you should always verify costs on your own.