Last active
October 22, 2019 16:03
-
-
Save ali-ramadhan/2984abdcbba3a5bae05142e1266ce1f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import random, choices | |
from Prisoner import Prisoner | |
""" | |
SchizophrenicRetribution: an old Prisoner who usually copies their | |
opponent's last choice, but forgets what to do as time goes on so | |
they usually just cooperate with anyone and everyone. | |
They won't stop telling you the same stories from their glory days | |
as a TitForTat. | |
""" | |
class SchizophrenicRetribution(Prisoner): | |
def __init__(self): | |
self.round_number = 0 | |
self.last_strategy = True | |
def pick_strategy(self): | |
r = random() | |
# 0 < schizophrenic factor < 1 increases with round number | |
# and maximum schizophrenia sets in after 100 rounds. | |
sf = min(self.round_number / 100, 1) | |
if r < (1 - 0.1*sf): | |
return self.last_strategy | |
else: | |
return choices([True, False], weights=[4, 1]) | |
def process_results(self, my_strategy, other_strategy): | |
self.round_number = self.round_number + 1 | |
self.last_strategy = other_strategy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment