Skip to content

Commit

Permalink
Merge pull request carykh#53 from djlf4568/patch-1
Browse files Browse the repository at this point in the history
Create qftft.py
  • Loading branch information
nekiwo authored May 28, 2021
2 parents 00f3fb9 + 6d5bd09 commit c5bb452
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions code/djlf4568/qftft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# email: [email protected]
# discord: DJLF#6985

def strategy(history, memory):
# "cooperate" = 1, "defect" = 0
choice = None
if history.shape[1] == 0: # first turn
choice = "cooperate"
elif history.shape[1] == 1: # second turn
if history[1,-1] == 0: # if opp defect last turn
choice = "defect"
else:
choice = "cooperate"
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: # not first or second turn
if history[0,-1] == 0: # if i defect last turn
choice = "cooperate"
else: # if i cooperate last turn
if history[1,-1] == 0: # if opp defect last turn
if history[0,-2] == 1: # if i cooperate two turns ago
choice = "defect"
else: # if i defect two turns ago
choice = "defect"
else: # if opp cooperate last turn
choice = "cooperate"

return choice, None

0 comments on commit c5bb452

Please sign in to comment.