adicionar função de mudar distribuicao de mapa e mostrar estatisticas de mapa
This commit is contained in:
@ -1,10 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import tkinter as tk
|
import random
|
||||||
from tkinter import ttk
|
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
from modules.agente import Agente
|
from modules.agente import Agente
|
||||||
from modules.mapa import Mapa
|
from modules.mapa import Mapa
|
||||||
|
import modules.estrategia as ModEstrategia
|
||||||
flags = 0
|
flags = 0
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +46,43 @@ def criarTabuleiro(
|
|||||||
0)
|
0)
|
||||||
|
|
||||||
|
|
||||||
|
def popularMapa(mapa: Mapa) -> None:
|
||||||
|
for pos_y in range(0, mapa.dimensao[0]):
|
||||||
|
for pos_x in range(0, mapa.dimensao[1]):
|
||||||
|
# escolher uma estrategia aleatoria
|
||||||
|
tmp_estrategia = random.choice(
|
||||||
|
ModEstrategia.listaNomesEstrategias())
|
||||||
|
# criar Agente com estrategia aleatoria e colocar na posicao y e x
|
||||||
|
mapa.mundo[pos_y][pos_x] = Agente(tmp_estrategia)
|
||||||
|
|
||||||
|
|
||||||
|
def mostrarEstatisticas(mapa: Mapa | None) -> None:
|
||||||
|
if mapa is None:
|
||||||
|
print("SEM MAPA!!")
|
||||||
|
else:
|
||||||
|
stats_estrategias: dict = {}
|
||||||
|
n_total_agentes: int = 0
|
||||||
|
print("estatisticas mapa:")
|
||||||
|
for tipo_estrategia in ModEstrategia.lista_estrategias:
|
||||||
|
stats_estrategias[tipo_estrategia] = 0
|
||||||
|
for pos_y in range(0, mapa.dimensao[0]):
|
||||||
|
for pos_x in range(0, mapa.dimensao[1]):
|
||||||
|
tmp_agente = mapa.posicao((pos_y, pos_x))
|
||||||
|
stats_estrategias[tmp_agente.estrategia] += 1
|
||||||
|
n_total_agentes += 1
|
||||||
|
for tipo_estrategia in stats_estrategias:
|
||||||
|
print(f"{tipo_estrategia}: {
|
||||||
|
(stats_estrategias[tipo_estrategia]/n_total_agentes)*100:3.2f}")
|
||||||
|
|
||||||
|
|
||||||
|
def interaccaoEntreAgentes(agente1: Agente, agente2: Agente) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def correrInteraccoesEntreAgentes(mapa: Mapa | None) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main(mapa: Mapa | None):
|
def main(mapa: Mapa | None):
|
||||||
if mapa is None:
|
if mapa is None:
|
||||||
print("SEM MAPA!!")
|
print("SEM MAPA!!")
|
||||||
@ -67,10 +103,13 @@ def main(mapa: Mapa | None):
|
|||||||
if event.key == pg.K_q:
|
if event.key == pg.K_q:
|
||||||
running = False
|
running = False
|
||||||
if event.key == pg.K_c:
|
if event.key == pg.K_c:
|
||||||
# trocar cor
|
mapa = Mapa((30, 30))
|
||||||
pass
|
popularMapa(mapa)
|
||||||
|
if event.key == pg.K_s:
|
||||||
|
mostrarEstatisticas(mapa)
|
||||||
# (367, 250)
|
# (367, 250)
|
||||||
criarTabuleiro(janela, mapa.dimensao, mapa)
|
criarTabuleiro(janela, mapa.dimensao, mapa)
|
||||||
|
correrInteraccoesEntreAgentes(mapa)
|
||||||
pg.display.flip()
|
pg.display.flip()
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
|
||||||
@ -78,30 +117,6 @@ def main(mapa: Mapa | None):
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
class Frame_Mapa(ttk.Frame):
|
|
||||||
def __init__(self, mapa: Mapa):
|
|
||||||
super().__init__()
|
|
||||||
self.n_linhas: int = mapa.dimensao[0]
|
|
||||||
self.n_colunas: int = mapa.dimensao[1]
|
|
||||||
for grid_y in range(0, self.n_linhas):
|
|
||||||
for grid_x in range(0, self.n_colunas):
|
|
||||||
tmp_label = tk.Label(self, text="0")
|
|
||||||
tmp_label.grid(column=grid_x, row=grid_y)
|
|
||||||
|
|
||||||
|
|
||||||
class App(tk.Tk):
|
|
||||||
def __init__(self, mapa: Mapa) -> None:
|
|
||||||
super().__init__()
|
|
||||||
# titulo e icone
|
|
||||||
self.title('Game Theory of Life')
|
|
||||||
self.iconbitmap()
|
|
||||||
# definir frames dentro da janela principal
|
|
||||||
self.frame_mapa = Frame_Mapa(mapa)
|
|
||||||
self.frame_mapa.grid(row=0, column=0)
|
|
||||||
# iniciar janela da aplicação
|
|
||||||
self.mainloop()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
mapa_mundo: Mapa = Mapa((10, 10))
|
mapa_mundo: Mapa = Mapa((10, 10))
|
||||||
app = App(mapa_mundo)
|
app = App(mapa_mundo)
|
||||||
|
|||||||
Reference in New Issue
Block a user