Skip to content

Instantly share code, notes, and snippets.

@Cis112233 Cis112233/Handler.py

Created Jul 25, 2017
Embed
What would you like to do?
botnames = [
'Equalizer',
'RandomBot'
]
#Agressor
#Caution
#Equalizer
#Random
bots = list(map(__import__, botnames))
scores = [0] * len(bots)
def play(bot1, bot2):
hand1 = [1, 1]
hand2 = [1, 1]
turn = 0
while turn < 100000:
bot = [bot1, bot2][turn % 2]
oth = [bot2, bot1][turn % 2]
hands = [hand1, hand2, hand1][turn % 2 : turn % 2 + 2]
try:
ret = bot.play(*hands)
except:
turn += 1
continue
if type(ret) == list and len(ret) == 2 and ret[0] in [0, 1] and ret[1] in [0, 1]:
hands[1][ret[1]] += hands[0][ret[0]]
elif ret:
if hands[0][0] == 0:
hands[0][0] = hands[0][1] // 2
hands[0][1] -= hands[0][0]
elif hands[0][1] == 0:
hands[0][1] = hands[0][0] // 2
hands[0][0] -= hands[0][1]
if hands[1][0] > 1000: hands[1][0] = 0
if hands[1][1] > 1000: hands[1][1] = 0
if not any(hands[1]):
print("Hand 1: "+str(hand1)+" Hand 2: "+str(hand2))
return turn % 2
turn += 1
return -1
for run in range(10):
for index in range(len(bots)):
for other in range(len(bots)):
if index != other:
result = play(bots[index], bots[other])
if result != -1: scores[[index, other][result]] += 1
print(dict(zip(botnames, scores)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.