forked from carykh/PrisonersDilemmaTournament
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request carykh#53 from djlf4568/patch-1
Create qftft.py
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
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 |