Spaces:
Sleeping
Sleeping
Ajout de la carte avec regions
Browse files- helper_functions.py +9 -9
- static/index.html +71 -27
helper_functions.py
CHANGED
@@ -7,13 +7,13 @@ def load_character_data():
|
|
7 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
8 |
json_path = os.path.join(current_dir, 'original_setup/trump.character.json')
|
9 |
|
10 |
-
with open(json_path, 'r') as file:
|
11 |
return json.load(file)
|
12 |
|
13 |
def load_chat_history(game_root):
|
14 |
history_path = game_root + '/chat_history.json'
|
15 |
try:
|
16 |
-
with open(history_path, 'r') as file:
|
17 |
return json.load(file)
|
18 |
except FileNotFoundError:
|
19 |
return []
|
@@ -45,7 +45,7 @@ def update_chat_history(chat_history, user_message=None, trump_message=None):
|
|
45 |
def save_chat_history(history, game_root):
|
46 |
history_path = os.path.join(game_root, 'chat_history.json')
|
47 |
|
48 |
-
with open(history_path, 'w') as file:
|
49 |
json.dump(history, file, indent=2)
|
50 |
|
51 |
def initialize_game():
|
@@ -63,22 +63,22 @@ def generate_round_context(game_number):
|
|
63 |
contexts_dir = 'original_setup/contexts/'
|
64 |
|
65 |
#generate idea
|
66 |
-
with open(contexts_dir + 'actions.list', 'r') as file:
|
67 |
idea_csq = file.readlines()
|
68 |
idea_csq = choice(idea_csq)
|
69 |
idea, delta_USA, delta_country, delta_friendliness = idea_csq.split(';')
|
70 |
delta_friendliness = delta_friendliness.split()[0]
|
71 |
-
with open(contexts_dir + 'countries.list', 'r') as f_countries:
|
72 |
countries = f_countries.readlines()
|
73 |
country = choice(countries).split()[0]
|
74 |
|
75 |
idea = idea.replace('[country]', country)
|
76 |
|
77 |
-
with open(contexts_dir + 'concerns.list', 'r') as f:
|
78 |
concerns = f.readlines()
|
79 |
concern = choice(concerns)
|
80 |
|
81 |
-
with open(contexts_dir + '2nd_characters.list', 'r') as f:
|
82 |
advisors = f.readlines()
|
83 |
advisor = choice(advisors)
|
84 |
|
@@ -107,12 +107,12 @@ def check_end(trump_response):
|
|
107 |
|
108 |
def process_ending(idea_is_accepted, game_number, idea):
|
109 |
if idea_is_accepted:
|
110 |
-
with open(f'games/game_{game_number}/events.list', 'a') as f:
|
111 |
f.write(idea + '\n')
|
112 |
|
113 |
world_graph = WorldGraph(f'games/game_{game_number}/world_graph.edgelist')
|
114 |
|
115 |
-
with open(f'games/game_{game_number}/round_consequences.json', 'r') as f:
|
116 |
consequences = json.load(f)
|
117 |
country = consequences['country']
|
118 |
delta_USA = int(consequences['delta_USA'])
|
|
|
7 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
8 |
json_path = os.path.join(current_dir, 'original_setup/trump.character.json')
|
9 |
|
10 |
+
with open(json_path, 'r',encoding='utf-8') as file:
|
11 |
return json.load(file)
|
12 |
|
13 |
def load_chat_history(game_root):
|
14 |
history_path = game_root + '/chat_history.json'
|
15 |
try:
|
16 |
+
with open(history_path, 'r',encoding='utf-8') as file:
|
17 |
return json.load(file)
|
18 |
except FileNotFoundError:
|
19 |
return []
|
|
|
45 |
def save_chat_history(history, game_root):
|
46 |
history_path = os.path.join(game_root, 'chat_history.json')
|
47 |
|
48 |
+
with open(history_path, 'w',encoding='utf-8') as file:
|
49 |
json.dump(history, file, indent=2)
|
50 |
|
51 |
def initialize_game():
|
|
|
63 |
contexts_dir = 'original_setup/contexts/'
|
64 |
|
65 |
#generate idea
|
66 |
+
with open(contexts_dir + 'actions.list', 'r',encoding='utf-8') as file:
|
67 |
idea_csq = file.readlines()
|
68 |
idea_csq = choice(idea_csq)
|
69 |
idea, delta_USA, delta_country, delta_friendliness = idea_csq.split(';')
|
70 |
delta_friendliness = delta_friendliness.split()[0]
|
71 |
+
with open(contexts_dir + 'countries.list', 'r',encoding='utf-8') as f_countries:
|
72 |
countries = f_countries.readlines()
|
73 |
country = choice(countries).split()[0]
|
74 |
|
75 |
idea = idea.replace('[country]', country)
|
76 |
|
77 |
+
with open(contexts_dir + 'concerns.list', 'r',encoding='utf-8') as f:
|
78 |
concerns = f.readlines()
|
79 |
concern = choice(concerns)
|
80 |
|
81 |
+
with open(contexts_dir + '2nd_characters.list', 'r',encoding='utf-8') as f:
|
82 |
advisors = f.readlines()
|
83 |
advisor = choice(advisors)
|
84 |
|
|
|
107 |
|
108 |
def process_ending(idea_is_accepted, game_number, idea):
|
109 |
if idea_is_accepted:
|
110 |
+
with open(f'games/game_{game_number}/events.list', 'a',encoding='utf-8') as f:
|
111 |
f.write(idea + '\n')
|
112 |
|
113 |
world_graph = WorldGraph(f'games/game_{game_number}/world_graph.edgelist')
|
114 |
|
115 |
+
with open(f'games/game_{game_number}/round_consequences.json', 'r',encoding='utf-8') as f:
|
116 |
consequences = json.load(f)
|
117 |
country = consequences['country']
|
118 |
delta_USA = int(consequences['delta_USA'])
|
static/index.html
CHANGED
@@ -279,11 +279,11 @@
|
|
279 |
// Voici un objet exemple contenant vos pays et l'attribut friendless
|
280 |
const countries = {
|
281 |
'AF': {
|
282 |
-
d: 'M1369.9,333.8h-5.4l-3.8-0.5l-2.5,2.9l-2.1,0.7l-1.5,1.3l-2.6-2.1l-1-5.4l-1.6-0.3v-2l-3.2-1.5l-1.7,2.3l0.2,2.6 l-0.6,0.9l-3.2-0.1l-0.9,3l-2.1-1.3l-3.3,2.1l-1.8-0.8l-4.3-1.4h-2.9l-1.6-0.2l-2.9-1.7l-0.3,2.3l-4.1,1.2l0.1,5.2l-2.5,2l-4,0.9 l-0.4,3l-3.9,0.8l-5.9-2.4l-0.5,8l-0.5,4.7l2.5,0.9l-1.6,3.5l2.7,5.1l1.1,4l4.3,1.1l1.1,4l-3.9,5.8l9.6,3.2l5.3-0.9l3.3,0.8l0.9-1.4 l3.8,0.5l6.6-2.6l-0.8-5.4l2.3-3.6h4l0.2-1.7l4-0.9l2.1,0.6l1.7-1.8l-1.1-3.8l1.5-3.8l3-1.6l-3-4.2l5.1,0.2l0.9-2.3l-0.8-2.5l2-2.7 l-1.4-3.2l-1.9-2.8l2.4-2.8l5.3-1.3l5.8-0.8l2.4-1.2l2.8-0.7L1369.9,333.8L1369.9,333.8z', friendless:'
|
283 |
},
|
284 |
'AL': {
|
285 |
d: 'M1077.5,300.5l-2,3.1l0.5,1.9l0,0l1,1l-0.5,1.9l-0.1,4.3l0.7,3l3,2.1l0.2,1.4l1,0.4l2.1-3l0.1-2.1l1.6-0.9V312 l-2.3-1.6l-0.9-2.6l0.4-2.1l0,0l-0.5-2.3l-1.3-0.6l-1.3-1.6l-1.3,0.5L1077.5,300.5L1077.5,300.5z'
|
286 |
-
,friendless:'
|
287 |
'DZ': {
|
288 |
d: 'M1021,336.9l-3.6,0.4l-2.2-1.5h-5.6l-4.9,2.6l-2.7-1l-8.7,0.5l-8.9,1.2l-5,2l-3.4,2.6l-5.7,1.2l-5.1,3.5l2,4.1 l0.3,3.9l1.8,6.7l1.4,1.4l-1,2.5l-7,1l-2.5,2.4l-3.1,0.5l-0.3,4.7l-6.3,2.5l-2.1,3.2L944,383l-5.4,1l-8.9,4.7l-0.1,7.5v0.4l-0.1,1.2 l20.3,15.5l18.4,13.9l18.6,13.8l1.3,3l3.4,1.8l2.6,1.1l0.1,4l6.1-0.6l7.8-2.8l15.8-12.5l18.6-12.2l-2.5-4l-4.3-2.9l-2.6,1.2l-2-3.6 l-0.2-2.7l-3.4-4.7l2.1-2.6l-0.5-4l0.6-3.5l-0.5-2.9l0.9-5.2l-0.4-3l-1.9-5.6l-2.6-11.3l-3.4-2.6v-1.5l-4.5-3.8l-0.6-4.8l3.2-3.6 l1.1-5.3l-1-6.2L1021,336.9L1021,336.9z'
|
289 |
},
|
@@ -928,32 +928,76 @@
|
|
928 |
}
|
929 |
};
|
930 |
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
953 |
|
954 |
-
svgContainer.appendChild(path);
|
955 |
-
}
|
956 |
-
});
|
957 |
</script>
|
958 |
</body>
|
959 |
</html>
|
|
|
279 |
// Voici un objet exemple contenant vos pays et l'attribut friendless
|
280 |
const countries = {
|
281 |
'AF': {
|
282 |
+
d: 'M1369.9,333.8h-5.4l-3.8-0.5l-2.5,2.9l-2.1,0.7l-1.5,1.3l-2.6-2.1l-1-5.4l-1.6-0.3v-2l-3.2-1.5l-1.7,2.3l0.2,2.6 l-0.6,0.9l-3.2-0.1l-0.9,3l-2.1-1.3l-3.3,2.1l-1.8-0.8l-4.3-1.4h-2.9l-1.6-0.2l-2.9-1.7l-0.3,2.3l-4.1,1.2l0.1,5.2l-2.5,2l-4,0.9 l-0.4,3l-3.9,0.8l-5.9-2.4l-0.5,8l-0.5,4.7l2.5,0.9l-1.6,3.5l2.7,5.1l1.1,4l4.3,1.1l1.1,4l-3.9,5.8l9.6,3.2l5.3-0.9l3.3,0.8l0.9-1.4 l3.8,0.5l6.6-2.6l-0.8-5.4l2.3-3.6h4l0.2-1.7l4-0.9l2.1,0.6l1.7-1.8l-1.1-3.8l1.5-3.8l3-1.6l-3-4.2l5.1,0.2l0.9-2.3l-0.8-2.5l2-2.7 l-1.4-3.2l-1.9-2.8l2.4-2.8l5.3-1.3l5.8-0.8l2.4-1.2l2.8-0.7L1369.9,333.8L1369.9,333.8z', friendless:'No'
|
283 |
},
|
284 |
'AL': {
|
285 |
d: 'M1077.5,300.5l-2,3.1l0.5,1.9l0,0l1,1l-0.5,1.9l-0.1,4.3l0.7,3l3,2.1l0.2,1.4l1,0.4l2.1-3l0.1-2.1l1.6-0.9V312 l-2.3-1.6l-0.9-2.6l0.4-2.1l0,0l-0.5-2.3l-1.3-0.6l-1.3-1.6l-1.3,0.5L1077.5,300.5L1077.5,300.5z'
|
286 |
+
,friendless:'No'},
|
287 |
'DZ': {
|
288 |
d: 'M1021,336.9l-3.6,0.4l-2.2-1.5h-5.6l-4.9,2.6l-2.7-1l-8.7,0.5l-8.9,1.2l-5,2l-3.4,2.6l-5.7,1.2l-5.1,3.5l2,4.1 l0.3,3.9l1.8,6.7l1.4,1.4l-1,2.5l-7,1l-2.5,2.4l-3.1,0.5l-0.3,4.7l-6.3,2.5l-2.1,3.2L944,383l-5.4,1l-8.9,4.7l-0.1,7.5v0.4l-0.1,1.2 l20.3,15.5l18.4,13.9l18.6,13.8l1.3,3l3.4,1.8l2.6,1.1l0.1,4l6.1-0.6l7.8-2.8l15.8-12.5l18.6-12.2l-2.5-4l-4.3-2.9l-2.6,1.2l-2-3.6 l-0.2-2.7l-3.4-4.7l2.1-2.6l-0.5-4l0.6-3.5l-0.5-2.9l0.9-5.2l-0.4-3l-1.9-5.6l-2.6-11.3l-3.4-2.6v-1.5l-4.5-3.8l-0.6-4.8l3.2-3.6 l1.1-5.3l-1-6.2L1021,336.9L1021,336.9z'
|
289 |
},
|
|
|
928 |
}
|
929 |
};
|
930 |
|
931 |
+
const regions = {
|
932 |
+
'Canada': ['CA'],
|
933 |
+
'Mexico': ['MX'],
|
934 |
+
'South America': ['AR', 'BO', 'BR', 'CL', 'CO', 'EC', 'GY', 'PY', 'PE', 'SR', 'UY', 'VE', 'GF'],
|
935 |
+
'Africa': ['AO', 'BJ', 'BF', 'BW', 'BI', 'CV', 'CF', 'CG', 'CM', 'CD', 'CI', 'DZ', 'EH', 'EG', 'ER', 'ET', 'GA', 'GH', 'GM', 'GN', 'GQ', 'GW', 'KE', 'LS', 'LR', 'LY', 'MA', 'MG', 'ML', 'MR', 'MU', 'MW', 'MZ', 'NA', 'NE', 'NG', 'RW', 'SD', 'SN', 'SO', 'SS', 'ST', 'SZ', 'TD', 'TG', 'TN', 'TZ', 'UG', 'ZA', 'ZM', 'ZW', 'SL'],
|
936 |
+
'Europe': ['AL', 'AD', 'AT', 'BE', 'BG', 'BY', 'CH', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE', 'IS', 'IT', 'LT', 'LU', 'LV', 'MC', 'MD', 'ME', 'MK', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RS', 'SE', 'SI', 'SK', 'UA', 'VA'],
|
937 |
+
'Middle-East': ['AE', 'BH', 'IL', 'IQ', 'IR', 'JO', 'KW', 'LB', 'OM', 'QA', 'SA', 'SY', 'YE'],
|
938 |
+
'Russia': ['RU'],
|
939 |
+
'China': ['CN'],
|
940 |
+
'India': ['IN'],
|
941 |
+
'Australia': ['AU'],
|
942 |
+
'Pacific': ['FJ', 'KI', 'MH', 'NR', 'NZ', 'PW', 'PG', 'SB', 'TO', 'TV', 'VU', 'WS'],
|
943 |
+
'Taiwan': ['TW'],
|
944 |
+
'Greenland': ['GL'],
|
945 |
+
'North-America': ['BZ', 'CR', 'CU', 'DO', 'GT', 'HN', 'HT', 'JM', 'NI', 'PA', 'SV', 'US'],
|
946 |
+
'Caribbean': ['AG', 'AI', 'BB', 'BS', 'DM', 'GD', 'KN', 'LC', 'VC', 'TT', 'VG', 'VI'],
|
947 |
+
'Other-Asia': ['AF', 'AM', 'AZ', 'BD', 'BT', 'CY', 'GE', 'ID', 'JP', 'KZ', 'KG', 'KH', 'KR', 'LA', 'LK', 'MM', 'MN', 'MY', 'NP', 'PH', 'PK', 'SG', 'TJ', 'TH', 'TL', 'TM', 'UZ', 'VN']
|
948 |
+
};
|
949 |
+
|
950 |
+
// Le dico qu'on reçoit
|
951 |
+
const regionData = {
|
952 |
+
"United-States": { "money": 100, "friendliness": -1 },
|
953 |
+
"Canada": { "money": 50, "friendliness": -1 },
|
954 |
+
"Mexico": { "money": 30, "friendliness": 2 },
|
955 |
+
"South-America": { "money": 40, "friendliness": 3 },
|
956 |
+
"Africa": { "money": 20, "friendliness": 1 },
|
957 |
+
"Europe": { "money": 80, "friendliness": 2 },
|
958 |
+
"Middle-East": { "money": 60, "friendliness": -2 },
|
959 |
+
"Russia": { "money": 70, "friendliness": -3 },
|
960 |
+
"China": { "money": 90, "friendliness": -1 },
|
961 |
+
"India": { "money": 50, "friendliness": 2 },
|
962 |
+
"Australia": { "money": 55, "friendliness": 1 },
|
963 |
+
"Pacific": { "money": 25, "friendliness": 3 },
|
964 |
+
"Taiwan": { "money": 65, "friendliness": 0 },
|
965 |
+
"Greenland": { "money": 10, "friendliness": 1 }
|
966 |
+
};
|
967 |
+
|
968 |
+
|
969 |
+
|
970 |
+
|
971 |
+
|
972 |
+
// Détermine la couleur de chaque région (vert si au moins un pays est "friendless: Yes", rouge sinon)
|
973 |
+
const regionColors = Object.keys(regionData).reduce((acc, region) => {
|
974 |
+
const friendliness = regionData[region].friendliness;
|
975 |
+
// Convertir `friendliness` en une couleur allant de rouge vif (-3) à vert vif (3)
|
976 |
+
const green = Math.max(0, 255 + friendliness * 85);
|
977 |
+
const red = Math.max(0, 255 - friendliness * 85);
|
978 |
+
acc[region] = `rgb(${red}, ${green}, 0)`; // Couleur calculée
|
979 |
+
return acc;
|
980 |
+
}, {});
|
981 |
+
|
982 |
+
|
983 |
+
// Injecte les chemins des régions dans la carte SVG
|
984 |
+
const worldMap = document.getElementById('worldMap');
|
985 |
+
|
986 |
+
Object.keys(regions).forEach((region) => {
|
987 |
+
const countryCodes = regions[region]; // Pays de la région
|
988 |
+
countryCodes.forEach((countryCode) => {
|
989 |
+
const country = countries[countryCode];
|
990 |
+
if (country && country.d) {
|
991 |
+
// Créer un chemin pour chaque pays
|
992 |
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
993 |
+
path.setAttribute('d', country.d); // Définir le chemin SVG
|
994 |
+
path.setAttribute('fill', regionColors[region] || 'gray'); // Couleur basée sur la région
|
995 |
+
path.setAttribute('stroke', '#000'); // Ajouter un contour noir
|
996 |
+
worldMap.appendChild(path);
|
997 |
+
}
|
998 |
+
});
|
999 |
+
});
|
1000 |
|
|
|
|
|
|
|
1001 |
</script>
|
1002 |
</body>
|
1003 |
</html>
|