Skip to content

Commit

Permalink
Merge pull request carykh#54 from djlf4568/patch-2
Browse files Browse the repository at this point in the history
Create rqftft.py
  • Loading branch information
nekiwo authored May 28, 2021
2 parents c5bb452 + 4c80613 commit dc1d116
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions code/djlf4568/rqftft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Email: [email protected]
# 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

0 comments on commit dc1d116

Please sign in to comment.