-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestRelation.py
More file actions
84 lines (59 loc) · 2.77 KB
/
testRelation.py
File metadata and controls
84 lines (59 loc) · 2.77 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
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
from generation.data.village import VillageInteraction
from utils.checkOrCreateConfig import Config
from utils.nameGenerator import NameGenerator
import generation.loreMaker as loremaker
import matplotlib.pyplot as plt
import math
def state_relation_to_color(state: int) -> str:
if state == VillageInteraction.STATE_WAR:
return "red"
elif state == VillageInteraction.STATE_TENSION:
return "yellow"
elif state == VillageInteraction.STATE_FRIENDSHIP:
return "blue"
elif state == VillageInteraction.STATE_LOVE:
return "green"
return "black"
def plot_relation(positions_x: dict, positions_y: dict, interactions: list) -> None:
for interaction in interactions:
if interaction.state == VillageInteraction.STATE_NEUTRAL:
continue
x = [positions_x[interaction.village1], positions_x[interaction.village2]]
y = [positions_y[interaction.village1], positions_y[interaction.village2]]
color = state_relation_to_color(interaction.state)
plt.plot(x, y, color=color)
def plot_village_point(positions_x, positions_y, plotted_villages: list):
for current in plotted_villages:
x: int = positions_x[current]
y: int = positions_y[current]
if current.isDestroyed:
plt.plot(x, y, marker="o", markersize=10, markeredgecolor="black", markerfacecolor="black")
else:
plt.plot(x, y, marker="o", markersize=10, markeredgecolor="black", markerfacecolor="green")
if __name__ == "__main__":
Config.getOrCreateConfig()
nameGenerator: NameGenerator = NameGenerator()
"""Generate village involving on our generation"""
number_to_generate = 10
positions_of_village = []
for i in range(number_to_generate):
positions_of_village.append([500 * i, 0])
villages: list = loremaker.initializedVillages(positions_of_village, nameGenerator)
villageInteractions: list = loremaker.createVillageRelationAndAssign(villages)
positions_x_on_graph: dict = {}
positions_y_on_graph: dict = {}
each_part = math.pi * 2 / number_to_generate
for i in range(number_to_generate):
village = villages[i]
positions_x_on_graph[village] = math.cos(i * each_part)
positions_y_on_graph[village] = math.sin(i * each_part)
plt.subplot(1, 2, 1)
plot_relation(positions_x_on_graph, positions_y_on_graph, villageInteractions)
loremaker.checkForImpossibleInteractions(villages, villageInteractions)
loremaker.generateLoreAfterRelation(villages)
for village in villages:
loremaker.handleVillageDestroy(village)
plt.subplot(1, 2, 2)
plot_relation(positions_x_on_graph, positions_y_on_graph, villageInteractions)
plot_village_point(positions_x_on_graph, positions_y_on_graph, villages)
plt.show()