-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
66 lines (44 loc) · 1.43 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import random
from ui import *
def random_choice(weights, index):
if index > len(weights) - 1:
index = len(weights) - 1
return random.choices(weights[index][0], weights[index][1])[0]
def min_choice(weights, index):
if index > len(weights) - 1:
index = len(weights) - 1
return min(weights[index][0])
def max_choice(weights, index):
if index > len(weights) - 1:
index = len(weights) - 1
return max(weights[index][0])
# Sums all values in cell array (including bonuses), returns the sum
def calculate_score(cells):
score = 0
for i in range(len(cells)):
cell = cells[i]
score += cell.value
for j in range(i + 1, len(cells)):
if cell.value == cells[j].value:
score += cell.value
return score
# Displays the range of possible number values for the shop
def get_shop_range(weights, turn):
return (
"("
+ str(min_choice(weights, turn))
+ "-"
+ str(max_choice(weights, turn))
+ ")"
)
# Return difference in scores between two boards
def calculate_score_diff(cells, cells_copy):
return calculate_score(cells_copy) - calculate_score(cells)
def cost(value):
return "(" + str(value) + ")"
def preview_text(value):
return "(" + ("+" if value >= 0 else "-") + str(abs(value)) + ")"
def center_x(button):
return button.x + BUTTON_WIDTH / 2
def above_y(button):
return button.y - 15