class DataExtension(): COIN_INIT_POSITIONS = [ Vector2(7, 4), Vector2(3, 7), Vector2(6, 6), Vector2(7, 2), Vector2(2, 8), Vector2(3, 1), Vector2(4, 3), Vector2(3, 5), Vector2(7, 6), Vector2(2, 1) ] #COIN_INIT_POSITIONS = [Vector2(*v) for v in np.random.randint(0, COIN_POOL_SIZE, COIN_POOL_SIZE*2).reshape(COIN_POOL_SIZE, -1)] def _create_coin_infos(self): coins = [] pos_indexes = random.sample(range(10), 5) for i in range(config.NUM_COIN): pos_idx = pos_indexes[i] tag = '{0}-{1}'.format(i, pos_idx) coin = copy.deepcopy(config.BASE_COIN) coin.id = coin.id.format(tag) coin.position = DataExtension.COIN_INIT_POSITIONS[pos_idx] coins.append(coin) return coins
def _initialize_action_mask(self): # create new plot plt = figure(plot_width=200, plot_height=200, title='action mask') plt.xaxis.visible = False plt.xgrid.visible = False plt.yaxis.visible = False plt.ygrid.visible = False # set xs xy center = Vector2(1, 1) xs, ys = [], [] for d in SerializerExtension.DIRECTS: v = d + center xs.append(v.x) ys.append(v.y) # skill xs.append(center.x) ys.append(center.y) self.action_mask_xs = xs self.action_mask_ys = ys self._rd_mask = plt.rect( self.action_mask_xs, self.action_mask_ys, 0.9, 0.9, fill_alpha=0.6, color=["silver"] * 10, line_color='silver', ) return plt
def _deserialize_action(self, data): # continues if len(data) == 4: direct = SerializerExtension.DIRECTS[np.argmax(data)] else: direct = Vector2(*data) actions = [('player-0', config.Action.move_toward, direct, None)] return actions
def _deserialize_action(self, data): if np.ndim(data) == 0: direct = SerializerExtension.DIRECTS[data] elif len(data) == len(SerializerExtension.DIRECTS): direct = SerializerExtension.DIRECTS[np.argmax(data)] else: direct = Vector2(*data) actions = [('player-0', config.Action.move_toward, direct, None)] return actions
def __init__(self, index, angles): vx = Vector2(1, 0) self.index = index self.angles = angles self.angle = np.mean(self.angles) self.direct = vx.rotate(self.angle) self.directs = (vx.rotate(self.angles[0]), vx.rotate(self.angles[1])) # temp self.sensed_object = None self.sensed_range = None
def get_label_continues(s): player = s[0:2] npc = s[2:].reshape((-1, 2)) d2 = np.sum(np.square(player - npc), axis=1) index = np.argmin(d2) target = npc[index] direct = Vector2(*(target - player)).normalized return direct
SAVE_SUMMARIES_SECS = 30 LOG_DIR = './log/' NUM_WORKER = 4 VISUALISED_WORKERS = [] # e.g. [0] or [1,2] _N_AVERAGE = 100 VSTR = 'V0' OB_SPACE_SHAPE = [6] GAME_NAME = config.GAME_NAME config.BOKEH_MODE = "bokeh_serve" # you need run `bokeh serve` firstly config.MAP_SIZE = Vector2(10, 10) config.GAME_PARAMS.fps = 24 config.GAME_PARAMS.max_steps = 300 config.NUM_PLAYERS = 1 config.NUM_NPC = 1 config.PLAYER_INIT_RADIUS = (0.0, 0.0) config.NPC_INIT_RADIUS = 1 / config.MAP_SIZE * 7 #(0.15, 0.2) config.NPC_SKILL_COUNT = 1
import numpy as np from easydict import EasyDict as edict from gymgame.engine import extension, Vector2 from gymgame.tinyrpg.sword import config, Serializer, EnvironmentGym from gymgame.tinyrpg.framework import Skill, Damage, SingleEmitter from gym import spaces GAME_NAME = config.GAME_NAME config.BOKEH_MODE = "notebook" # you need run `bokeh serve` firstly config.MAP_SIZE = Vector2(30, 30) #config.GRID_SIZE = Vector2(20, 20) config.GAME_PARAMS.fps = 24 config.GAME_PARAMS.max_steps = 300 config.NUM_PLAYERS = 1 config.NUM_NPC = 1 config.PLAYER_INIT_RADIUS = (0.0, 1.0) config.NPC_INIT_RADIUS = (0.0, 1.0) config.NPC_SKILL_COUNT = 1 config.SKILL_DICT = { 'normal_attack':
import numpy as np from gymgame.engine import extension, Vector2 from gymgame.tinyrpg.man import config, Serializer, EnvironmentGym from gym import spaces config.MAP_SIZE = Vector2(10, 10) #config.GRID_SIZE = (30, 30) config.GAME_PARAMS.max_steps = 100 config.NUM_BULLET = 0 config.NUM_COIN = 5 config.PLAYER_INIT_RADIUS = (0.0, 0.1) config.COIN_INIT_RADIUS = (0.3, 1.0) config.COIN_REVIVE = False GAME_NAME = config.GAME_NAME @extension(EnvironmentGym) class EnvExtension(): def _init_action_space(self): return spaces.Discrete(4) @extension(Serializer)