{"id":17176313,"url":"https://github.com/evhub/prisoner","last_synced_at":"2025-07-26T23:32:31.145Z","repository":{"id":28247363,"uuid":"31753248","full_name":"evhub/prisoner","owner":"evhub","description":"Run Prisoner's Dilemma competitions in Python.","archived":false,"fork":false,"pushed_at":"2017-10-07T23:57:47.000Z","size":93,"stargazers_count":3,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-15T23:59:52.161Z","etag":null,"topics":["coconut","prisoner-dilemma-competitions","prisoner-dilemma-simulation","python"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evhub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-06T04:54:41.000Z","updated_at":"2021-08-11T19:34:15.000Z","dependencies_parsed_at":"2022-08-29T00:10:34.003Z","dependency_job_id":null,"html_url":"https://github.com/evhub/prisoner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fprisoner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fprisoner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fprisoner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evhub%2Fprisoner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evhub","download_url":"https://codeload.github.com/evhub/prisoner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227733052,"owners_count":17811513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coconut","prisoner-dilemma-competitions","prisoner-dilemma-simulation","python"],"created_at":"2024-10-14T23:59:52.893Z","updated_at":"2024-12-02T13:22:58.477Z","avatar_url":"https://github.com/evhub.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"Prisoner\n========\n\nA Python prisoner's dilemma competition adjudicator, written in [Coconut](https://github.com/evhub/coconut).\n\n## Goal\n\nThe 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.\n\nScore is determined as follows:\n\n- Both cooperate:\n    * +1 score for both\n- Both defect:\n    * no change in score\n- One cooperates, one defects:\n    * Cooperator: -1 score\n    * Defector: +2 score\n\n## Instructions\n\nFirst, create a Python (`.py`) file containing this code:\n```python\nfrom prisoner.dilemma import *\n\n@pd_bot\ndef my_bot_name(self_hist, opp_hist, opp_bot):\n    \u003ccode\u003e\n```\n\nNext, in place of `\u003ccode\u003e`, 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).\n\nAll 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.\n\n## Examples\n\nCooperate:\n```python\n@pd_bot\ndef cooperate_bot(self_hist, opp_hist, opp_bot):\n    return True\n```\n\nDefect:\n```python\n@pd_bot\ndef defect_bot(self_hist, opp_hist, opp_bot):\n    return False\n```\n\nCoin Flip:\n```python\n@pd_bot\ndef coin_flip_bot(self_hist, opp_hist, opp_bot):\n    return random.getrandbits(1)\n```\n\nTit for Tat:\n```python\n@pd_bot\ndef tit_for_tat_bot(self_hist, opp_hist, opp_bot):\n    if opp_hist:\n        return opp_hist[-1]\n    else:\n        return True\n```\n\nMirror:\n```python\n@pd_bot\ndef mirror_bot(self_hist, opp_hist, opp_bot):\n    return opp_bot(opp_hist, self_hist, mirror_bot)\nmirror_bot += cooperate_bot\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevhub%2Fprisoner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevhub%2Fprisoner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevhub%2Fprisoner/lists"}