redefinir metodo __str__() para mostrar info sobre objectos
This commit is contained in:
@ -10,8 +10,9 @@ mapa.mostrar()
|
|||||||
|
|
||||||
# Gui.App()
|
# Gui.App()
|
||||||
|
|
||||||
|
print(mapa)
|
||||||
pos_y = random.randint(0, tamanho_mundo[0])
|
pos_y = random.randint(0, tamanho_mundo[0])
|
||||||
pos_x = random.randint(0, tamanho_mundo[1])
|
pos_x = random.randint(0, tamanho_mundo[1])
|
||||||
obj_agente: Agente | None = mapa.posicao((pos_y, pos_x))
|
obj_agente: Agente | None = mapa.posicao((pos_y, pos_x))
|
||||||
if obj_agente is not None:
|
if obj_agente is not None:
|
||||||
obj_agente.mostrar()
|
print(obj_agente)
|
||||||
|
|||||||
@ -36,6 +36,9 @@ class Agente():
|
|||||||
self.id_agente = id(self)
|
self.id_agente = id(self)
|
||||||
self.pontuacao = 0
|
self.pontuacao = 0
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'Dados Agente ({self.id_agente})\n\testrategia: {self.estrategia}\n\tpontução: {self.pontuacao}'
|
||||||
|
|
||||||
def definirEstrategia(self):
|
def definirEstrategia(self):
|
||||||
match self.estrategia:
|
match self.estrategia:
|
||||||
case Estrategia.Neutro:
|
case Estrategia.Neutro:
|
||||||
@ -58,27 +61,3 @@ class Agente():
|
|||||||
self.retaliação = 0.5
|
self.retaliação = 0.5
|
||||||
self.perdao = 0.5
|
self.perdao = 0.5
|
||||||
self.coerencia = 0.5
|
self.coerencia = 0.5
|
||||||
|
|
||||||
def mostrar(self) -> None:
|
|
||||||
print(f'Dados Agente: {self.id_agente}')
|
|
||||||
print(f'\testrategia: {self.estrategia}')
|
|
||||||
print(f'\tpontuação: {self.pontuacao}')
|
|
||||||
|
|
||||||
|
|
||||||
# agente = Agente()
|
|
||||||
#
|
|
||||||
# print(f'ID: {agente.id_agente}')
|
|
||||||
# print(f'Estratégia: {agente.estrategia}')
|
|
||||||
# print(f'\tAmabilidade: {agente.amabilidade}')
|
|
||||||
# print(f'\tRetaliação: {agente.retaliação}')
|
|
||||||
# print(f'\tPerdão: {agente.perdao}')
|
|
||||||
# print(f'\tCoerência: {agente.coerencia}')
|
|
||||||
|
|
||||||
|
|
||||||
# lista_estrategias = Estrategia._member_map_
|
|
||||||
# lista_estrategias = Estrategia.__dict__
|
|
||||||
|
|
||||||
# for estrategia in lista_estrategias:
|
|
||||||
# print(estrategia)
|
|
||||||
|
|
||||||
# print(lista_estrategias)
|
|
||||||
|
|||||||
@ -12,6 +12,10 @@ class Mapa:
|
|||||||
self.mundo = []
|
self.mundo = []
|
||||||
self.dimensao = dimensao
|
self.dimensao = dimensao
|
||||||
self.mundo = self.inicializar()
|
self.mundo = self.inicializar()
|
||||||
|
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) -> list:
|
||||||
# inicializar mundo
|
# inicializar mundo
|
||||||
|
|||||||
Reference in New Issue
Block a user