Scripts for analyzing mana steal and mana regen using markov chains

This commit is contained in:
hppeng 2022-02-06 00:04:01 -08:00
parent 29bf9c6c3c
commit 303bf558b5
3 changed files with 109 additions and 0 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ sets/
.idea/
*.iml
.editor_log.txt

48
testing/ms_linalg.py Normal file
View file

@ -0,0 +1,48 @@
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
# Attack speed independent. Fast speed losses not accounted for
mana_consumption = 3
mana_steal = 10 # /3s
mana_regen = 0 # /5s
#mana_steal = 5 # /3s
#mana_regen = 5 # /5s
natural_regen = 1
weight_natural = 8/15 # 4/5 * 2/3
weight_mr = 2/15 # 1/5 * 2/3
weight_ms = 4/15 # 4/5 * 1/3
weight_mr_ms = 1/15 # 1/5 * 1/3
MAX_MANA = 20
transition_matrix = np.zeros((MAX_MANA, MAX_MANA))
for i in range(MAX_MANA):
natural_state = max(0, i - mana_consumption + natural_regen)
mr_state = min(19, natural_state + mana_regen)
ms_state = min(19, natural_state + mana_steal)
mr_ms_state = min(19, natural_state + mana_regen + mana_steal)
transition_matrix[natural_state, i] = weight_natural
transition_matrix[mr_state, i] += weight_mr
transition_matrix[ms_state, i] += weight_ms
transition_matrix[mr_ms_state, i] += weight_mr_ms
eigval, eigvec = la.eig(transition_matrix)
print(eigval)
eps = 0.00001
ind = np.argwhere(abs(eigval - 1) < eps)
steady_state = abs(eigvec[:, ind])
steady_state /= np.sum(steady_state)
cumulative = np.cumsum(steady_state)
print("mana\tprob cumsum")
for i in range(MAX_MANA):
print(f"{i+1}\t{cumulative[i]}")
plt.figure()
plt.scatter(range(len(steady_state)), steady_state)
plt.xlim(0, 19)
plt.ylim(0, 0.2)
plt.xlabel("Mana Value")
plt.ylabel("Probability at t=infty")
plt.title(f"Build={mana_regen}mr,{mana_steal}ms,{mana_consumption}mana/sec")
plt.show()

60
testing/ms_sslow.py Normal file
View file

@ -0,0 +1,60 @@
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
# Super slow attack speed. (Idealized to 1 hit/2s, 2/3 chance of proc
mana_consumption = 3
mana_steal = 5 # /3s
mana_regen = 4 # /5s
#mana_steal = 5 # /3s
#mana_regen = 5 # /5s
natural_regen = 1
ms_period = 2
ms_chance = ms_period / 3
no_ms_chance = 1 - ms_chance
MAX_MANA = 20
TIME_CYCLE = 10
transition_matrix = np.zeros((MAX_MANA * TIME_CYCLE, MAX_MANA * TIME_CYCLE))
for j in range(TIME_CYCLE):
for i in range(MAX_MANA):
natural_state = max(0, i - mana_consumption + natural_regen)
if j % 5 == 0: # mr activation
natural_state = min(19, natural_state + mana_regen)
next_ind = ((j+1) % TIME_CYCLE) * MAX_MANA
if j % ms_period == 0: # ms activation
ms_state = min(19, natural_state + mana_steal)
transition_matrix[next_ind + natural_state, i+j*MAX_MANA] = no_ms_chance
transition_matrix[next_ind + ms_state, i+j*MAX_MANA] += ms_chance
else:
transition_matrix[next_ind + natural_state, i+j*MAX_MANA] = 1
eigval, eigvec = la.eig(transition_matrix)
print(eigval)
eps = 0.00001
ind = np.argwhere(abs(eigval - 1) < eps)
steady_state = np.sum(abs(eigvec[:, ind]).reshape((TIME_CYCLE, MAX_MANA)), axis=0)
steady_state /= np.sum(steady_state)
cumulative = np.cumsum(steady_state)
print("mana\tcumulative probability")
for i in range(MAX_MANA):
print(f"{i+1}\t{cumulative[i]}")
x_ticks = list(range(len(steady_state)))
plt.figure()
plt.scatter(x_ticks, steady_state, label="mana values")
plt.xlim(0, 19)
plt.ylim(0, 0.3)
plt.axvline(x=6+mana_consumption)
plt.xlabel("Mana Value")
plt.xticks(x_ticks)
plt.ylabel("Probability at t=infty")
plt.legend()
ax2 = plt.gca().twinx()
ax2.plot(x_ticks, cumulative, label="cumulative probability")
ax2.set_ylim(0, 1)
ax2.set_ylabel("Cumulative probability at t=infty")
plt.title(f"Build={mana_regen}mr,{mana_steal}ms,{mana_consumption}mana/sec")
plt.legend()
plt.show()