-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
63 lines (51 loc) · 1.83 KB
/
utilities.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
### This script holds some utility functions.
import numpy as np
from scipy.stats import randint
## funtion categorize_token
# takes a vector of token values x
# returns a vector of token classes
def categorize_tokens(x):
# declare an empty vector to hold the translated values
categories = np.array([])
# categorize each token based on its value
for i in range(len(x)):
if x[i] < 0:
categories = np.append(categories, 0)
elif x[i] <= 3:
categories = np.append(categories, 1)
elif x[i] <= 7:
categories = np.append(categories, 2)
elif x[i] <= 11:
categories = np.append(categories, 3)
elif x[i] <= 15:
categories = np.append(categories, 4)
else:
categories = np.append(categories, 5)
return(categories)
## function expand_inventory
# takes a list of vectors x and integer players
# returns a zero-padded array of token categories in inventories
def expand_inventory(x, players):
# declare an array of -1 placeholders with the appropriate dimensions
inventory = np.full((players, 32), -1)
# insert the values from x into inventory
for i in range(len(x)):
inventory[i, :len(x[i])] = categorize_tokens(x[i])
return(inventory)
## function expand_vector
# takes a vector x
# returns a zero-padded vector
def expand_vector(x):
# append zeros until the vector reaches max length
while len(x) < 32:
x = np.append(x, 0)
return(x)
## function death_drop
# takes a player inventory
# returns an index indicating which token to drop
def death_drop(inventory):
# create a vector of zeroes
inventory_mask = np.zeros(len(inventory))
# select a token at random
inventory_mask[randint.rvs(0, len(inventory))] = 1
return inventory_mask