SHOW:
|
|
- or go back to the newest paste.
| 1 | import random | |
| 2 | import math | |
| 3 | ||
| 4 | def play(totals, player, win, can_attack, hand): | |
| 5 | if win != -1: | |
| 6 | return totals, win, can_attack, hand[player] | |
| 7 | else: | |
| 8 | for i in range(3): | |
| 9 | tar = math.floor(random.random() * float(len(totals[0]) + len(totals[1]))) | |
| 10 | if ((tar < len(totals[0])) and (len(totals[0]) < 9)): | |
| 11 | totals[0][tar] -= 1 | |
| 12 | - | if ((totals[0][tar] == 0) and (tar != 0)): |
| 12 | + | if ((totals[0][tar] <= 0) and (tar != 0)): |
| 13 | totals[0].pop(tar) | |
| 14 | can_attack[0].pop(tar) | |
| 15 | - | elif ((totals[0][tar] == 0) and (tar <= 0)): |
| 15 | + | elif ((totals[0][tar] <= 0) and (tar <= 0)): |
| 16 | totals[player].append(2) | |
| 17 | return totals, 1, can_attack, (hand[player]-1) | |
| 18 | elif ((tar >= len(totals[0])) and (len(totals[0]) < 9)): | |
| 19 | totals[1][tar-len(totals[0])] -= 1 | |
| 20 | - | if ((totals[1][tar-len(totals[0])] == 0) and ((tar-len(totals[0])) != 0)): |
| 20 | + | if ((totals[1][tar-len(totals[0])] <= 0) and ((tar-len(totals[0])) != 0)): |
| 21 | totals[1].pop(tar-len(totals[0])) | |
| 22 | can_attack[1].pop(tar-len(totals[0])) | |
| 23 | - | elif ((totals[1][tar-len(totals[0])] == 0) and ((tar-len(totals[0])) <= 0)): |
| 23 | + | elif ((totals[1][tar-len(totals[0])] <= 0) and ((tar-len(totals[0])) <= 0)): |
| 24 | totals[player].append(2) | |
| 25 | return totals, 0, can_attack, (hand[player]-1) | |
| 26 | else: | |
| 27 | return totals, -1, can_attack, hand | |
| 28 | totals[player].append(2) | |
| 29 | can_attack[player].append(False) | |
| 30 | return totals, -1, can_attack, (hand[player]-1) | |
| 31 | ||
| 32 | def attack(can_attack, player): | |
| 33 | dmg = 0 | |
| 34 | for i in can_attack[player]: | |
| 35 | if i: | |
| 36 | dmg += 3 | |
| 37 | return dmg | |
| 38 | ||
| 39 | def wakeup(can_attack, player): | |
| 40 | for i in range(1,len(can_attack[player])): | |
| 41 | if not can_attack[player][i]: | |
| 42 | can_attack[player][i] = True | |
| 43 | return can_attack | |
| 44 | ||
| 45 | - | def hero_power(totals, player, toon): |
| 45 | + | def hero_power(totals, player, toon, atk_list): |
| 46 | opp = int(math.cos((math.pi/2.0) * player)) | |
| 47 | - | totals[int(math.cos((math.pi/2.0) * player))][0] -= 2 |
| 47 | + | |
| 48 | totals[opp][0] -= 2 | |
| 49 | elif toon == "wario": | |
| 50 | totals[player][0] += 2 | |
| 51 | - | return totals |
| 51 | + | elif toon == "durid": |
| 52 | - | return totals |
| 52 | + | totals[opp][0] -= 1 |
| 53 | totals[player][0] += 1 | |
| 54 | elif toon == "jaina": | |
| 55 | min_health = 150816 | |
| 56 | - | iterations = 10000 |
| 56 | + | mindex = 0 |
| 57 | - | toon = ["wario", "huntard"] |
| 57 | + | boop = totals[opp] |
| 58 | for i in range(len(boop)): | |
| 59 | if ((boop[i] < min_health) and (boop[i] > 0)): | |
| 60 | mindex = i | |
| 61 | min_health = boop[i] | |
| 62 | totals[opp][mindex] -= 1 | |
| 63 | elif toon == "uther": | |
| 64 | totals[player].append(1) | |
| 65 | atk_list[player].append(False) | |
| 66 | else: | |
| 67 | return totals, atk_list | |
| 68 | return totals, atk_list | |
| 69 | ||
| 70 | win_counter = 0 | |
| 71 | turn_counter = 0 | |
| 72 | iterations = 100000 | |
| 73 | toon = ["uther", "durid"] | |
| 74 | - | if (((math.floor(mana/2) - 1) > hand_size[0]) and hp): |
| 74 | + | |
| 75 | - | boards = hero_power(boards, 0, toon[0]) |
| 75 | + | #testurds |
| 76 | #print("hp")
| |
| 77 | #print(boards[0]) | |
| 78 | #print(boards[1]) | |
| 79 | - | boards[1][0] -= attack(attack_list, 0) |
| 79 | + | |
| 80 | for i in range(iterations): | |
| 81 | boards = [[30], [30]] | |
| 82 | attack_list = [[False], [False]] | |
| 83 | mana = 2 | |
| 84 | win = -1 | |
| 85 | n=2 | |
| 86 | hand_size = [5,5] | |
| 87 | ||
| 88 | boards, win, attack_list, hand_size[1] = play(boards, 1, win, attack_list, hand_size) | |
| 89 | - | boards = hero_power(boards, 1, toon[1]) |
| 89 | + | |
| 90 | attack_list = wakeup(attack_list, 0) | |
| 91 | hand_size[0] += 1 | |
| 92 | ||
| 93 | hp = True | |
| 94 | for i in range(math.floor(mana/2)): | |
| 95 | if (((math.floor(mana/2) - 1) > hand_size[0]) and hp): | |
| 96 | boards, attack_list = hero_power(boards, 0, toon[0], attack_list) | |
| 97 | hp = False | |
| 98 | elif hand_size[0] > 0: | |
| 99 | boards, win, attack_list, hand_size[0] = play(boards, 0, win, attack_list, hand_size) | |
| 100 | boards[1][0] -= attack(attack_list, 0) | |
| 101 | hp = False | |
| 102 | if boards[1][0] <= 0: | |
| 103 | win = 0 | |
| 104 | n += 1 | |
| 105 | ||
| 106 | attack_list = wakeup(attack_list, 1) | |
| 107 | hand_size[1] += 1 | |
| 108 | hp = True | |
| 109 | for i in range(math.floor(mana/2)): | |
| 110 | if (((math.floor(mana/2) - 1) > hand_size[1]) and hp): | |
| 111 | boards, attack_list = hero_power(boards, 1, toon[1], attack_list) | |
| 112 | hp = False | |
| 113 | elif hand_size[1] > 0: | |
| 114 | boards, win, attack_list, hand_size[1] = play(boards, 1, win, attack_list, hand_size) | |
| 115 | boards[0][0] -= attack(attack_list, 1) | |
| 116 | if boards[0][0] <= 0: | |
| 117 | win = 1 | |
| 118 | n += 1 | |
| 119 | ||
| 120 | mana += 1 | |
| 121 | ||
| 122 | win_counter += win | |
| 123 | turn_counter += n | |
| 124 | ||
| 125 | 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") |