final merge

This commit is contained in:
tubks 2021-06-22 22:21:03 +02:00
parent 3af4d0e68f
commit daecac46b7

View File

@ -1,22 +1,64 @@
from model import GameMap
from src.agent.map.gameMap import GameMap
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.modules.TextVisualization import TextElement
from mesa.visualization.ModularVisualization import ModularServer
#from src.decisiontree import create_model
from src.direction import Direction
from collections import defaultdict
import src.agent.ga_chromosome as ga
def player_representation(agent):
portrayal = {"Shape": "sprites/hero.png",
portrayal = {"Shape": "sprites/heroE.png",
"Layer": 1}
if agent.isBox:
if agent.isPlayer and agent.direction==Direction.N:
portrayal["Shape"] = "sprites/heroN.png"
elif agent.isPlayer and agent.direction == Direction.W:
portrayal["Shape"] = "sprites/heroW.png"
elif agent.isPlayer and agent.direction == Direction.S:
portrayal["Shape"] = "sprites/heroS.png"
elif agent.isBox:
portrayal["Shape"] = "sprites/box.png"
portrayal["Layer"] = 0
elif agent.isCreature:
portrayal["Shape"]='sprites/goblin.png'
if agent.name=='Goblin':
portrayal["Shape"] = 'sprites/goblin.png'
elif agent.name=='Skeleton':
portrayal["Shape"] = 'sprites/skeletonArcher.png'
return portrayal
grid = CanvasGrid(player_representation, 10, 10, 500, 500)
def chest_content(agent):
if agent.isBox:
portrayal = {"Shape": "sprites/coin.jpg",
"Layer": 1}
return portrayal
grid = CanvasGrid(player_representation, 10, 10, 700, 700)
image=CanvasGrid(chest_content, 1, 1, 200, 200)
class Stats(TextElement):
def render(self, model):
hp = str(model.get_hp())
position = str(model.get_position())
gold = str(model.get_gold())
return "Player hp: {}<br>Current position: {}<br>Player's gold: {}".format(
hp, position, gold)
# class ChestContent(CanvasGrid):
# def render(self,model):
# grid_state = defaultdict(list)
# portrayal = self.chest_content(agent)
# portrayal["x"] = 0
# portrayal["y"] = 0
# grid_state[portrayal["Layer"]].append(portrayal)
# return
# class FightStats(TextElement):
# def render(self, model):
# if model.player.combat:
# return model.player.describe_situation(model.player.opponent, model.player.strategy)
# else:
# return "Not fighting"
ga.create_model()
server = ModularServer(GameMap,
[grid],
[grid,Stats()],
"Map",
{"x":10, "y":10})
server.port = 8521
{"x": 10, "y": 10})
server.port = 8081
server.launch()