From 4c8061370d6a78895d661571bda8f5b09eb00ab5 Mon Sep 17 00:00:00 2001 From: djlf4568 <74474584+djlf4568@users.noreply.github.com> Date: Thu, 27 May 2021 21:10:42 -0700 Subject: [PATCH] Create rqftft.py --- code/djlf4568/rqftft.py | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 code/djlf4568/rqftft.py diff --git a/code/djlf4568/rqftft.py b/code/djlf4568/rqftft.py new file mode 100644 index 0000000..6ad7667 --- /dev/null +++ b/code/djlf4568/rqftft.py @@ -0,0 +1,48 @@ +# Email: danieljin4568@gmail.com +# Revised version of qftft ("Quarter" Forgiving Tit For Tat) +# Includes random strategy detection (sort of) +# I'd be surprised if this actually works + +# "cooperate" = 1, "defect" = 0 + +def strategy(history, memory): + global cCount + global cRDCount + choice = None + + if history.shape[1] == 0: # first turn + cCount = 0 + cRDCount = 0 + choice = "cooperate" + if history.shape[1] > 1 and history[0,-2] == 1: + cCount += 1 + if history[1,-1] == 0 and history[0,-2] == 1: + cRDCount += 1 + + if history.shape[1] == 0: + pass + elif history.shape[1] == 1: # second turn + if history[1,-1] == 0: # if opp defect last turn + choice = "defect" + else: + choice = "cooperate" + elif cCount >= 10 and cRDCount / cCount > 0.3: # if detect random + choice = "defect" + elif history.shape[1] >= 4 and history[1,0] == 0 and history[1,1] == 0 and history[1,2] == 0 and history[1,3] == 0: + choice = "defect" + elif history.shape[1] >= 4 and history[1,0] == 1 and history[1,1] == 1 and history[1,2] == 1 and history[1,3] == 1: + choice = "cooperate" + + else: + if history[0,-1] == 0: # if i defect last turn + choice = "cooperate" + else: + if history[1,-1] == 0: # if opp defect last turn + if history[0,-2] == 1: # if i cooperate two turns ago + choice = "defect" + else: + choice = "defect" + else: + choice = "cooperate" + + return choice, None