def __init__(self, state_size, action_size, random_seed): """Initialize an Agent object. Params ====== state_size (int): dimension of each state action_size (int): dimension of each action random_seed (int): random seed """ self.state_size = state_size self.action_size = action_size self.seed = random.seed(random_seed) self.time_step = 0 # Actor Network (w/ Target Network) self.actor_local = Actor(state_size, action_size, random_seed).to(device) self.actor_target = Actor(state_size, action_size, random_seed).to(device) self.actor_optimizer = optim.Adam(self.actor_local.parameters(), lr=LR_ACTOR) # Critic Network (w/ Target Network) self.critic_local = Critic(state_size, action_size, random_seed).to(device) self.critic_target = Critic(state_size, action_size, random_seed).to(device) self.critic_optimizer = optim.Adam(self.critic_local.parameters(), lr=LR_CRITIC, weight_decay=WEIGHT_DECAY) # Noise process self.noise = OUNoise(action_size, random_seed) # Replay memory self.memory = ReplayBuffer(action_size, BUFFER_SIZE, BATCH_SIZE, random_seed)
def generate(self): if self.butterfly == None: self.butterfly = Actor.Actor() self.butterfly.loadModel('phase_4/models/props/SZ_butterfly-mod.bam') self.butterfly.loadAnims({'flutter': 'phase_4/models/props/SZ_butterfly-flutter.bam', 'glide': 'phase_4/models/props/SZ_butterfly-glide.bam', 'land': 'phase_4/models/props/SZ_butterfly-land.bam'}) index = self.doId % len(self.wingTypes) chosenType = self.wingTypes[index] node = self.butterfly.getGeomNode() for type in self.wingTypes: wing = node.find('**/' + type) if type != chosenType: wing.hide() else: if index == 0 or index == 1: color = self.yellowColors[self.doId % len(self.yellowColors)] else: if index == 2 or index == 3: color = self.whiteColors[self.doId % len(self.whiteColors)] else: if index == 4: color = self.paleYellowColors[self.doId % len(self.paleYellowColors)] else: color = Vec4(1, 1, 1, 1) wing.setColor(color) self.butterfly2 = Actor.Actor(other=self.butterfly) self.butterfly.enableBlend(blendType=PartBundle.BTLinear) self.butterfly.loop('flutter') self.butterfly.loop('land') self.butterfly.loop('glide') rng = RandomNumGen.RandomNumGen(self.doId) playRate = 0.6 + 0.8 * rng.random() self.butterfly.setPlayRate(playRate, 'flutter') self.butterfly.setPlayRate(playRate, 'land') self.butterfly.setPlayRate(playRate, 'glide') self.butterfly2.setPlayRate(playRate, 'flutter') self.butterfly2.setPlayRate(playRate, 'land') self.butterfly2.setPlayRate(playRate, 'glide') self.glideWeight = rng.random() * 2 lodNode = LODNode('butterfly-node') lodNode.addSwitch(100, 40) lodNode.addSwitch(40, 0) self.butterflyNode = NodePath.NodePath(lodNode) self.butterfly2.setH(180.0) self.butterfly2.reparentTo(self.butterflyNode) self.butterfly.setH(180.0) self.butterfly.reparentTo(self.butterflyNode) self.__initCollisions() self.dropShadow = loader.loadModelCopy('phase_3/models/props/drop_shadow') self.dropShadow.setColor(0, 0, 0, 0.3) self.dropShadow.setPos(0, 0.1, -0.05) self.dropShadow.setScale(self.shadowScaleBig) self.dropShadow.reparentTo(self.butterfly) return
def __init__(self, node): AnimatedProp.AnimatedProp.__init__(self, node) self.fish = Actor.Actor() self.fish.reparentTo(self.node.getParent()) self.fish.setTransform(self.node.getTransform()) self.node.clearMat() self.fish.prepareBundle(self.node) self.fish.loadAnims({ 'jump': 'phase_4/models/props/SZ_fish-jump', 'swim': 'phase_4/models/props/SZ_fish-swim' }) self.splashSfxList = ( loader.loadSfx('phase_4/audio/sfx/TT_splash1.mp3'), loader.loadSfx('phase_4/audio/sfx/TT_splash2.mp3')) self.node = self.fish self.geom = self.fish.getGeomNode() self.exitRipples = Ripples(self.geom) self.exitRipples.setBin('fixed', 25, 1) self.exitRipples.setPosHprScale(-0.3, 0.0, 1.24, 0.0, 0.0, 0.0, 0.7, 0.7, 0.7) self.splash = Splash(self.geom) self.splash.setPosHprScale(-1, 0.0, 1.23, 0.0, 0.0, 0.0, 0.7, 0.7, 0.7) randomSplash = random.choice(self.splashSfxList) self.track = Sequence(FunctionInterval(self.randomizePosition), Parallel( self.fish.actorInterval('jump'), Sequence(Wait(0.25), Func(self.exitRipples.play, 0.75)), Sequence( Wait(1.14), Func(self.splash.play), SoundInterval(randomSplash, volume=0.8, node=self.node))), Wait(5 + 10 * random.random()), name=self.uniqueName('Fish'))
def loadBam(self, filePath): """ Loads a Toontown Beta Bam file. Args: filePath (string): Path to Bam file to load. """ isAnimation = 0 # First, we need to check if this Bam file is an animation. It's definitely not animation if filePath[-8:-4] not in ('1500', '1000', '-500', '-250', '-800', '-400', '-mod'): for actorBase, actorPhase in ACTOR_REFERENCE.items(): if filePath.find(actorBase[:-4]) > -1: # If the beginning of the file name is found in the Actor Reference, treat # this file as an animation isAnimation = 1 geom = Actor.Actor(actorPhase + '/' + actorBase, {'anim': filePath}) geom.loop('anim') break # If it's not an animation, just load a regular ol' bam file if not isAnimation: geom = base.loader.loadModel(filePath) geom.reparentTo(render) return geom
def initRandomVehicles(self): for index in range(0, int(len(self.structures) * UNIVERSAL_SHIP_DENSITY)): pilot = Actor('miner') ship = Miner(pilot, self) pilot.setVehicle(ship) pilot.setProfession('miner') self.actors.append(pilot)
def __getPropCopy(self, name): if self.propTypes[name] == 'actor': if not self.props.has_key(name): prop = Actor.Actor() prop.loadModel(self.propStrings[name][0]) animDict = {} animDict[name] = self.propStrings[name][1] prop.loadAnims(animDict) prop.name = name self.storeProp(name, prop) if name in Variants: self.makeVariant(name) return Actor.Actor(other=self.props[name]) else: if not self.props.has_key(name): prop = loader.loadModel(self.propStrings[name][0]) prop.name = name self.storeProp(name, prop) if name in Variants: self.makeVariant(name) return self.props[name].copyTo(hidden)
def __init__(self, env, state_size, action_size, max_action): """ TD3 PyTorch Td3 (agent) policy network model. Args: - env: Openai Gym environment - state_size: Dimensionality of states. - action_size: Dimensionality of actions. - max_action: Maximum action value. """ self.env = env self.state_size = state_size self.action_size = action_size self.max_action = max_action self.actor = Actor(self.state_size, self.action_size, self.max_action) self.actor_target = Actor(self.state_size, self.action_size, self.max_action) self.actor_target.load_state_dict(self.actor.state_dict()) self.actor_optimizer = torch.optim.Adam(self.actor.parameters()) self.critic = Critic(self.state_size, self.action_size) self.critic_target = Critic(self.state_size, self.action_size) self.critic_target.load_state_dict(self.critic.state_dict()) self.critic_optimizer = torch.optim.Adam(self.critic.parameters())
def __loadStuff(self): if self.pole == None: self.pole = Actor.Actor() self.pole.loadModel('phase_4/models/props/fishing-pole-mod') self.pole.loadAnims({'cast': 'phase_4/models/props/fishing-pole-chan'}) self.pole.pose('cast', 0) self.ptop = self.pole.find('**/joint_attachBill') if self.bob == None: import Ripples self.bob = loader.loadModelCopy('phase_4/models/props/fishing_bob') self.ripples = Ripples.Ripples(self.nodePath) self.ripples.hide() if self.splashSound == None: self.splashSound = base.loadSfx('phase_4/audio/sfx/TT_splash1.mp3') return
def get_actor(self, actor_id): """ Gets an Actor instance using an actor_id :param actor_id: string id of an actor :return: an Actor """ if actor_id == self.director: retrieve_id = "director-{0}".format(actor_id) director = True else: retrieve_id = actor_id director = False default = Actor.Actor('NonsenseActorId', director) if Actor.Actor.all_actors.get(retrieve_id, None): return Actor.Actor.all_actors[retrieve_id] else: return default
def __init__(self, node): AnimatedProp.AnimatedProp.__init__(self, node) self.telescope = Actor.Actor() self.telescope.reparentTo(self.node.getParent()) self.telescope.prepareBundle(self.node) self.telescope.loadAnims( {'anim': 'phase_3.5/models/props/HQ_telescope-chan'}) self.telescope.pose('anim', 0) self.node = self.telescope self.track = Sequence( Wait(5.0), self.telescope.actorInterval('anim', startTime=0.0, endTime=32 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=32 / 24.0, endTime=78 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=79 / 24.0, endTime=112 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=112 / 24.0, endTime=79 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=78 / 24.0, endTime=32 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=32 / 24.0, endTime=78 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=79 / 24.0, endTime=112 / 24.0), Wait(0.5), self.telescope.actorInterval('anim', startTime=112 / 24.0, endTime=148 / 24.0), Wait(4.0), name=self.uniqueName('HQTelescope'))
def __init__(self, node): AnimatedProp.AnimatedProp.__init__(self, node) self.periscope = Actor.Actor() self.periscope.reparentTo(self.node.getParent()) self.periscope.prepareBundle(self.node) self.periscope.loadAnims( {'anim': 'phase_3.5/models/props/HQ_periscope-chan'}) self.periscope.pose('anim', 0) self.node = self.periscope self.track = Sequence( Wait(2.0), self.periscope.actorInterval('anim', startTime=0.0, endTime=40 / 24.0), Wait(0.69999999999999996), self.periscope.actorInterval('anim', startTime=40 / 24.0, endTime=90 / 24.0), Wait(0.69999999999999996), self.periscope.actorInterval('anim', startTime=91 / 24.0, endTime=121 / 24.0), Wait(0.69999999999999996), self.periscope.actorInterval('anim', startTime=121 / 24.0, endTime=91 / 24.0), Wait(0.69999999999999996), self.periscope.actorInterval('anim', startTime=90 / 24.0, endTime=40 / 24.0), Wait(0.69999999999999996), self.periscope.actorInterval('anim', startTime=40 / 24.0, endTime=90 / 24.0), Wait(0.69999999999999996), self.periscope.actorInterval('anim', startTime=91 / 24.0, endTime=121 / 24.0), Wait(0.5), self.periscope.actorInterval('anim', startTime=121 / 24.0, endTime=148 / 24.0), Wait(3.0), name=self.uniqueName('HQPeriscope'))
def getLoseActor(self): if self.loseActor == None: (filePrefix, phase) = ModelDict[self.style.body] loseModel = 'phase_' + str(phase) + filePrefix + 'lose-mod' loseAnim = 'phase_' + str(phase) + filePrefix + 'lose' self.loseActor = Actor.Actor(loseModel, {'lose': loseAnim}) loseNeck = self.loseActor.find('**/joint-head') for part in self.headParts: part.instanceTo(loseNeck) self.setSuitClothes(self.loseActor) self.loseActor.setScale(self.scale) self.loseActor.setPos(self.getPos()) self.loseActor.setHpr(self.getHpr()) shadowJoint = self.loseActor.find('**/joint-shadow') dropShadow = loader.loadModelCopy('phase_3/models/props/drop_shadow') dropShadow.setScale(0.45000000000000001) dropShadow.setColor(0.0, 0.0, 0.0, 0.5) dropShadow.reparentTo(shadowJoint) return self.loseActor
def __init__(self, name, remotes=None): self.name = name self.remotes = remotes self.state = 0 self.status = "running" log("Initializing robot", self.name) self.observer = Observer(self.name) self.thinker = Thinker(self.name) self.actor = Actor(self.name) self.session_done = False self.vague = False self.actions = [] self.rewards = [] self.cont_reward = [] if self.remotes: # Observer try: self.remotes['observer'] except: self.observer = Pyro4.Proxy(self.remotes['observer']) # Thinker try: self.remotes['thinker'] except: self.thinker = Pyro4.Proxy(self.remotes['thinker']) # Actor try: self.remotes['actor'] except: self.actor = Pyro4.Proxy(self.remotes['actor']) self.observer.initialize() self.observer.register_device('microphone', Microphone(self.name)) self.observer.register_device('camera', Camera(self.name)) self.actor.register_device('speaker', Speaker(self.name)) self.actor.register_device('eyes', Eyes(self.name))
if done: print(i, "---", ep_reward) break if i % 20 == 0: pass #video_saver.release() if __name__ == '__main__': batch_size = 64 tf_config = tf.ConfigProto() #tf_config.gpu_options.per_process_gpu_memory_fraction = 0.6 tf_config.gpu_options.allow_growth = True saver = tf.train.Saver() env = gym.make('InvertedPendulum-v2') #print(env.action_space.high) with tf.Session(config=tf_config) as sess: actor = Actor.Actor(sess, [4], 1, 0.0001, 0.001, batch_size) critic = Critic.Critic(sess, [4], 1, 0.001, 0.001, 0.99, actor.get_num_trainable_vars()) actor_noise = Noise.GaussianNoise() train_feature(sess, env, actor, critic, actor_noise, batch_size, saver)
def OpenLevelUpWindow(): """Sets up the level up window.""" import GUIREC global LevelUpWindow, TextAreaControl, NewProfPoints, actor global DoneButton global NewSkillPoints, KitName, LevelDiff global Level, Classes, NumClasses, DualSwap, IsMulti global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual LevelUpWindow = GemRB.LoadWindow (3) if GameCheck.IsBG2(): InfoButton = LevelUpWindow.GetControl (125) InfoButton.SetText (13707) InfoButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUpInfoPress) # hide "Character Generation" LevelUpWindow.DeleteControl(0x1000007e) DoneButton = LevelUpWindow.GetControl (0) DoneButton.SetText (11962) DoneButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUpDonePress) DoneButton.SetState (IE_GUI_BUTTON_DISABLED) DoneButton.MakeDefault() # also disable closing by ESC, so we don't stack upgrades DoneButton.MakeEscape () # name pc = GemRB.GameGetSelectedPCSingle () actor = Actor.Actor(pc) Label = LevelUpWindow.GetControl (0x10000000+90) Label.SetText (GemRB.GetPlayerName (pc)) # some current values OldHPMax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS, 1) OldThaco = GemRB.GetPlayerStat (pc, IE_TOHIT, 1) OldLore = GemRB.GetPlayerStat (pc, IE_LORE, 1) for i in range (5): OldSaves[i] = GemRB.GetPlayerStat (pc, IE_SAVEVSDEATH+i, 1) # class Label = LevelUpWindow.GetControl (0x10000000+106) Label.SetText (GUICommon.GetActorClassTitle (pc)) print("Title: " + GUICommon.GetActorClassTitle (pc) + "\tActor Title: " + actor.ClassTitle()) Class = GemRB.GetPlayerStat (pc, IE_CLASS) print("Class: " + str(Class) + "\tActor Class: " + str(actor.classid)) # kit ClassName = GUICommon.GetClassRowName (Class, "class") Kit = GUICommon.GetKitIndex (pc) print("Kit: " + str(Kit) + "\tActor Kit: " + str(actor.KitIndex())) print("ClassName: " + ClassName + "\tActor ClassNames: " + str(actor.ClassNames())) # need this for checking gnomes RaceName = GemRB.GetPlayerStat (pc, IE_RACE, 1) RaceName = CommonTables.Races.FindValue (3, RaceName) RaceName = CommonTables.Races.GetRowName (RaceName) # figure our our proficiency table and index if Kit == 0: KitName = ClassName else: #rowname is just a number, the kitname is the first data column KitName = CommonTables.KitList.GetValue(Kit, 0) # our multiclass variables IsMulti = GUICommon.IsMultiClassed (pc, 1) Classes = [IsMulti[1], IsMulti[2], IsMulti[3]] NumClasses = IsMulti[0] # 2 or 3 if IsMulti; 0 otherwise IsMulti = NumClasses > 1 IsDual = 0 DualSwap = 0 # not multi, check dual if not IsMulti: # check if we're dual classed IsDual = GUICommon.IsDualClassed (pc, 1) Classes = [] # either dual or single only care about 1 class NumClasses = 1 # not dual, must be single if IsDual[0] == 0: Classes = [Class] else: # resolve kits to classes (new class goes first) if IsDual[0] == 3: # 1st kit Classes.append (CommonTables.KitList.GetValue (IsDual[2], 7)) else: # 1st class Classes.append (CommonTables.Classes.GetValue (IsDual[2], 5)) if IsDual[0] == 1: # 2nd kit Classes.append (CommonTables.KitList.GetValue (IsDual[1], 7)) else: # 2nd class Classes.append (CommonTables.Classes.GetValue (IsDual[1], 5)) # store a boolean for IsDual IsDual = IsDual[0] > 0 print("NumClasses: " + str(NumClasses) + "\tActor NumClasses: " + str(actor.NumClasses())) if IsDual: # convert the classes from indicies to class id's DualSwap = GUICommon.IsDualSwap (pc) ClassName = GUICommon.GetClassRowName (Classes[0], "index") KitName = ClassName # for simplicity throughout the code print("Classes: " + str(Classes) + "\tActor Classes: " + str(actor.Classes())) print("IsDual: " + str(IsDual > 0) + "\tActor IsDual: " + str(actor.isdual)) # get the next target levels and difference between levels Level = LUCommon.GetNextLevels(pc, Classes) LevelDiff = LUCommon.GetLevelDiff(pc, Level) # clear some globals, since we may get called multiple times with different classes DeltaWSpells = 0 DeltaDSpells = 0 OldDSpells = [0]*7 OldWSpells = [0]*9 NewDSpells = [0]*7 NewWSpells = [0]*9 # calculate the new spells (results are stored in global variables) GetNewSpells(pc, Classes, Level, LevelDiff, Kit) # this is handled by core # # setup class bonuses for this class # if IsMulti or IsDual or Kit == 0: # ABTable = CommonTables.ClassSkills.GetValue (TmpClassName, "ABILITIES") # else: # single-classed with a kit # ABTable = CommonTables.KitList.GetValue (str(Kit), "ABILITIES") # # # add the abilites if we have a table to ref # if ABTable != "*" and GemRB.HasResource (ABTable, RES_2DA, 1): # GUICommon.AddClassAbilities (pc, ABTable, Level[i], LevelDiff[i]) print("Actor CurrentLevels:" + str(actor.Levels())) print("Levels: " + str(Level) + "\tActor NextLevels: " + str(actor.NextLevels())) print("LevelDiffs: " + str(LevelDiff) + "\tActor LevelDiffs: " + str(actor.LevelDiffs())) #update our saves, thaco, hp and lore LUCommon.SetupSavingThrows (pc, Level) LUCommon.SetupThaco (pc, Level) LUCommon.SetupLore (pc, LevelDiff) LUCommon.SetupHP (pc, Level, LevelDiff) # we set up these labels so late, so they can show the new HP if GameCheck.IsBG1() or GameCheck.IsIWD1(): # armorclass Label = LevelUpWindow.GetControl (0x10000057) Label.SetText (str (GemRB.GetPlayerStat (pc, IE_ARMORCLASS))) Label.SetTooltip (17183) # hp now Label = LevelUpWindow.GetControl (0x10000058) Label.SetText (str (GemRB.GetPlayerStat (pc, IE_HITPOINTS))) Label.SetTooltip (17184) # hp max Label = LevelUpWindow.GetControl (0x10000059) Label.SetText (str (GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS))) Label.SetTooltip (17378) # use total levels for HLAs HLACount = 0 if GameCheck.HasTOB(): # make sure SoA doesn't try to get it HLATable = GemRB.LoadTable("lunumab") # we need to check each level against a multi value (this is kinda screwy) if actor.multiclass: print("Actor HLA Names: " + str(["MULTI" + str(actor.NumClasses()) + name \ for name in actor.ClassNames()])) else: print("Actor HLA Names: " + str(actor.ClassNames())) for i in range (NumClasses): if IsMulti: # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF MultiName = GUICommon.GetClassRowName (Classes[i], "class") MultiName = "MULTI" + str(NumClasses) + MultiName else: MultiName = ClassName # if we can't learn for this class, we can't learn at all FirstLevel = HLATable.GetValue (MultiName, "FIRST_LEVEL", GTV_INT) if Level[i] < FirstLevel: HLACount = 0 break if (Level[i] - LevelDiff[i]) < FirstLevel: # count only from FirstLevel up HLACount += (Level[i] - FirstLevel + 1) else: HLACount += LevelDiff[i] # set values required by the hla level up code HLACount = HLACount // HLATable.GetValue (ClassName, "RATE", GTV_INT) GemRB.SetVar ("HLACount", HLACount) if GameCheck.IsBG2(): HLAButton = LevelUpWindow.GetControl (126) if HLACount: HLAButton.SetText (4954) HLAButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LevelUpHLAPress) else: HLAButton.SetFlags (IE_GUI_BUTTON_DISABLED, OP_OR) # setup our profs Level1 = [] for i in range (len (Level)): Level1.append (Level[i]-LevelDiff[i]) if GameCheck.IsBG2(): LUProfsSelection.SetupProfsWindow (pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUProfsSelection.SetupProfsWindow (pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False, 0) NewProfPoints = GemRB.GetVar ("ProfsPointsLeft") #we autohide the skills and let SetupSkillsWindow show them if needbe for i in range (4): HideSkills (i) if GameCheck.IsBG2(): LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUSkillsSelection.SetupSkillsWindow (pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False) NewSkillPoints = GemRB.GetVar ("SkillPointsLeft") if GameCheck.IsBG2(): TextAreaControl = LevelUpWindow.GetControl(110) TextAreaControl.SetText(GetLevelUpNews()) else: TextAreaControl = LevelUpWindow.GetControl(42) TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff)) RedrawSkills() LevelUpWindow.ShowModal (MODAL_SHADOW_GRAY) # if we have a sorcerer who can learn spells, we need to do spell selection for c in range(NumClasses): if Spellbook.HasSorcererBook (pc, Classes[c]) and DeltaWSpells > 0: LUSpellSelection.OpenSpellsWindow (pc, "SPLSRCKN", Level[c], LevelDiff[c])
[actor_belief_values[option] for option in action if action != []]) receiver_rewards.append( [receiver_reward_values[option] for option in action if action != []]) # Convert to numpy arrays. actions = np.array(actions) actor_rewards = np.array(actor_rewards) actor_beliefs = np.array(actor_beliefs) receiver_rewards = np.array(receiver_rewards) # Instantiate a state, actor, and observer. state = State(actions=actions, actor_rewards=actor_rewards, actor_beliefs=actor_beliefs, receiver_rewards=receiver_rewards) actor = Actor() observer = Observer(state, actor) print("Actions:") print(actions) index = 0 action = actions[index] print("Action:") print(action) # Run the sacrifice model. print(observer.sacrifice(action)) # Run the utilitarian model. print(observer.utilitarian(action, receiver_reward_values))
def copyProp(prop): import Actor if isinstance(prop, Actor.Actor): return Actor.Actor(other=prop) else: return prop.copyTo(hidden)
Looking closer at the floor you can see blood stains. You get the feeling you should leave as soon as possible.""" ) # Build the links nodeA.undirectedConnect(nodeB, ["use"], "Grey hallway") nodeA.directedConnect(nodeC, ["use", "open"], "Green doorway") nodeC.directedConnect(nodeA, ["use", "open"], "White doorway") nodeD.undirectedConnect(nodeB, ["use", "climb"], "Ladder") # Build the player player_commands = { "use": UseCommand(), "open": OpenCommand(), "climb": ClimbCommand() } player = Actor("Some person", commandList=player_commands, location=nodeA) # Create the interface interface = Interface(default="Enter a command: ", options=player_commands) # Main loop running = True while running: if (player.moved): interface.output(player.location.describe()) player.moved = False userInput = interface.getInput() commandName, arguments = interface.getCommand(userInput) command = player.getCommand(commandName) commandError = None
test_data = [] test_data.append(temp) #print test_data reset = Signal(bool(False)) input_arc = Arc.Arc(reset, no_inputs, input_bitwidth, actor_scale, input_bitwidth, complex_valued, size_factor) actor1_actor2_arc = Arc.Arc(reset, actor_scale, input_bitwidth, actor_scale, input_bitwidth, complex_valued, size_factor) output_arc = Arc.Arc(reset, actor_scale, output_bitwidth, no_outputs, output_bitwidth, complex_valued, size_factor) clk = Signal(bool(False)) actor1 = Actor.Actor(clk, input_arc, actor1_actor2_arc, actor_scale) actor2 = Actor.Actor(clk, actor1_actor2_arc, output_arc, actor_scale) #Simulation #signal_trace = traceSignals(test_bench_actor,actor1,actor2,input_arc,actor1_actor2_arc,output_arc,no_inputs,input_bitwidth,no_outputs,output_bitwidth,complex_valued,test_data,clk) test_bench_actor_inst = test_bench_actor(actor1, actor2, input_arc, actor1_actor2_arc, output_arc, no_inputs, input_bitwidth, no_outputs, output_bitwidth, complex_valued, test_data, clk, verbose) simulation = Simulation(test_bench_actor_inst) simulation.run(100) if (conversion): verilog_inst = toVerilog(actor_conversion_testbench, clk, reset,
tf.reset_default_graph() options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) meta = tf.RunMetadata() config = tf.ConfigProto(log_device_placement=True, device_count={ "CPU": 10, "GPU": 1 }, inter_op_parallelism_threads=10) with Sess(options, meta, config=config) as sess: workers = [] for i in range(settings.NB_ACTORS): with tf.device("/device:CPU:" + str(i)): workers.append(Actor.Actor(sess, i + 1)) print("Initializing learner...") with tf.device("/device:GPU:0"): learner = Learner(sess, *workers[0].get_env_features()) print("Learner initialized !\n") if settings.LOAD: learner.load() threads = [] for i in range(settings.NB_ACTORS): thread = threading.Thread(target=workers[i].run) threads.append(thread) threads.append(threading.Thread(target=learner.run))
saver = tf.train.Saver() state_dim = utils.state_1d_dim_calc(env) actor_lr = 1e-3 critic_lr = 1e-3 tau = 5e-3 gamma = 0.99 sigma = 0.2 critic_reg_weight = 0.0 noise_type = "ou" assert noise_type in ["ou","gaussian"] with tf.Session(config=tf_config) as sess: #state_dim : 1d, action_spec : scalar actor = Actor.Actor(sess, state_dim, env.action_spec().shape[0], actor_lr, tau, batch_size) critic = Critic.Critic(sess, state_dim, env.action_spec().shape[0], critic_lr, tau, gamma, actor.get_num_trainable_vars(),critic_reg_weight) if noise_type == "gaussian": actor_noise = Noise.GaussianNoise(action_dim=env.action_spec().shape[0],sigma=sigma) elif noise_type == "ou": actor_noise = Noise.OrnsteinUhlenbeckActionNoise(mu=np.zeros([env.action_spec().shape[0]]), sigma=sigma) exp_detail = utils.experiment_detail_saver( domain_name, task_name, step_size, actor_lr, critic_lr, tau, gamma, sigma, batch_size, critic_reg_weight) print(exp_detail) utils.append_file_writer(video_dir, "experiment_detail.txt", "Critic origin type : "\
Level([ " ", " ", "PPPP ", "PPPP ", " PPPPPPP ", " ", " ", "PPPPPPPP PPP", "PPPPPPPPPPPPPPPPPPPPPP", "PPPPPPPPPPPPPPPPPPPPPP", "PPPPPPPPPPPPPPPPPPPPPP", ])) game.enemyList.append([ Actor(10 * 64, 3 * 64, "Enemy"), Actor(14 * 64, 3 * 63, "Enemy"), Actor(12 * 64, 7 * 64, "Enemy") ]) game.nameList.append("Watch out!") game.levelList.append( Level([ " ", " ", " PPPPPP", " PPPPPPPPP", " PPPPPPPPPP ", " PPPPPPP ", " ", "PPPPP PPPP",
def OpenLevelUpWindow(): """Sets up the level up window.""" import GUIREC global LevelUpWindow, TextAreaControl, NewProfPoints, actor global DoneButton global NewSkillPoints, KitName, LevelDiff global Level, Classes, NumClasses, DualSwap, IsMulti global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual LevelUpWindow = GemRB.LoadWindow(3) if GameCheck.IsBG2(): InfoButton = LevelUpWindow.GetControl(125) InfoButton.SetText(13707) InfoButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpInfoPress) DoneButton = LevelUpWindow.GetControl(0) DoneButton.SetText(11962) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpDonePress) DoneButton.SetState(IE_GUI_BUTTON_DISABLED) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) # hide "Character Generation" Label = LevelUpWindow.CreateLabel( 0x1000007e, 0, 0, 0, 0, "NUMBER", "", IE_FONT_ALIGN_CENTER | IE_FONT_SINGLE_LINE) # name pc = GemRB.GameGetSelectedPCSingle() actor = Actor.Actor(pc) Label = LevelUpWindow.GetControl(0x10000000 + 90) Label.SetText(GemRB.GetPlayerName(pc)) if GameCheck.IsBG1() or GameCheck.IsIWD1(): # armorclass Label = LevelUpWindow.GetControl(0x10000057) Label.SetText(str(GemRB.GetPlayerStat(pc, IE_ARMORCLASS))) Label.SetTooltip(17183) # hp now Label = LevelUpWindow.GetControl(0x10000058) Label.SetText(str(GemRB.GetPlayerStat(pc, IE_HITPOINTS))) Label.SetTooltip(17184) # hp max Label = LevelUpWindow.GetControl(0x10000059) Label.SetText(str(GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS))) Label.SetTooltip(17378) # some current values OldHPMax = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS, 1) OldThaco = GemRB.GetPlayerStat(pc, IE_TOHIT, 1) OldLore = GemRB.GetPlayerStat(pc, IE_LORE, 1) for i in range(5): OldSaves[i] = GemRB.GetPlayerStat(pc, IE_SAVEVSDEATH + i, 1) # class Label = LevelUpWindow.GetControl(0x10000000 + 106) Label.SetText(GUICommon.GetActorClassTitle(pc)) print "Title:", GUICommon.GetActorClassTitle( pc), "\tActor Title:", actor.ClassTitle() Class = GemRB.GetPlayerStat(pc, IE_CLASS) print "Class:", Class, "\tActor Class:", actor.classid SkillTable = GemRB.LoadTable("skills") # kit ClassName = GUICommon.GetClassRowName(Class, "class") Kit = GUICommon.GetKitIndex(pc) print "Kit:", Kit, "\tActor Kit:", actor.KitIndex() print "ClassName:", ClassName, "\tActor ClassNames:", actor.ClassNames() # need this for checking gnomes RaceName = GemRB.GetPlayerStat(pc, IE_RACE, 1) RaceName = CommonTables.Races.FindValue(3, RaceName) RaceName = CommonTables.Races.GetRowName(RaceName) # figure our our proficiency table and index if Kit == 0: KitName = ClassName else: #rowname is just a number, the kitname is the first data column KitName = CommonTables.KitList.GetValue(Kit, 0) # our multiclass variables IsMulti = GUICommon.IsMultiClassed(pc, 1) Classes = [IsMulti[1], IsMulti[2], IsMulti[3]] NumClasses = IsMulti[0] # 2 or 3 if IsMulti; 0 otherwise IsMulti = NumClasses > 1 IsDual = 0 DualSwap = 0 # not multi, check dual if not IsMulti: # check if we're dual classed IsDual = GUICommon.IsDualClassed(pc, 1) Classes = [IsDual[2], IsDual[1]] # make sure the new class is first # either dual or single only care about 1 class NumClasses = 1 # not dual, must be single if IsDual[0] == 0: Classes = [Class] else: # make sure Classes[1] is a class, not a kit if IsDual[0] == 1: # kit Classes[1] = CommonTables.KitList.GetValue(IsDual[1], 7) else: # class TmpClassName = GUICommon.GetClassRowName(Classes[1], "index") Classes[1] = CommonTables.Classes.GetValue(TmpClassName, "ID") # store a boolean for IsDual IsDual = IsDual[0] > 0 print "NumClasses:", NumClasses, "\tActor NumClasses:", actor.NumClasses() Level = [0] * 3 LevelDiff = [0] * 3 # reorganize the leves if we're dc so the one we want to use is in Level[0] # and the old one is in Level[1] (used to regain old class abilities) if IsDual: # convert the classes from indicies to class id's DualSwap = GUICommon.IsDualSwap(pc) ClassName = GUICommon.GetClassRowName(Classes[0], "index") KitName = ClassName # for simplicity throughout the code Classes[0] = CommonTables.Classes.GetValue(ClassName, "ID") # Class[1] is taken care of above # we need the old level as well if DualSwap: Level[1] = GemRB.GetPlayerStat(pc, IE_LEVEL) else: Level[1] = GemRB.GetPlayerStat(pc, IE_LEVEL2) print "Classes:", Classes, "\tActor Classes:", actor.Classes() print "IsDual:", IsDual > 0, "\tActor IsDual", actor.isdual hp = 0 HaveCleric = 0 # clear some globals, since we may get called multiple times with different classes DeltaWSpells = 0 DeltaDSpells = 0 OldDSpells = [0] * 7 OldWSpells = [0] * 9 NewDSpells = [0] * 7 NewWSpells = [0] * 9 # get a bunch of different things each level for i in range(NumClasses): # print "Class:",Classes[i] # we don't care about the current level, but about the to-be-achieved one # get the next level Level[i] = LUCommon.GetNextLevelFromExp( GemRB.GetPlayerStat(pc, IE_XP) / NumClasses, Classes[i]) TmpClassName = GUICommon.GetClassRowName(Classes[i], "class") # find the level diff for each classes (3 max, obviously) if i == 0: if DualSwap: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL2) else: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL) elif i == 1: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL2) elif i == 2: LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL3) # print "Level (",i,"):",Level[i] # print "Level Diff (",i,"):",LevelDiff[i] # save our current and next spell amounts StartLevel = Level[i] - LevelDiff[i] DruidTable = CommonTables.ClassSkills.GetValue(TmpClassName, "DRUIDSPELL", GTV_STR) ClericTable = CommonTables.ClassSkills.GetValue( TmpClassName, "CLERICSPELL", GTV_STR) MageTable = CommonTables.ClassSkills.GetValue(TmpClassName, "MAGESPELL", GTV_STR) # see if we have mage spells if MageTable != "*": # we get 1 extra spell per level if we're a specialist Specialist = 0 if CommonTables.KitList.GetValue( Kit, 7) == 1: # see if we're a kitted mage Specialist = 1 if Spellbook.HasSorcererBook(pc, Classes[i]): MageTable = "SPLSRCKN" MageTable = GemRB.LoadTable(MageTable) # loop through each spell level and save the amount possible to cast (current) for j in range(MageTable.GetColumnCount()): NewWSpells[j] = MageTable.GetValue(str(Level[i]), str(j + 1), GTV_INT) OldWSpells[j] = MageTable.GetValue(str(StartLevel), str(j + 1), GTV_INT) if NewWSpells[ j] > 0: # don't want specialist to get 1 in levels they should have 0 NewWSpells[j] += Specialist if OldWSpells[j] > 0: OldWSpells[j] += Specialist DeltaWSpells = sum(NewWSpells) - sum(OldWSpells) elif ClericTable != "*": # check for cleric spells if not GemRB.HasResource(ClericTable, RES_2DA, 1): ClericTable = "MXSPLPRS" # iwd1 doesn't have a DRUIDSPELL column in the table ClericTable = GemRB.LoadTable(ClericTable) HaveCleric = 1 # same as above for j in range(ClericTable.GetColumnCount()): NewDSpells[j] = ClericTable.GetValue(str(Level[i]), str(j + 1), GTV_INT) OldDSpells[j] = ClericTable.GetValue(str(StartLevel), str(j + 1), GTV_INT) DeltaDSpells = sum(NewDSpells) - sum(OldDSpells) elif DruidTable != "*": # clerics have precedence in multis (ranger/cleric) if HaveCleric == 0: #use MXSPLPRS if we can't find the resource (SoA fix) if not GemRB.HasResource(DruidTable, RES_2DA): DruidTable = "MXSPLPRS" # check druid spells DruidTable = GemRB.LoadTable(DruidTable) # same as above for j in range(DruidTable.GetColumnCount()): NewDSpells[j] = DruidTable.GetValue( str(Level[i]), str(j + 1), GTV_INT) OldDSpells[j] = DruidTable.GetValue( str(StartLevel), str(j + 1), GTV_INT) DeltaDSpells = sum(NewDSpells) - sum(OldDSpells) # this is handled by core # # setup class bonuses for this class # if IsMulti or IsDual or Kit == 0: # ABTable = CommonTables.ClassSkills.GetValue (TmpClassName, "ABILITIES") # else: # single-classed with a kit # ABTable = CommonTables.KitList.GetValue (str(Kit), "ABILITIES") # # # add the abilites if we have a table to ref # if ABTable != "*" and GemRB.HasResource (ABTable, RES_2DA, 1): # GUICommon.AddClassAbilities (pc, ABTable, Level[i], LevelDiff[i]) print "Actor CurrentLevels:", actor.Levels() print "Levels:", Level, "Actor NextLevels:", actor.NextLevels() print "LevelDiffs:", LevelDiff, "Actor LevelDiffs:", actor.LevelDiffs() #update our saves, thaco, hp and lore LUCommon.SetupSavingThrows(pc, Level) LUCommon.SetupThaco(pc, Level) LUCommon.SetupLore(pc, LevelDiff) LUCommon.SetupHP(pc, Level, LevelDiff) # use total levels for HLAs HLACount = 0 if GameCheck.HasTOB(): # make sure SoA doesn't try to get it HLATable = GemRB.LoadTable("lunumab") # we need to check each level against a multi value (this is kinda screwy) if actor.multiclass: print "Actor HLA Names:",["MULTI"+str(actor.NumClasses())+name \ for name in actor.ClassNames()] else: print "Actor HLA Names:", actor.ClassNames() for i in range(NumClasses): if IsMulti: # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF MultiName = GUICommon.GetClassRowName(Classes[i], "class") MultiName = "MULTI" + str(NumClasses) + MultiName else: MultiName = ClassName # if we can't learn for this class, we can't learn at all FirstLevel = HLATable.GetValue(MultiName, "FIRST_LEVEL", GTV_INT) if Level[i] < FirstLevel: HLACount = 0 break if (Level[i] - LevelDiff[i]) < FirstLevel: # count only from FirstLevel up HLACount += (Level[i] - FirstLevel + 1) else: HLACount += LevelDiff[i] # set values required by the hla level up code HLACount = HLACount / HLATable.GetValue(ClassName, "RATE", GTV_INT) GemRB.SetVar("HLACount", HLACount) if GameCheck.IsBG2(): HLAButton = LevelUpWindow.GetControl(126) if HLACount: HLAButton.SetText(4954) HLAButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpHLAPress) else: HLAButton.SetFlags(IE_GUI_BUTTON_DISABLED, OP_OR) # setup our profs Level1 = [] for i in range(len(Level)): Level1.append(Level[i] - LevelDiff[i]) if GameCheck.IsBG2(): LUProfsSelection.SetupProfsWindow( pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUProfsSelection.SetupProfsWindow( pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False, 0) NewProfPoints = GemRB.GetVar("ProfsPointsLeft") #we autohide the skills and let SetupSkillsWindow show them if needbe for i in range(4): HideSkills(i) if GameCheck.IsBG2(): LUSkillsSelection.SetupSkillsWindow( pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level) else: LUSkillsSelection.SetupSkillsWindow( pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow, RedrawSkills, Level1, Level, 0, False) NewSkillPoints = GemRB.GetVar("SkillPointsLeft") if GameCheck.IsBG2(): TextAreaControl = LevelUpWindow.GetControl(110) TextAreaControl.SetText(GetLevelUpNews()) else: TextAreaControl = LevelUpWindow.GetControl(42) TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff)) RedrawSkills() GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND) LevelUpWindow.ShowModal(MODAL_SHADOW_GRAY) # if we have a sorcerer who can learn spells, we need to do spell selection for c in range(len(Classes)): if Spellbook.HasSorcererBook(pc, Classes[c]) and DeltaWSpells > 0: LUSpellSelection.OpenSpellsWindow(pc, "SPLSRCKN", Level[c], LevelDiff[c])
tau = 1e-3 gamma = 0.99 sigma = 0.2 critic_reg_weight = 0.0 noise_type = "ou" action_dim = env.action_spec().shape[0] * num_of_action actor_type = "rnn" assert noise_type in ["ou", "gaussian"] assert actor_type in ["rnn", "basic"] with tf.Session(config=tf_config) as sess: #state_dim : 1d, action_spec : scalar if actor_type == "basic": actor = Actor.Actor(sess, state_dim, action_dim, actor_lr, tau, batch_size) elif actor_type == "rnn": actor = RNNActor.Actor(sess, state_dim, action_dim, actor_lr, tau, batch_size, num_of_action) critic = Critic.Critic(sess, state_dim, action_dim, critic_lr, tau, gamma, actor.get_num_trainable_vars(), critic_reg_weight) if noise_type == "gaussian": actor_noise = Noise.GaussianNoise(action_dim=action_dim, sigma=sigma) elif noise_type == "ou": actor_noise = Noise.OrnsteinUhlenbeckActionNoise(mu=np.zeros( [int(action_dim / num_of_action)]), sigma=sigma)
msg += "#" t_conn.sendall(bytes(msg, "utf8")) except Exception as e: print("[ERROR] " + str(e)) t_conn.close() for actor_name in actors: actor_info = actors_list[actor_name] actor_ip = actor_info["ip"] actor_port = actor_info["port"] if "state_names" in actor_info: actors[actor_name] = Actor.Actor(actor_ip, actor_port, actor_info["state_count"], actor_name, actor_info["state_names"]) else: actors[actor_name] = Actor.Actor(actor_ip, actor_port, actor_name, actor_info["state_count"]) # CONNECT TO ACTORS pre = "[SERVER] " for actor in actors: now = datetime.datetime.now() try: actors[actor].connect() c_t = "[" + str(now.day) + "." + str(now.month) + "." + str(now.year) + ", " \ + str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) + "]" print(c_t, pre, actor, "connected") except Exception:
def client_thread(t_conn): pre_client = "[" + str(t_conn.getpeername()[0]) + ":" + str( t_conn.getpeername()[1]) + "] " while True: # noinspection PyBroadException try: data = t_conn.recv(Constants.REQUEST_LENGTH) if not data: break now = datetime.datetime.now() c_msg = str(data, "utf8") c_t3 = "[" + str(now.day) + "." + str(now.month) + "." + str(now.year) + ", " \ + str(now.hour) + ":" + str(now.minute) + ":" + str(now.second) + "] " pre_c = c_t3 + pre_client while (len(pre_c)) < 47: pre_c += " " # UI_CLIENT_DATA_REQUEST if c_msg == Constants.UI_CLIENT_DATA_REQUEST: if log_data_requests: print(pre_c, "Received UI_CLIENT_DATA_REQUEST") msg = get_info() while len(bytes(msg, "utf8")) < Constants.SERVER_ANSWER_LENGTH: msg += "#" t_conn.sendall(bytes(msg, "utf8")) # UI_CLIENT_SENSOR_DATA_REQUEST if c_msg == Constants.UI_CLIENT_SENSOR_DATA_REQUEST: # TODO Send Sensor-Data requested by external rpi-Server pass # UI_CLIENT_COMMAND_IDENTIFIER if Constants.UI_CLIENT_COMMAND_IDENTIFIER in c_msg: c_msg = c_msg.replace("#", "") print(pre_c, "Received UI_CLIENT_COMMAND:", c_msg) c_parts = c_msg.split("_") c_cmd_name = c_parts[1] c_cmd_n_state = c_parts[2] actors[c_cmd_name].switch_to(int(c_cmd_n_state)) msg = get_info() while len(bytes(msg, "utf8")) < Constants.SERVER_ANSWER_LENGTH: msg += "#" t_conn.sendall(bytes(msg, "utf8")) # UI_CLIENT_ADD_DEVICE_IDENTIFIER if Constants.UI_CLIENT_ADD_DEVICE_IDENTIFIER in c_msg: c_msg = c_msg.replace("#", "") print(pre_c, "Received UI_CLIENT_ADD_DEVICE:", c_msg) c_parts = c_msg.split("_") n_name = c_parts[1] n_ip = c_parts[2] n_port = int(c_parts[3]) n_states = int(c_parts[4]) if n_name not in actors: if len(c_parts) == 5 + n_states: n_state_names = c_parts[5:len(c_parts)] actors[n_name] = Actor.Actor(n_ip, n_port, n_states, n_name, n_state_names) else: n_state_names = None actors[n_name] = Actor.Actor(n_ip, n_port, n_states, n_name) try: actors[n_name].connect() file = open(actors_file_name, 'r') all_text = "" line = file.readline() while line: all_text += line line = file.readline() file.close() all_text = all_text[0:len(all_text) - 2] all_text += ",\n" all_text += " \"" + n_name + "\": {\n" all_text += " \"ip\": \"" + n_ip + "\",\n" all_text += " \"port\": " + str(n_port) + ",\n" all_text += " \"state_count\": " + str( n_states) + ",\n" if n_state_names is not None: all_text += " \"state_names\": [" for name in n_state_names: all_text += "\"" + name + "\", " all_text = all_text[0:len(all_text) - 2] if n_state_names: all_text += "]\n" all_text += " }\n" all_text += "}" file = open(actors_file_name, "w") file.write(all_text) file.close() except: print("Actor not found.") del actors[n_name] msg = get_info() while len(bytes(msg, "utf8")) < Constants.SERVER_ANSWER_LENGTH: msg += "#" t_conn.sendall(bytes(msg, "utf8")) except Exception as e: print("[ERROR] " + str(e)) t_conn.close()
# File: I (Python 2.2) global startTime from PandaModules import * from ShowBaseGlobal import * from IntervalGlobal import * from Actor import * import Mopath boat = loader.loadModel('models/misc/smiley') boat.reparentTo(render) donald = Actor() donald.loadModel('phase_6/models/char/donald-wheel-1000') donald.loadAnims({ 'steer': 'phase_6/models/char/donald-wheel-wheel' }) donald.reparentTo(boat) dock = loader.loadModel('models/misc/smiley') dock.reparentTo(render) sound = loader.loadSfx('phase_6/audio/sfx/SZ_DD_waterlap.mp3') foghorn = loader.loadSfx('phase_6/audio/sfx/SZ_DD_foghorn.mp3') mp = Mopath.Mopath() mp.loadFile(Filename('phase_6/paths/dd-e-w')) boatMopath = MopathInterval(mp, boat, 'boatpath') boatTrack = Track([ boatMopath], 'boattrack') BOAT_START = boatTrack.getIntervalStartTime('boatpath') BOAT_END = boatTrack.getIntervalEndTime('boatpath') donaldSteerInterval = ActorInterval(donald, 'steer') donaldLoopInterval = ActorInterval(donald, 'steer', loop = 1, duration = 10.0) donaldSteerTrack = Track([ donaldSteerInterval, donaldLoopInterval], name = 'steerTrack')
# inicializuj prostredie Weights & Biases wandb.init(project="stable-baselines") wandb.config.gamma = 0.99 wandb.config.batch_size = 100 wandb.config.tau = 0.005 wandb.config.lr_A=0.0001 wandb.config.lr_C=0.001 wandb.config.learning_start = 100 # Herne prostredie env = gym.make('MountainCarContinuous-v0') # Actor actorNet = Actor.Actor(env.observation_space.shape, env.action_space.shape, lr=wandb.config.lr_A) actorNet_target = Actor.Actor(env.observation_space.shape, env.action_space.shape, lr=wandb.config.lr_A) # Critic criticNet = Critic.Critic(env.observation_space.shape, env.action_space.shape, lr=wandb.config.lr_C) criticNet_target = Critic.Critic(env.observation_space.shape, env.action_space.shape, lr=wandb.config.lr_C) # replay buffer rpm = ReplayBuffer.ReplayBuffer(1000000) # 1M history noise = OrnsteinUhlenbeckActionNoise(mean=0.0, sigma=0.5, size=env.action_space.shape) # (gradually) replace target network weights with online network weights def replace_weights(tau=wandb.config.tau): theta_a,theta_c = actorNet.model.get_weights(),criticNet.model.get_weights() theta_a_targ,theta_c_targ = actorNet_target.model.get_weights(),criticNet_target.model.get_weights()