renomear função 'mostrarEstatistica()' para 'prepararEstatistica()'
para melhor representar o que a função faz (dado que removemos o codigo que mostrava a estatistica do mapa), renomeamos a função para melhor descrever a sua tarefa
This commit is contained in:
@ -73,7 +73,7 @@ def popularMapa(mapa: Mapa) -> None:
|
|||||||
mapa.mundo[pos_y][pos_x] = Agente(estrategia, (pos_x, pos_y))
|
mapa.mundo[pos_y][pos_x] = Agente(estrategia, (pos_x, pos_y))
|
||||||
|
|
||||||
|
|
||||||
def mostrarEstatisticas(mapa: Mapa | None) -> dict[str, int]:
|
def prepararEstatistica(mapa: Mapa | None) -> dict[str, int]:
|
||||||
if mapa is None:
|
if mapa is None:
|
||||||
print("SEM MAPA!!")
|
print("SEM MAPA!!")
|
||||||
else:
|
else:
|
||||||
@ -87,11 +87,11 @@ def mostrarEstatisticas(mapa: Mapa | None) -> dict[str, int]:
|
|||||||
tmp_agente = mapa.posicao((pos_y, pos_x))
|
tmp_agente = mapa.posicao((pos_y, pos_x))
|
||||||
stats_estrategias[tmp_agente.estrategia] += 1
|
stats_estrategias[tmp_agente.estrategia] += 1
|
||||||
n_total_agentes += 1
|
n_total_agentes += 1
|
||||||
for tipo_estrategia in stats_estrategias:
|
# for tipo_estrategia in stats_estrategias:
|
||||||
print(
|
# print(
|
||||||
f"{tipo_estrategia}: {
|
# f"{tipo_estrategia}: {
|
||||||
(stats_estrategias[tipo_estrategia] / n_total_agentes) * 100:3.2f}"
|
# (stats_estrategias[tipo_estrategia] / n_total_agentes) * 100:3.2f}"
|
||||||
)
|
# )
|
||||||
return stats_estrategias
|
return stats_estrategias
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ def main(mapa: Mapa | None, tamanho_mapa: tuple[int, int]):
|
|||||||
running: bool = True
|
running: bool = True
|
||||||
# cor1: tuple[int, int, int, int] = (255, 0, 0, 0)
|
# cor1: tuple[int, int, int, int] = (255, 0, 0, 0)
|
||||||
# cor2: tuple[int, int, int, int] = (0, 255, 0, 0)
|
# cor2: tuple[int, int, int, int] = (0, 255, 0, 0)
|
||||||
mostrarMapa(mapa)
|
# mostrarMapa(mapa)
|
||||||
quadrado_seleccionado: pg.Rect | None = None
|
quadrado_seleccionado: pg.Rect | None = None
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
@ -146,9 +146,6 @@ def main(mapa: Mapa | None, tamanho_mapa: tuple[int, int]):
|
|||||||
janela.fill(0)
|
janela.fill(0)
|
||||||
mapa = Mapa(tamanho_mapa)
|
mapa = Mapa(tamanho_mapa)
|
||||||
popularMapa(mapa)
|
popularMapa(mapa)
|
||||||
# mostrar estatisticas do mapa com 's' (stats)
|
|
||||||
if event.key == pg.K_s:
|
|
||||||
mostrarEstatisticas(mapa)
|
|
||||||
# correr proxima iteração com 'n' (next)
|
# correr proxima iteração com 'n' (next)
|
||||||
if event.key == pg.K_n:
|
if event.key == pg.K_n:
|
||||||
ModInteraccoes.correrInteraccoesEntreAgentes(mapa)
|
ModInteraccoes.correrInteraccoesEntreAgentes(mapa)
|
||||||
@ -217,7 +214,7 @@ def main(mapa: Mapa | None, tamanho_mapa: tuple[int, int]):
|
|||||||
janela_stats.fill(pg.Color(0, 0, 0, 0))
|
janela_stats.fill(pg.Color(0, 0, 0, 0))
|
||||||
janela.blit(janela_stats, (janela.get_size()[0] - 200, 10))
|
janela.blit(janela_stats, (janela.get_size()[0] - 200, 10))
|
||||||
font = pg.font.Font(None, 20)
|
font = pg.font.Font(None, 20)
|
||||||
dict_estrat = mostrarEstatisticas(mapa)
|
dict_estrat = prepararEstatistica(mapa)
|
||||||
n_linhas = 0
|
n_linhas = 0
|
||||||
for strat in dict_estrat:
|
for strat in dict_estrat:
|
||||||
strat_label = font.render(
|
strat_label = font.render(
|
||||||
|
|||||||
Reference in New Issue
Block a user