def _preprocess_json(js, opt): t = STree(js['tgt']) js['lay'] = t.layout(opt.dataset, add_skip=False) js['lay_skip'] = t.layout(opt.dataset, add_skip=True) assert len(str(t).split(' ')) == len(js['lay_skip']), (list( zip(str(t).split(' '), js['lay_skip'])), ' '.join(js['tgt'])) js['tgt'] = str(t).split(' ')
def data_aug_by_permute_order(js_list, permute_order_times, opt): r_list = [] for js in js_list: st = STree(js['tgt']) p_list = [str(st)] for __ in range(permute_order_times): p_list.append(str(st.permute(not_layout=True))) p_set = set(p_list) for p in p_set: r_list.append({'src': js['src'], 'tgt': p.split(' ')}) for js in r_list: _preprocess_json(js, opt) return r_list
def main(): random.seed(1) world = SWorld().channel SDisplayWindow(world) home = SHome(world, location=(250, 400), instanceName='Home') STree(world, 'WOOD', location=(150, 150), instanceName='FarawayTree', hitpoints=1) SWoodcutter(world, location=(200, 400), homeLocation=home.location, velocity=50, instanceName='Woodcutter', stamina=100, maxStamina=100) try: #actor.printAllActorChannelBalances() world.send((None, 'START_TICK_TASKLET')) r = stackless.run() print 'stackless.run() result =', r except KeyboardInterrupt: print "Exit" print "End of Program"
def main(): random.seed(1) totalWood = 0 world = SWorld().channel SDisplayWindow(world) homeList = [] gatheringList = ["WOOD"] for i in range(1): homeList.append( SHome(world, location=getRandomLoc(), instanceName="Home #%d" % (i + 1))) #homeList.append(SHome(world, location=(250,400), instanceName="Home #%d" % (i + 1))) for i in range(20): gatheringName = random.choice(gatheringList) STree(world, gatheringName, location=getRandomLoc(), instanceName="Tree #%d [%s]" % (i + 1, gatheringName), hitpoints=10) for i in range(20): SWoodcutter(world, location=getRandomLoc(), homeLocation=random.choice(homeList).location, velocity=50 + (random.random() - 0.5) * 3, instanceName="Woodcutter #%d" % (i + 1)) homeLoc = random.choice(homeList).location SArchitect(world, location=homeLoc, homeLocation=homeLoc, velocity=50 + (random.random() - 0.5) * 3, instanceName="Architect") try: actor.printAllActorChannelBalances() r = stackless.run() print 'stackless.run() result =', r except KeyboardInterrupt: print "Exit" print "End of Program", totalWood actor.printAllActorChannelBalances()
def main(): js_list = table.IO.read_anno_json(opt.train_anno, opt) bpe_list = learn_bpe([STree(js['lay']) for js in js_list], opt.bpe_num_merge, opt.bpe_min_freq) bpe_processor = BpeProcessor(bpe_list, True) print('Preparing training ...') fields = table.IO.TableDataset.get_fields() print("Building Training...") train = table.IO.TableDataset(opt.train_anno, fields, bpe_processor, opt.permute_order, opt, True) if Path(opt.valid_anno).exists(): print("Building Valid...") valid = table.IO.TableDataset(opt.valid_anno, fields, bpe_processor, 0, opt, True) else: valid = None if Path(opt.test_anno).exists(): print("Building Test...") test = table.IO.TableDataset(opt.test_anno, fields, bpe_processor, 0, opt, False) else: test = None print("Building Vocab...") table.IO.TableDataset.build_vocab(train, valid, test, opt) print("Saving train/valid/fields") # Can't save fields, so remove/reconstruct at training time. torch.save(table.IO.TableDataset.save_vocab(fields), open(os.path.join(opt.save_data, 'vocab.pt'), 'wb')) torch.save(bpe_processor, open(os.path.join(opt.save_data, 'bpe.pt'), 'wb')) train.fields = [] torch.save(train, open(os.path.join(opt.save_data, 'train.pt'), 'wb')) if Path(opt.valid_anno).exists(): valid.fields = [] torch.save(valid, open(os.path.join(opt.save_data, 'valid.pt'), 'wb')) if Path(opt.test_anno).exists(): test.fields = [] torch.save(test, open(os.path.join(opt.save_data, 'test.pt'), 'wb'))
def testOneWoodcutterAndOneWood(self): ''' logging.getLogger().setLevel(logging.DEBUG) logging.debug('Debug level logging enabled.') ''' random.seed(1) world = SWorld(exitOnNoHarvestables=True).channel home = SHome(world, location=(32 * 5, 32 * 5), instanceName='WoodcutterHome') SWoodcutter(world, location=(32 * 3 + 16, 32 * 3 + 16), homeLocation=home.location, velocity=4, instanceName='Woodcutter', roamingRadius=200, stamina=10000, maxStamina=10000, intention='PATHFINDING_HARVESTABLE') tree = STree(world, 'WOOD', location=(32 * 4, 32 * 3), instanceName='Tree', hitpoints=1) world.send((None, 'START_TICK_TASKLET')) r = stackless.run() logging.info('End of Program, stackless.run() result = %s' % r) self.assertEqual(0, tree.hitpoints) self.assertEqual('DEPLETED', tree.deathReason)
def main(): random.seed(1) logging.getLogger().setLevel(logging.INFO) worldSizeX = 15 worldSizeY = 15 worldActor = SWorld(width=worldSizeX, height=worldSizeY, disableCollisionCheck=True, useTestData=True) world = worldActor.channel # # Initially joining actors # #STree(world, 'WOOD', location=(32*5+16,32*5+16), instanceName='TestTree') STree(world, 'WOOD', location=(32 * 5 + 16, 32 * 15 + 16), instanceName='Tree', hitpoints=3, hitpointsDecay=0) STree(world, 'WOOD', location=(32 * 11 + 16, 32 * 7 + 16), instanceName='FarawayTree', hitpoints=4, hitpointsDecay=0) STree(world, 'WOOD', location=(32 * 15 + 16, 32 * 8 + 16), instanceName='VFTree', hitpoints=15, hitpointsDecay=0) STree(world, 'WOOD', location=(32 * 6 + 16, 32 * 5 + 16), instanceName='HiddenTree', hitpoints=7, hitpointsDecay=0) home = SHome(world, location=(32 * 10 + 16, 32 * 13 + 16), instanceName='WoodcutterHome').channel SWoodcutter(world, location=(32 * 0 + 16, 32 * 16 + 16), velocity=20, home=home, instanceName='Woodcutter', roamingRadius=200, stamina=10, maxStamina=1000, intention='PATHFINDING_HARVESTABLE', display=None) for i in range(10): SPrey(world, location=getRandomActorTile(0, 0, 1, 1), velocity=20, angle=getRandomAngle(), instanceName='Prey%d' % i, stamina=100, maxStamina=100, roamingVelocity=random.randrange(25, 35), intention='ROAMING') # # Sight # ''' sightX, sightY = 14, 14 sight = SSight(world, location=(32 * sightX, 32 * sightY), instanceName='TestSight', sightRange=7).channel''' you = SPrey(world, location=getRandomActorTile(19, 6, 20, 7), velocity=20, angle=getRandomAngle(), instanceName='YOU', stamina=100, maxStamina=100, roamingVelocity=random.randrange(25, 35), intention='SYNCING').channel # # 막촌 보좌관 # SPrey(world, location=getRandomActorTile(19, 5, 20, 6), velocity=20, angle=180, instanceName='HeadmanAssistant', stamina=100, maxStamina=100, roamingVelocity=random.randrange(25, 35), intention='SYNCING', conversation=dialog.HeadmanAssistant()) # # 평범한 막촌 주민 # SPrey(world, location=getRandomActorTile(19, 2, 20, 3), velocity=20, angle=180, instanceName='Villager', stamina=100, maxStamina=100, roamingVelocity=random.randrange(25, 35), intention='SYNCING', conversation=dialog.Villager()) # # Display # SDisplayWindow(world, windowTitle='Falling Sun Server', swidth=32 * 23, sheight=32 * 15, client=you, sightedActorsOnly=False) # # Servers # SServer(world, 'Server') SWebSocketServer(world, 'WebSocketServer') logging.info('All actors initialized successfully.') logging.info('Starting the tick tasklet...') try: world.send((None, 'START_TICK_TASKLET')) r = stackless.run() assert r is None except KeyboardInterrupt: logging.info('Exit by KeyboardInterrupt') logging.info('End of Program')
def main(): random.seed(1) logging.getLogger().setLevel(logging.INFO) # logging.debug('Debug level logging enabled.') # world = SWorld(disableCollisionCheck=True).channel world = SWorld(useTestData=True).channel display = SDisplayWindow(world, swidth=32 * 23, sheight=32 * 23).channel ''' for i in range(10): SPrey(world, location=(32*11+16,32*8+16), velocity=10, angle=90, instanceName='PreyI #%d' % (i+1), stamina=100, maxStamina=100, intention='RESTING') for i in range(10): SPrey(world, location=(32*5+16,32*5+16), velocity=5, angle=90, instanceName='Prey II #%d' % (i+1), stamina=100, maxStamina=100, intention='RESTING') ''' SPrey(world, location=(32 * 5 + 16, 32 * 5 + 16), velocity=50, angle=90, instanceName='Prey', stamina=100, maxStamina=100, intention='ROAMING') STree(world, 'WOOD', location=(32 * 5, 32 * 15), instanceName='Tree', hitpoints=3, hitpointsDecay=0) STree(world, 'WOOD', location=(32 * 11, 32 * 7), instanceName='FarawayTree', hitpoints=4, hitpointsDecay=0) STree(world, 'WOOD', location=(32 * 15, 32 * 8), instanceName='VFTree', hitpoints=15, hitpointsDecay=0) STree(world, 'WOOD', location=(32 * 6, 32 * 5), instanceName='HiddenTree', hitpoints=7, hitpointsDecay=0) home = SHome(world, location=(32 * 10, 32 * 13), instanceName='WoodcutterHome') home2 = SHome(world, location=(32 * 16, 32 * 17), instanceName='Wc2Home') SWoodcutter(world, location=(32 * 0 + 16, 32 * 16 + 16), homeLocation=home.location, velocity=20, home=home.channel, instanceName='Woodcutter', roamingRadius=200, stamina=10, maxStamina=1000, intention='PATHFINDING_HARVESTABLE', display=display) SWoodcutter(world, location=(32 * 0 + 16, 32 * 2 + 16), homeLocation=home2.location, velocity=20, home=home2.channel, instanceName='Wc2', roamingRadius=200, stamina=10, maxStamina=1000, intention='PATHFINDING_HARVESTABLE', display=display) SWoodcutter(world, location=(32 * 16 + 16, 32 * 18 + 16), homeLocation=home2.location, velocity=20, home=home2.channel, instanceName='Wc3-rest', roamingRadius=200, stamina=6, maxStamina=10, intention='RESTING', display=display) logging.info('All actors initialized successfully.') logging.info('Starting the tick tasklet...') try: world.send((None, 'START_TICK_TASKLET')) r = stackless.run() assert r is None except KeyboardInterrupt: logging.info('Exit by KeyboardInterrupt') logging.info('End of Program')
def spawnTree(self): if random.randrange(0, 10000) < 1: STree(self.channel, "WOOD", (random.randrange(50, 450), random.randrange(50, 450)), instanceName="SpawnedTree")
def _lay_bpe(line): t = STree(line['lay']) self.bpe_processor.process(t) r = t.to_list(shorten=True) return r