-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_results.py
76 lines (62 loc) · 3.97 KB
/
display_results.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
from tkinter.messagebox import showinfo
from statistics import fmean
from config import *
from global_items import handle, smilies, smilies_data, evolution_status
import config
@handle
def D_find_average_from_smilies():
smilies_amount = len(smilies)
write_text_eventual = ''
averaged = {
'generation_n': round(fmean(smiley.generation_n for smiley in smilies)),
'plant_preference': round(fmean(1 if smiley.food_preference == PLANTS else 0 for smiley in smilies)), # Percent of smilies preferring plants
'vision_distance': round(fmean(smiley.vision_distance for smiley in smilies)),
'average_smiley_speed': round(fmean(smiley.speed for smiley in smilies)*SPEED_RATIO),
'procreation_threshold': round(fmean(smiley.procreation_threshold for smiley in smilies)),
'energy': round(fmean(smiley.energy for smiley in smilies)),
'descendants left': smilies_amount,
}
averaged_analysis = {}
one_species_survived_line = 'One of the species has survived'
average_generation_number = f'The average generation number of the smilies of the survived species: {averaged["generation_n"]}'
def ending() -> str: # Handling the 's' at the end of the word 'descendant'
return f"{smilies_amount} descendant{'s' if smilies_amount > 1 else ''} left"
descendants_left_line = ending()
initial_values = {
'vision_distance': smilies_data['average_vision_distance'],
'smiley_speed': smilies_data['average_speed'],
'procreation_threshold': PROCREATION_THRESHOLD,
'energy': INITIAL_ENERGY
}
plant_preference_chance_text_turtle = round(sum(1 if smiley.food_preference == PLANTS else 0 for smiley in smilies)/smilies_amount*100) # Percent of smilies preferring plants
for property in averaged:
if property not in ('generation_n', 'descendants left', 'average_smiley_speed'):
if property == 'plant_preference':
averaged_analysis['plant_preference-now'] = f'The chance that the food preference is "plant" for the survived species now: {plant_preference_chance_text_turtle}%'
averaged_analysis['plant_preference-initial'] = f'The chance that the food preference is "plant" for every species initially: {round(PLANT_PREFERENCE_CHANCE*SPEED_RATIO)}%\n'
averaged_analysis['smiley_preference-now'] = f'The chance that the food preference is "smiley" for the survived species now: {100-plant_preference_chance_text_turtle}%'
averaged_analysis['smiley_preference-initial'] = f'The chance that the food preference is "smiley" for every species initially: {100-round(PLANT_PREFERENCE_CHANCE*SPEED_RATIO)}%\n'
else:
averaged_analysis[property+'-now'] = f'The average {property.replace("_", " ")} of the survived species now:\xa0{averaged[property]}'
value_ = initial_values[property]*100 if float(initial_values[property]) != int(initial_values[property]) else initial_values[property]
averaged_analysis[property+'-initial'] = f'The average {property.replace("_", " ")} for every species initially:\xa0{int(value_)}\n'
write_text = [
one_species_survived_line,
descendants_left_line+'\n',
average_generation_number+'\n'] + [averaged_analysis[text] for text in averaged_analysis]
for text in write_text:
if text != '':
write_text_eventual += text+'\n'
return write_text_eventual
@handle
def D_display_results():
match evolution_status.result:
case config.NO_CREATURES:
write_text_eventual = 'Neither smilies nor zombies have survived'
case config.ONE_SMILEY_SPECIES_WON:
write_text_eventual = D_find_average_from_smilies()
case config.ONLY_ZOMBIE_BOSS:
write_text_eventual = 'Only the zombie boss has survived. This happens tremendously infrequently :)'
case _:
write_text_eventual = 'The zombies have won'
showinfo(title=TITLE, message=write_text_eventual)