Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- def play(totals, player, win, can_attack, hand):
- if win != -1:
- return totals, win, can_attack, hand[player]
- else:
- for i in range(3):
- tar = math.floor(random.random() * float(len(totals[0]) + len(totals[1])))
- if ((tar < len(totals[0])) and (len(totals[0]) < 9)):
- totals[0][tar] -= 1
- if ((totals[0][tar] <= 0) and (tar != 0)):
- totals[0].pop(tar)
- can_attack[0].pop(tar)
- elif ((totals[0][tar] <= 0) and (tar <= 0)):
- totals[player].append(2)
- return totals, 1, can_attack, (hand[player]-1)
- elif ((tar >= len(totals[0])) and (len(totals[0]) < 9)):
- totals[1][tar-len(totals[0])] -= 1
- if ((totals[1][tar-len(totals[0])] <= 0) and ((tar-len(totals[0])) != 0)):
- totals[1].pop(tar-len(totals[0]))
- can_attack[1].pop(tar-len(totals[0]))
- elif ((totals[1][tar-len(totals[0])] <= 0) and ((tar-len(totals[0])) <= 0)):
- totals[player].append(2)
- return totals, 0, can_attack, (hand[player]-1)
- else:
- return totals, -1, can_attack, hand
- totals[player].append(2)
- can_attack[player].append(False)
- return totals, -1, can_attack, (hand[player]-1)
- def attack(can_attack, player):
- dmg = 0
- for i in can_attack[player]:
- if i:
- dmg += 3
- return dmg
- def wakeup(can_attack, player):
- for i in range(1,len(can_attack[player])):
- if not can_attack[player][i]:
- can_attack[player][i] = True
- return can_attack
- def hero_power(totals, player, toon, atk_list):
- opp = int(math.cos((math.pi/2.0) * player))
- if toon == "huntard":
- totals[opp][0] -= 2
- elif toon == "wario":
- totals[player][0] += 2
- elif toon == "durid":
- totals[opp][0] -= 1
- totals[player][0] += 1
- elif toon == "jaina":
- min_health = 150816
- mindex = 0
- boop = totals[opp]
- for i in range(len(boop)):
- if ((boop[i] < min_health) and (boop[i] > 0)):
- mindex = i
- min_health = boop[i]
- totals[opp][mindex] -= 1
- elif toon == "uther":
- totals[player].append(1)
- atk_list[player].append(False)
- else:
- return totals, atk_list
- return totals, atk_list
- win_counter = 0
- turn_counter = 0
- iterations = 100000
- toon = ["uther", "durid"]
- #testurds
- #print("hp")
- #print(boards[0])
- #print(boards[1])
- for i in range(iterations):
- boards = [[30], [30]]
- attack_list = [[False], [False]]
- mana = 2
- win = -1
- n=2
- hand_size = [5,5]
- boards, win, attack_list, hand_size[1] = play(boards, 1, win, attack_list, hand_size)
- while win == -1:
- attack_list = wakeup(attack_list, 0)
- hand_size[0] += 1
- hp = True
- for i in range(math.floor(mana/2)):
- if (((math.floor(mana/2) - 1) > hand_size[0]) and hp):
- boards, attack_list = hero_power(boards, 0, toon[0], attack_list)
- hp = False
- elif hand_size[0] > 0:
- boards, win, attack_list, hand_size[0] = play(boards, 0, win, attack_list, hand_size)
- boards[1][0] -= attack(attack_list, 0)
- hp = False
- if boards[1][0] <= 0:
- win = 0
- n += 1
- attack_list = wakeup(attack_list, 1)
- hand_size[1] += 1
- hp = True
- for i in range(math.floor(mana/2)):
- if (((math.floor(mana/2) - 1) > hand_size[1]) and hp):
- boards, attack_list = hero_power(boards, 1, toon[1], attack_list)
- hp = False
- elif hand_size[1] > 0:
- boards, win, attack_list, hand_size[1] = play(boards, 1, win, attack_list, hand_size)
- boards[0][0] -= attack(attack_list, 1)
- if boards[0][0] <= 0:
- win = 1
- n += 1
- mana += 1
- win_counter += win
- turn_counter += n
- print("coin winrate: " + str(100.0 * (float(win_counter)/float(iterations))) + "\navg turn count: " + str(float(turn_counter)/float(iterations)) + "\ntested over " + str(iterations) + " iterations")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement