View difference between Paste ID: mxrdBWW5 and gxKbfjis
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)):
13
                    totals[0].pop(tar)
14
                    can_attack[0].pop(tar)
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)):
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)):
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(len(can_attack[player])):
41
        if not can_attack[player][i]:
42
            can_attack[player][i] = True
43
    return can_attack
44
45
win_counter = 0
46
turn_counter = 0
47
iterations = 10
48
for i in range(iterations):
49
    boards = [[30], [30]]
50
    attack_list = [[False], [False]]
51
    mana = 2
52
    win = -1
53
    n=2
54
    hand_size = [5,5]
55
    
56
    boards, win, attack_list, hand_size[1] = play(boards, 1, win, attack_list, hand_size)
57
    while win == -1:
58
        attack_list = wakeup(attack_list, 0)
59
        hand_size[0] += 1
60
        for i in range(math.floor(mana/2)):
61
            if hand_size[0] > 0:
62
                boards, win, attack_list, hand_size[0] = play(boards, 0, win, attack_list, hand_size)
63
        boards[1][0] -= attack(attack_list, 0)
64
        if boards[1][0] <= 0:
65
            win = 0
66
        n += 1
67
        
68
        attack_list = wakeup(attack_list, 1)
69
        hand_size[1] += 1
70
        for i in range(math.floor(mana/2)):
71
            if hand_size[1] > 0:
72
                boards, win, attack_list, hand_size[1] = play(boards, 1, win, attack_list, hand_size)
73
        boards[0][0] -= attack(attack_list, 1)
74
        if boards[0][0] <= 0:
75
            win = 1
76
        n += 1
77
78
        mana += 1
79
        
80
    win_counter += win
81
    turn_counter += n
82
    
83
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")