Giter VIP home page Giter VIP logo

prisoner's Introduction

Prisoner

A Python prisoner's dilemma competition adjudicator, written in Coconut.

Goal

The goal of the competition is to write a Prisoner's Dilemma bot that survives into the final round. Each round, every bot is pitted against every other bot for approximately (but not usually exactly) 100 rounds, and the bot or bots with the lowest average score among all the games they played that round are eliminated. The game continues until all the bots left are tied.

Score is determined as follows:

  • Both cooperate:
    • +1 score for both
  • Both defect:
    • no change in score
  • One cooperates, one defects:
    • Cooperator: -1 score
    • Defector: +2 score

Instructions

First, create a Python (.py) file containing this code:

from prisoner.dilemma import *

@pd_bot
def my_bot_name(self_hist, opp_hist, opp_bot):
    <code>

Next, in place of <code>, insert whatever Python code you want that returns either True for cooperate or False for defect. To do this, you have use of the arguments self_hist (a list containing all your previous moves), opp_hist (a list containing all your opponent's previous moves), and opp_bot (your opponent's bot function).

All bot functions will be timed out in the case of infinite recursion and False assumed if nothing has been returned. To prevent this, bots may be added together, and if the first bot times out the second bot will be used instead.

Examples

Cooperate:

@pd_bot
def cooperate_bot(self_hist, opp_hist, opp_bot):
    return True

Defect:

@pd_bot
def defect_bot(self_hist, opp_hist, opp_bot):
    return False

Coin Flip:

@pd_bot
def coin_flip_bot(self_hist, opp_hist, opp_bot):
    return random.getrandbits(1)

Tit for Tat:

@pd_bot
def tit_for_tat_bot(self_hist, opp_hist, opp_bot):
    if opp_hist:
        return opp_hist[-1]
    else:
        return True

Mirror:

@pd_bot
def mirror_bot(self_hist, opp_hist, opp_bot):
    return opp_bot(opp_hist, self_hist, mirror_bot)
mirror_bot += cooperate_bot

prisoner's People

Contributors

evhub avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.