-
Notifications
You must be signed in to change notification settings - Fork 0
/
Visualization.py
323 lines (208 loc) · 9.99 KB
/
Visualization.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import os
import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
"""
STATS GENERATOR FOR TURN BASED OR ACTION RPG (ROLE PLAYING GAMES)
By: ROHMAN WIDIYANTO
GitHub: http://github.com/rohwid/
All component or object defined separately, here's the reason:
- Levels: Because sometimes the characters won't start from 1st level.
- Magic Point: Because sometimes the games doesn't need it (ex: action RPG).
- Number of Weaknesses: Same reason with Magic Point.
- Generate data container: Generate data container dynamically.
Notes:
- Anything which contain "show" in the function was used for debug or
check the values.
"""
from Model import var_val, mean_values
color_db = ['#E74C3C', '#8E44AD', '#3498DB', '#27AE60', '#F39C12', '#707B7C', '#2C3E50']
current_work_dir = os.path.dirname(os.path.abspath(__file__))
def init_plt():
plt.rcParams['figure.figsize'] = (12, 8)
plt.rcParams['figure.dpi'] = 100
plt.rcParams.update({'font.size': 12})
def label_2d_fig(axes, x_name, y_name, pad_size, size):
axes.set_xlabel(x_name, fontsize=size)
axes.xaxis.labelpad = pad_size
axes.set_ylabel(y_name, fontsize=size)
axes.yaxis.labelpad = pad_size
def label_2d_plot(x_name, y_name, pad_size, size):
plt.xlabel(x_name, fontsize=size, labelpad=pad_size)
plt.ylabel(y_name, fontsize=size, labelpad=pad_size)
def label_3d_fig(axes, x_name, y_name, z_name, pad_size, size):
axes.set_xlabel(x_name, fontsize=size)
axes.xaxis.labelpad = pad_size
axes.set_ylabel(y_name, fontsize=size)
axes.yaxis.labelpad = pad_size
axes.set_zlabel(z_name, fontsize=size)
axes.zaxis.labelpad = pad_size
def player_hp_graph(level, hp, graph_title, graph, title):
init_plt()
fig = plt.figure()
# left, button, width, height (range 0 to 1)
axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])
axes.plot(level, hp, color='#2980B9')
label_2d_fig(axes, 'Levels', 'Player HP', 25, 16)
if graph_title != '' and title is not None and title:
axes.set_title(graph_title, fontsize=20, fontweight='bold')
fig.savefig(current_work_dir + '/graph_output_result/PlayerHpDistribution.png')
if graph:
plt.show()
def player_mp_graph(level, mp, graph_title, graph, title):
init_plt()
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, button, width, height (range 0 to 1)
axes.plot(level, mp, color='#2980B9')
label_2d_fig(axes, 'Levels', 'Player MP', 25, 16)
if graph_title != "" and title is not None and title:
axes.set_title(graph_title, fontsize=20, fontweight='bold')
fig.savefig(current_work_dir + '/graph_output_result/PlayerMpDistribution.png')
if graph:
plt.show()
def player_stats_graph(stats, level, name_stats, graph_title, graph, title):
init_plt()
stats_graph = np.zeros((stats.shape[0], stats.shape[1]))
for i in range(stats.shape[1]):
temp_stats_graph = 0
for j in range(stats.shape[0]):
temp_stats_graph = temp_stats_graph + stats[j][i]
stats_graph[j][i] = temp_stats_graph
fig = plt.figure()
# left, button, width, height (range 0 to 1)
axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])
for i in range(stats_graph.shape[1]):
axes.plot(level, stats_graph[:, i], label=name_stats[i])
label_2d_fig(axes, 'Levels', 'Player Stats', 25, 16)
if graph_title != '' and title is not None and title:
axes.set_title(graph_title, fontsize=20, fontweight='bold')
axes.legend()
fig.savefig(current_work_dir + '/graph_output_result/PlayerStatsDistribution.png')
if graph:
plt.show()
def enemy_level_graph(range_level, graph_title, graph, title):
init_plt()
num_bins = int(max(range_level))
plt.hist(range_level, num_bins, edgecolor='black')
label_2d_plot('Levels', 'Enemy(n)', 25, 16)
if graph_title != '' and title is not None and title:
plt.title(graph_title, fontsize=20, fontweight='bold')
plt.savefig(current_work_dir + '/graph_output_result/EnemyLevelDistribution.png')
if graph:
plt.show()
def enemy_level_normal_distribution(range_level, graph_title, graph, title):
init_plt()
mean = mean_values(range_level)
variance = var_val(range_level, mean)
sigma = math.sqrt(variance)
x = np.linspace(mean - 3 * sigma, mean + 3 * sigma, len(range_level))
plt.plot(x, norm.pdf(x, mean, sigma))
label_2d_plot('Levels', 'Enemy(n)', 25, 16)
if graph_title != '' and title is not None and title:
plt.title(graph_title, fontsize=20, fontweight='bold')
plt.savefig(current_work_dir + '/graph_output_result/EnemyLevelDistributionNormal.png')
if graph:
plt.show()
def enemy_type_graph(enemy_type, enemies_type, graph_title, graph, title):
init_plt()
name = np.arange(len(enemy_type))
count_enemies = np.zeros(len(enemy_type))
for i in range(len(count_enemies)):
for j in range(len(enemies_type)):
if enemies_type[j] == i:
count_enemies[i] = count_enemies[i] + 1
plt.bar(name, count_enemies, color='#2980B9', width=0.5, align='center')
plt.xticks(name, enemy_type, fontsize=12)
label_2d_plot('Types', 'Enemy(n)', 25, 16)
if graph_title != '' and title is not None and title:
plt.title('Enemy Type Distribution', fontsize=20, fontweight='bold')
plt.savefig(current_work_dir + '/graph_output_result/EnemyTypeDistribution.png')
if graph:
plt.show()
def enemy_weak_graph(element_name, damage_name, weak_container, graph_title, graph, title):
init_plt()
# set width of bar
bar_width = 0.25
# set height of bar
data = np.zeros((len(damage_name), len(element_name)))
for i in range(len(damage_name)):
for j in range(weak_container.shape[1]):
for k in range(weak_container.shape[0]):
if weak_container[k][j] == i:
data[i][j] = data[i][j] + 1
# Set position of bar on X axis
r1 = np.arange(len(element_name))
r2 = [x + bar_width for x in r1]
r3 = [x + bar_width for x in r2]
# Make the plot
plt.bar(r1, data[0], color='#2980B9', width=bar_width, edgecolor='white', label='Normal Damage')
plt.bar(r2, data[1], color='#F39C12', width=bar_width, edgecolor='white', label='Repel (No Damage)')
plt.bar(r3, data[2], color='#2ECC71', width=bar_width, edgecolor='white', label='Weaknesses')
# Add xticks on the middle of the group bars
plt.xticks([r + bar_width for r in range(len(element_name))], element_name)
label_2d_plot('Weaknesses', 'Enemy(n)', 25, 16)
if graph_title != '' and title is not None and title:
plt.title(graph_title, fontsize=20, fontweight='bold')
# Create legend & Show graphic
plt.legend()
plt.savefig(current_work_dir + '/graph_output_result/EnemyWeakDistribution.png')
if graph:
plt.show()
def enemy_hp_graph(level, enemy_name, hp, graph, title):
init_plt()
fig = plt.figure()
axes = fig.add_subplot(111, projection='3d')
name_enemies = np.arange(0, len(enemy_name))
axes.scatter(level, name_enemies, hp, color='#2980B9')
label_3d_fig(axes, 'Levels', 'Enemy(n)', 'HP', 20, 16)
if title is not None and title:
axes.set_title('Enemy HP Stats Distribution', fontsize=20, fontweight='bold')
fig.savefig(current_work_dir + '/graph_output_result/EnemyHpDistribution.png')
if graph:
plt.show()
def enemy_mp_graph(level, enemy_name, mp, graph, title):
init_plt()
fig = plt.figure()
axes = fig.add_subplot(111, projection='3d')
name_enemies = np.arange(0, len(enemy_name))
axes.scatter(level, name_enemies, mp, color='#2980B9')
label_3d_fig(axes, 'Levels', 'Enemy(n)', 'MP', 20, 16)
if title is not None and title:
axes.set_title('Enemy MP Stats Distribution', fontsize=20, fontweight='bold')
fig.savefig(current_work_dir + '/graph_output_result/EnemyMpDistribution.png')
if graph:
plt.show()
def enemy_stats_graph(level, enemy_name, stats_name, stats_container, graph_title, graph, title):
enemies = np.arange(0, len(enemy_name))
single_stats_graph(level, enemy_name, stats_name, stats_container, graph_title, graph, title)
for i in range(stats_container.shape[1]):
i_stats_name = stats_name[i]
i_stats_container = stats_container[:, i]
color = color_db[i]
parted_enemy_stats(level, enemies, i_stats_name, i_stats_container, color, graph, title)
def single_stats_graph(level, enemies_name, stats_name, stats_container, graph_title, graph, title):
init_plt()
fig = plt.figure()
axes = fig.add_subplot(111, projection='3d')
enemies = np.arange(0, len(enemies_name))
for i in range(stats_container.shape[1]):
axes.scatter(level, enemies, stats_container[:, i], color=color_db[i], label=stats_name[i])
label_3d_fig(axes, 'Levels', 'Enemy(n)', 'Stats', 20, 16)
if graph_title != '' and title is not None and title:
axes.set_title(graph_title, fontsize=20, fontweight='bold')
axes.legend()
fig.savefig(current_work_dir + '/graph_output_result/EnemyStatsDistribute.png')
if graph:
plt.show()
def parted_enemy_stats(level, enemies, stats_name, stats_container, selected_color, graph, title):
init_plt()
fig = plt.figure()
axes = fig.add_subplot(111, projection='3d')
axes.scatter(level, enemies, stats_container, color=selected_color, label=stats_name)
label_3d_fig(axes, 'Levels', 'Enemy(n)', 'Stats', 20, 16)
if title is not None and title:
axes.set_title('Enemy ' + stats_name + ' Stats Distribution', fontsize=20, fontweight='bold')
fig.savefig(current_work_dir + '/graph_output_result/Enemy' + stats_name + 'Distribute')
if graph:
plt.show()