From 40579b4429cc68e355595923fcc3aeb9381f47eb Mon Sep 17 00:00:00 2001 From: Luis Rodrigues Date: Tue, 10 Sep 2024 17:38:42 +0100 Subject: [PATCH] definir flag 'aleatorio' para gerar dados aleatorios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit para utilização em testes --- game_theory_of_life.py | 2 +- modules/agente.py | 4 ++-- modules/mapa.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/game_theory_of_life.py b/game_theory_of_life.py index 1ee4f36..c24d964 100644 --- a/game_theory_of_life.py +++ b/game_theory_of_life.py @@ -5,7 +5,7 @@ from modules.mapa import Mapa tamanho_mundo: tuple[int, int] = (30, 30) -mapa = Mapa(tamanho_mundo) +mapa = Mapa(tamanho_mundo, aleatorio=True) mapa.mostrar() # Gui.App() diff --git a/modules/agente.py b/modules/agente.py index 1444335..5845b01 100644 --- a/modules/agente.py +++ b/modules/agente.py @@ -28,13 +28,13 @@ class Agente(): pontuacao: int - def __init__(self): + def __init__(self, aleatorio: bool = False): # definir estrategia aleatoriamente self.estrategia = Estrategia(random.randint(0, Estrategia.__len__()-1)) self.definirEstrategia() # identificador de agente self.id_agente = id(self) - self.pontuacao = 0 + self.pontuacao = 0 if not aleatorio else random.randint(1, 99) def __str__(self): return f'Dados Agente ({self.id_agente})\n\testrategia: {self.estrategia}\n\tpontução: {self.pontuacao}' diff --git a/modules/mapa.py b/modules/mapa.py index afafa5b..0cc1d7b 100644 --- a/modules/mapa.py +++ b/modules/mapa.py @@ -8,21 +8,21 @@ class Mapa: dimensao: tuple[int, int] mundo: list - def __init__(self, dimensao: tuple[int, int]): + def __init__(self, dimensao: tuple[int, int], aleatorio: bool = False): self.mundo = [] self.dimensao = dimensao - self.mundo = self.inicializar() + self.mundo = self.inicializar(aleatorio=aleatorio) self.id_mapa = id(self) def __str__(self): return f'Dados Mapa ({self.id_mapa})\n\tdimensao: {self.dimensao[0]} x {self.dimensao[1]}' - def inicializar(self) -> list: + def inicializar(self, aleatorio: bool = False) -> list: # inicializar mundo for _ in range(0, self.dimensao[0]): mundo_tmp: list = [] for _ in range(0, self.dimensao[1]): - mundo_tmp.append(Agente()) + mundo_tmp.append(Agente(aleatorio)) self.mundo.append(mundo_tmp) return self.mundo