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#51 from ThatXliner/main
Added my algorithms
- Loading branch information
Showing
7 changed files
with
408 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,140 @@ | ||
import random | ||
import enum | ||
|
||
|
||
class WhatHappened(enum.Enum): | ||
just_told_on_him = "because they are nice and i need advantage" | ||
nothing = None | ||
told_on_him_again = "hope they won't care" | ||
stay_silent_pls = "because they are angry" | ||
stay_lie_pls = "ALWAYS" | ||
|
||
|
||
def strategy(history, memory): | ||
US = history[0] | ||
THEM = history[1] | ||
gametime = history.shape[1] | ||
they_bad = len( | ||
list(filter(lambda x: x == 0, THEM)) | ||
) # The number of times they cooped | ||
they_good = len( | ||
list(filter(lambda x: x == 1, THEM)) | ||
) # The number of times they bad | ||
if len(THEM) <= 1 or memory == "WhatHappened.stay_silent_pls": # Go coop first | ||
return "stay silent", "WhatHappened.nothing" | ||
if they_good > they_bad or THEM[-1] == 1: | ||
if memory in { | ||
"WhatHappened.just_told_on_him", | ||
"WhatHappened.told_on_him_again", | ||
}: # They don't care if we defect | ||
return "tell truth", "WhatHappened.told_on_him_again" | ||
return "stay silent", "WhatHappened.nothing" # Coop! | ||
if they_bad > they_good or THEM[-1] == 0: | ||
if they_good == 0: | ||
return "tell truth", "WhatHappened.just_told_on_him" | ||
# if (they_bad / they_good) <= 1.7: | ||
# print("random") | ||
# print(they_bad / they_good) | ||
if memory == "WhatHappened.just_told_on_him": # punishment? | ||
return ( | ||
"stay silent", | ||
"WhatHappened.told_on_him_again", | ||
) # Tests shows, leaving this out gives more luck | ||
if memory == "WhatHappened.told_on_him_again": # please cool down | ||
return "stay silent", "WhatHappened.stay_silent_pls" | ||
return "tell truth", "WhatHappened.just_told_on_him" | ||
assert they_bad == they_good | ||
print("RANDOM") # on testing, this never runs | ||
return 0, "WhatHappened.nothing" | ||
|
||
|
||
# def strategy(history, memory): | ||
# US = history[0] | ||
# THEM = history[1] | ||
# gametime = history.shape[1] | ||
# they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
# they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
# if len(THEM) <= 1 or memory == WhatHappened.stay_silent_pls: # Go coop first | ||
# return "stay silent", WhatHappened.nothing | ||
# # if they_good == they_bad: | ||
# # ... | ||
# if they_good > they_bad or THEM[-1] == 1: | ||
# if memory in { | ||
# WhatHappened.just_told_on_him, | ||
# WhatHappened.told_on_him_again, | ||
# }: # They don't care | ||
# return "tell truth", WhatHappened.told_on_him_again | ||
# # if random.random() * 100 < 10: | ||
# # return "tell truth", WhatHappened.just_told_on_him | ||
# return "stay silent", WhatHappened.nothing | ||
# if they_bad > they_good or THEM[-1] == 0: | ||
# # if memory == WhatHappened.nothing: | ||
# # return "tell truth", WhatHappened.nothing | ||
# # if they_good == 0: | ||
# # return "tell truth", WhatHappened.stay_lie_pls | ||
# if memory == WhatHappened.told_on_him_again: # please cool down | ||
# return "stay silent", WhatHappened.stay_silent_pls | ||
# if memory == WhatHappened.just_told_on_him: | ||
# return "stay silent", WhatHappened.nothing | ||
# return "tell truth", WhatHappened.just_told_on_him | ||
# assert they_bad == they_good | ||
# print("RANDOM") | ||
# return 0, WhatHappened.nothing | ||
# return ( | ||
# THEM[-1] if random.randint(0, 1) == 0 else random.randint(0, 1) | ||
# ), WhatHappened.nothing | ||
|
||
|
||
# def strategy(history, memory): | ||
# US = history[0] | ||
# THEM = history[1] | ||
# gametime = history.shape[1] | ||
# they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
# they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
# if len(THEM) <= 1 or memory == WhatHappened.stay_silent_pls: # Go coop first | ||
# return "stay silent", WhatHappened.nothing | ||
# if they_good > they_bad or THEM[-1] == 1: | ||
# if memory in { | ||
# WhatHappened.just_told_on_him, | ||
# WhatHappened.told_on_him_again, | ||
# }: # They don't care | ||
# return "tell truth", WhatHappened.told_on_him_again | ||
# # if random.random() < 0.10 and they_good == len(THEM): | ||
# # return "tell truth", WhatHappened.just_told_on_him | ||
# # if gametime >= 50 and they_good == len(THEM): | ||
# # return "tell truth", WhatHappened.just_told_on_him | ||
# return "stay silent", WhatHappened.nothing | ||
# if they_bad > they_good or THEM[-1] == 0: | ||
# # if memory == WhatHappened.nothing: | ||
# # return "tell truth", WhatHappened.nothing | ||
# # if they_good == 0: | ||
# # return "tell truth", WhatHappened.stay_lie_pls | ||
# if memory == WhatHappened.just_told_on_him: # punishment? | ||
# "tell truth", WhatHappened.told_on_him_again | ||
# if memory == WhatHappened.told_on_him_again: # please cool down | ||
# return "stay silent", WhatHappened.stay_silent_pls | ||
# return "tell truth", WhatHappened.just_told_on_him | ||
# assert they_bad == they_good | ||
# return ( | ||
# THEM[-1] if random.randint(0, 1) == 0 else random.randint(0, 1) | ||
# ), WhatHappened.nothing | ||
# def strategy(history, memory): | ||
# US = history[0] | ||
# THEM = history[1] | ||
# gametime = history.shape[1] | ||
# they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
# they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
# if len(THEM) <= 1 or memory == WhatHappened.stay_silent_pls: # Go coop first | ||
# return "stay silent", WhatHappened.nothing | ||
# if they_good > they_bad: | ||
# if memory == WhatHappened.just_told_on_him: # They don't care | ||
# return "tell truth", WhatHappened.told_on_him_again | ||
# # if 40 < gametime: | ||
# # return "tell truth", NOne | ||
# return "stay silent", WhatHappened.nothing | ||
# else: | ||
# if memory == WhatHappened.told_on_him_again: | ||
# return "stay silent", WhatHappened.stay_silent_pls | ||
# # if memory is True: | ||
# # return "stay silent", WhatHappened.nothing | ||
# return "tell truth", WhatHappened.just_told_on_him |
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,12 @@ | ||
def strategy(history, memory): | ||
US = history[0] | ||
THEM = history[1] | ||
gametime = history.shape[1] | ||
they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
if gametime == 0: # Go coop first | ||
return "stay silent", None | ||
if they_good > they_bad: | ||
return "stay silent", None | ||
else: | ||
return "tell truth", None |
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 @@ | ||
def strategy(history, memory): | ||
US = history[0] | ||
THEM = history[1] | ||
gametime = history.shape[1] | ||
they_bad = len( | ||
list(filter(lambda x: x == 0, THEM)) | ||
) # The number of times they cooped | ||
they_good = len( | ||
list(filter(lambda x: x == 1, THEM)) | ||
) # The number of times they bad | ||
if len(THEM) <= 1 or memory == "WhatHappened.stay_silent_pls": # Go coop first | ||
return "stay silent", "WhatHappened.nothing" | ||
if they_good > they_bad or THEM[-1] == 1: | ||
if memory in { | ||
"WhatHappened.just_told_on_him", | ||
"WhatHappened.told_on_him_again", | ||
}: # They don't care if we defect | ||
return "tell truth", "WhatHappened.told_on_him_again" | ||
return "stay silent", "WhatHappened.nothing" # Coop! | ||
if they_bad > they_good or THEM[-1] == 0: | ||
# if memory == "WhatHappened.just_told_on_him": # punishment? | ||
# return "tell truth", "WhatHappened.told_on_him_again" | ||
# Tests shows, leaving the above out gives more luck | ||
|
||
# But that means this logically shouldn't run... but other algorithms make it run | ||
if memory == "WhatHappened.told_on_him_again": # please cool down | ||
return "stay silent", "WhatHappened.stay_silent_pls" | ||
return "tell truth", "WhatHappened.just_told_on_him" | ||
assert they_bad == they_good | ||
print("RANDOM") # on testing, this never runs | ||
return 0, "WhatHappened.nothing" |
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,33 @@ | ||
# pylint: disable=C,W,R | ||
# type: ignore | ||
def strategy(history, memory): | ||
US = history[0] | ||
THEM = history[1] | ||
gametime = history.shape[1] | ||
they_bad = len( | ||
list(filter(lambda x: x == 0, THEM)) | ||
) # The number of times they cooped | ||
they_good = len( | ||
list(filter(lambda x: x == 1, THEM)) | ||
) # The number of times they bad | ||
if len(THEM) <= 1 or memory == "WhatHappened.stay_silent_pls": # Go coop first | ||
return "stay silent", "WhatHappened.nothing" | ||
if they_good > they_bad or THEM[-1] == 1: | ||
if memory in { | ||
"WhatHappened.just_told_on_him", | ||
"WhatHappened.told_on_him_again", | ||
}: # They don't care if we defect | ||
return "tell truth", "WhatHappened.told_on_him_again" | ||
return "stay silent", "WhatHappened.nothing" # Coop! | ||
if they_bad > they_good or THEM[-1] == 0: | ||
if memory == "WhatHappened.just_told_on_him": # punishment? | ||
return "tell truth", "WhatHappened.told_on_him_again" | ||
# Tests shows, leaving the above out gives more luck | ||
|
||
# But that means this logically shouldn't run... but other algorithms make it run | ||
if memory == "WhatHappened.told_on_him_again": # please cool down | ||
return "stay silent", "WhatHappened.stay_silent_pls" | ||
return "tell truth", "WhatHappened.just_told_on_him" | ||
assert they_bad == they_good | ||
print("RANDOM") # on testing, this never runs | ||
return 0, "WhatHappened.nothing" |
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,10 @@ | ||
# import numpy as np | ||
# | ||
# # Reminder: For the history array, "tell truth" = 0, "stay silent" = 1 | ||
# import random | ||
# | ||
# | ||
def strategy(history, memory=None): | ||
if len(history[1]) == 0: | ||
return 1, None | ||
return history[1, 0], None |
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,135 @@ | ||
# # pylint: disable=C,W,R | ||
# # type: ignore | ||
# import random | ||
# | ||
# # Reminder: For the history array, "tell truth" = 0, "stay silent" = 1 | ||
# | ||
import random | ||
|
||
# | ||
# | ||
# def strategy(history, memory): | ||
# return 0, None | ||
# | ||
# | ||
# # US = history[0] | ||
# # THEM = history[1] | ||
# # they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
# # they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
# # if len(THEM) <= 1: # Go defect first | ||
# # return 1, None | ||
# # else: | ||
# # if they_bad > they_good: # mostly fail? (as of right now) | ||
# # return 1, None # Maybe it's tit for tat | ||
# # elif ( | ||
# # they_good > they_bad | ||
# # ): # Reminder: For the history array, "tell truth" = 0, "stay silent" = 1 | ||
# # return 0, None # Always good? | ||
# # else: | ||
# # if ( # Check if opponent seems random | ||
# # 0.4 | ||
# # < ( | ||
# # (they_bad if they_bad > 0 else 1) | ||
# # / (they_good if they_good > 0 else 1) | ||
# # ) | ||
# # < 0.6 | ||
# # ): | ||
# # return 0, None | ||
# # # if len(history[1]) == 0: | ||
# # # return 1, None | ||
# # return -history[1, -1], None | ||
# | ||
# | ||
def strategy(history, memory): | ||
US = history[0] | ||
THEM = history[1] | ||
they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
if history.shape[1] == 0: # We're on the first turn! | ||
return "stay silent", None | ||
else: | ||
if they_bad > they_good: # mostly fail? (as of right now) | ||
return THEM[-1], None | ||
elif ( | ||
they_good > they_bad | ||
): # Reminder: For the history array, "tell truth" = 0, "stay silent" = 1 | ||
return 0, None # Always good? | ||
else: | ||
if ( # Check if opponent seems random | ||
0.4 | ||
< ( | ||
(they_bad if they_bad > 0 else 1) | ||
/ (they_good if they_good > 0 else 1) | ||
) | ||
< 0.6 | ||
) or they_good == they_bad: | ||
return 0, None | ||
|
||
# if they_bad > they_good: # mostly fail? (as of right now) | ||
# return THEM[-1], None | ||
# elif ( | ||
# they_good > they_bad | ||
# ): # Reminder: For the history array, "tell truth" = 0, "stay silent" = 1 | ||
# return 0, None # Always good? | ||
# else: | ||
# if ( # Check if opponent seems random | ||
# 0.4 | ||
# < ( | ||
# (they_bad if they_bad > 0 else 1) | ||
# / (they_good if they_good > 0 else 1) | ||
# ) | ||
# < 0.6 | ||
# ): | ||
# return 0, None | ||
# if len(history[1]) == 0: | ||
# return 1, None | ||
# return history[1, 0], None | ||
|
||
|
||
# | ||
# | ||
# # import random | ||
# # | ||
# # | ||
# # def strategy(history, memory): | ||
# # if history.shape[1] <= 2: | ||
# # return 1, None | ||
# # else: | ||
# # if history[1, -1] == 0 and history[1, -2] == 0: | ||
# # return (random.randint(0, 1)), None | ||
# # elif history[1, -1] == 1 and history[1, -2] == 1: | ||
# # return 0, None | ||
# # else: | ||
# # return (random.randint(0, 1)), None | ||
# | ||
# | ||
# def strategy(history, memory): | ||
# US = history[0] | ||
# THEM = history[1] | ||
# they_bad = len(list(filter(lambda x: x == 0, THEM))) | ||
# they_good = len(list(filter(lambda x: x == 1, THEM))) | ||
# | ||
# if len(THEM) <= 1: # Go coop first | ||
# return 1, None | ||
# else: | ||
# if they_bad > they_good: | ||
# return 1, None | ||
# else: | ||
# if they_good > they_bad: | ||
# return 0, None | ||
# return THEM[-1], None | ||
# | ||
# | ||
# # import random | ||
# # | ||
# # | ||
# # def strategy(history, memory): | ||
# # if history.shape[1] <= 2: | ||
# # return 1, {} | ||
# # else: | ||
# # if history[1, -1] == 0 and history[1, -2] == 0: | ||
# # return (random.randint(0, 1)), {} | ||
# # elif history[1, -1] == 1 and history[1, -2] == 1: | ||
# # return 0, {} | ||
# # else: | ||
# # return (random.randint(0, 1)), {} |
Oops, something went wrong.