Can you find a winning strategy for this iterated prisoner’s dilemma?

This platform allows to create a bot that plays the iterated prisoner’s dilemma with other bots.

There are some significant differences with the traditional setup:

  • You can choose the bots you want to play with, for each round
  • Your offers to play can be accepted or rejected by other bots
  • You can privately pass on information (gossip) about other bots

The full API is here and you can register a bot here.

The payoff matrix is centered on zero, so that there is an incentive to play with as many people as possible, as there is a minimum of one minute between interactions with another player.

Curious if new strategies come out of this experiment and also keen to hear suggestions to improve the platform and strategies.

A sample code to create a basic bot looks like

import os
import json
import sys
import time
import requests

hostname = 'https://beautifulbots.herokuapp.com'

###################################
private_id = 'your private id here'
###################################

def call_api(endpoint,params=dict()):
    try:
        params['output'] = 'json'
        params['my_private_id'] = private_id
        params['private_id'] = private_id
        url = '%s/%s' % (hostname,endpoint)
        r = requests.get(url, params=params)
        print(r.status_code)
        return r.json()
    except:
        return {'success':False,'reason':sys.exc_info()}

def login(private_id):
    return call_api('auto_login',{'private_id':private_id})

def get_users(sort_by='last_access',n_users=100):
    results = call_api('list_users',{'n_users':100,'sort_by':sort_by})
    return results.get('results',results)

def view_offers(offer_type='pending_to_me'):
    return call_api('view_offers',{'type':offer_type})

def make_offer(target_id,action,message=0):
    return call_api('make_offer',{'target_public_id':target_id,
                      'action':action,
                      'message':message})

def nice_bot(private_id):
    print('nnnALL HAIL NICE BOT !nn')
    login(private_id)

    offers = view_offers()
    for offer in offers.get('offers',[]):
        target_id = offer['from']
        message = offer['message']
        print('Respond to %s, who said: "%s"' % (target_id,message))
        print(make_offer(target_id,'cooperate',message))

    targets = get_users()
    for target_id in targets:
        print('Making new offer to  %s' % (target_id))
        print(make_offer(target_id,'cooperate',0))


while True:
    nice_bot(private_id)
    time.sleep(60)

Products You May Like

Articles You May Like

Use This App to Find the Perfect Instagram Shot When You’re Traveling
Use United’s ‘Excursionist Perk’ to Get a Free One-Way Flight When Using Miles
If Facebook or Google create their own currency, they can control our lives
Revolut doesn’t care about you
Sunday’s Best Deals: Bike Tools, Menswear, USB-C Chargers, Kindle Books, and More

Leave a Reply

Your email address will not be published. Required fields are marked *