-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvampire_test.py
More file actions
47 lines (39 loc) · 1.63 KB
/
vampire_test.py
File metadata and controls
47 lines (39 loc) · 1.63 KB
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
import icepool
import pytest
from icepool import vectorize
def test_vampire():
# One method is to express the possible outcomes using a tuple
# that has exactly one element set according to the symbol rolled.
# This is called a "one-hot" representation.
# In this case we have four types of symbols.
normal_die = icepool.Die({
vectorize(0, 0, 0, 0): 5, # failure
vectorize(0, 1, 0, 0): 4, # success
vectorize(0, 0, 1, 0): 1, # crit
})
hunger_die = icepool.Die({
vectorize(1, 0, 0, 0): 1, # bestial failure
vectorize(0, 0, 0, 0): 4, # failure
vectorize(0, 1, 0, 0): 4, # success
vectorize(0, 0, 0, 1): 1, # messy crit
})
# Summing the dice produces the total number of each symbol rolled.
# The @ operator means roll the left die, then roll that many of the right die and sum.
# For outcomes that are vectors, sums are performed element-wise.
total = 3 @ normal_die + 2 @ hunger_die
# Then we can use a function to compute the final result.
def eval_one_hot(hunger_botch, success, crit, hunger_crit):
total_crit = crit + hunger_crit
success += total_crit + 2 * (total_crit // 2)
if total_crit >= 2:
if hunger_crit > 0:
win_type = 'messy'
else:
win_type = 'crit'
else:
win_type = ''
loss_type = 'bestial' if hunger_botch > 0 else ''
return success, win_type, loss_type
# star=True unpacks the tuples before giving them to eval_one_hot.
result = total.map(eval_one_hot)
assert result.quantity((0, '', '')) == 2000