def __init__(self, config): self.speed_noise_level = config['speed_noise'] self.altitude_noise_level = config['altitude_noise'] self.sy_min = config['sy_min'] self.sy_max = config['sy_max'] self.last_sy = 0.0 World.__init__(self, config)
def __init__(self): self.world = World() self.exception_text = [] self.log_text = [] self.client_player = {} self.red_client = None self.blue_client = None self.player_debug = {}
def __init__(self, config, drone=None): World.__init__(self, config) self.last_sy = 0.0 self.sy_min = config['sy_min'] self.sy_max = config['sy_max'] self.last_y = 0.0 self.drone = drone
def __init__(self, dt=0.01, state=None, params=None): if not state: state = { 'y': 0., 'dy': 0., 'ydot': 0., } World.__init__(self, dt, state, params)
def build(file="core/config/lifeGame.txt"): """""" global w cm = ConfigManager(file) cm.setUpConfig() cm.load() w = World(cm) print(w) print(w.__repr__())
def one_image(label_interest=5): images, labels = load_mnist.load_images(images_number=100) world = World() poppy = Agent() image_interest = images[labels == label_interest][0] world.add_image(image_interest) poppy.cortex.reset_activations() poppy.cortex.display = True while True: poppy.sense_data(world) poppy.cortex.associate(label=label_interest)
def commandCreate(self, parts, byuser, overriderank): "/create worldname width height length - Admin\nCreates a new world with specified dimensions." if len(parts) == 1: self.client.sendServerMessage("Please specify a world name.") elif self.client.factory.world_exists(parts[1]): self.client.sendServerMessage("Worldname in use") elif len(parts) < 5: self.client.sendServerMessage("Please specify dimensions. (width, length, height)") elif int(parts[2]) < 16 or int(parts[3]) < 16 or int(parts[4]) < 16: self.client.sendServerMessage("No dimension may be smaller than 16.") elif int(parts[2]) > 1024 or int(parts[3]) > 1024 or int(parts[4]) > 1024: self.client.sendServerMessage("No dimension may be greater than 1024.") elif (int(parts[2]) % 16) > 0 or (int(parts[3]) % 16) > 0 or (int(parts[4]) % 16) > 0: self.client.sendServerMessage("All dimensions must be divisible by 16.") else: world_id = parts[1].lower() sx, sy, sz = int(parts[2]), int(parts[3]), int(parts[4]) grass_to = (sy // 2) world = World.create( "worlds/%s" % world_id, sx, sy, sz, # Size sx//2,grass_to+2, sz//2, 0, # Spawn ([BLOCK_DIRT]*(grass_to-1) + [BLOCK_GRASS] + [BLOCK_AIR]*(sy-grass_to)) # Levels ) self.client.factory.loadWorld("worlds/%s" % world_id, world_id) self.client.factory.worlds[world_id].all_write = False self.client.sendServerMessage("World '%s' made and booted." % world_id)
def __init__(self, dt=0.01, state=None, params=None, rollover=True): if not params: params = {'m': .25, 'k': 1.1, 'l': 1.} if not state: state = { 'x': 0., 'xdot': 0., 'xdotdot': 0., 'theta_int': 0., 'theta': 0., 'thetadot': 0., 'thetadotdot': 0. } World.__init__(self, dt, state, params) self.rollover = rollover
def learn_pairs(label_interest=5, n_jumps_test=50): """ :param label_interest: MNIST label of interest :param n_jumps_test: how many test saccades to be made for one image; as we increase `n_jumps_test`, we expect overlap with L23 train history to decrease in time, since during the training we observe only the most significant features in an image. Ideally, we'd like the overlap not to decrease much in time. """ images, labels = load_mnist.load_images(images_number=100) world = World() poppy = Agent() images_interest = images[labels == label_interest] for image in images_interest: world.add_image(image) poppy.cortex.reset_activations() l23_train = poppy.learn_pairs(world, label_interest) world.reset() if n_jumps_test == 0: l23_test = poppy.learn_pairs(world, label=label_interest) else: l23_test = [] poppy.sense_data(world) for saccade in range(n_jumps_test): poppy.sense_data(world) l23_test.append(poppy.cortex.V1.layers['L23'].cells.copy()) l23_test = np.vstack(l23_test) overlap = np.dot(l23_train, l23_test.T) overlap = (overlap * 255 / poppy.cortex.V1.layers['L23'].n_active).astype(np.uint8) cv2.imshow('overlap', overlap) cv2_step()
def __init__(self, dt=0.01, state=None, params=None, rollover=True): if not params: params = { 'm': .25, 'k': 1.1, 'l': 1. } if not state: state = { 'x': 0., 'xdot': 0., 'xdotdot': 0., 'theta_int': 0., 'theta': 0., 'thetadot': 0., 'thetadotdot': 0. } World.__init__(self, dt, state, params) self.rollover = rollover
def build(self): with open('scenarios/rise_of_bavaria/setup.json') as f: setup = ujson.load(f) actor = Visual(name='observer') ai1 = AI(name='testai1') # ai2 = AI(name='testai2', entity_id=list(setup['entities'].keys())[1]) setup.update({ 'actors': [ actor, ai1, # ai2 ], 'actor_to_entity_mapping': { actor.name: list(setup['entities'].keys())[0], ai1.name: list(setup['entities'].keys())[1] }, 'seed': 555 }) world = World(setup) view = actor.view t = Thread(target=world.run) t.start() return view
class API(object): def __init__(self): self.world = World() self.exception_text = [] self.log_text = [] self.client_player = {} self.red_client = None self.blue_client = None self.player_debug = {} def get_world_state_for(self, client): return self.world.get_state_for(self.client_player[client]) def create_players(self, red_client, blue_client): self.red_client = red_client self.blue_client = blue_client self.client_player = { red_client: settings.PLAYERS['FIRST_PLAYER_KEY'], blue_client: settings.PLAYERS['SECOND_PLAYER_KEY'] } self.player_debug = { settings.PLAYERS['FIRST_PLAYER_KEY']: { 'exceptions': [], 'logs': [], 'fatal_error': [], }, settings.PLAYERS['SECOND_PLAYER_KEY']: { 'exceptions': [], 'logs': [], 'fatal_error': [], } } def clear_client_debug(self): self.player_debug = { k: { 'exceptions': [], 'logs': [], 'fatal_error': [] } for k, _ in self.player_debug.iteritems() } def apply_commands(self, commands, client): player = self.client_player.get(client) for command in commands: command_name = command.get("command") args = command.get("args") if command_name: method_to_call = getattr(self, command_name, None) if method_to_call is None: continue try: method_to_call(player=player, **args) except TypeError: pass def tick(self): self.world.tick() def get_visio_state(self): world_state = self.world.get_visio_state() world_state.update( {'debug': {k: v for k, v in self.player_debug.iteritems()}}) self.clear_client_debug() return world_state def get_state(self): return self.world.get_state() def get_score_state(self): return self.world.get_score_state() def go_to_floor(self, player, floor, elevator_id): elevator = filter(lambda x: x.id == elevator_id, self.world.get_elevator_for(player)) if not elevator: return elevator = elevator[0] if isinstance(floor, int): elevator.go_to_floor(floor) def set_elevator_to_passenger(self, player, passenger_id, elevator_id): elevator = filter(lambda x: x.id == elevator_id, self.world.get_elevator_for(player)) passenger = filter(lambda x: x.id == passenger_id, self.world.get_passengers()) if not passenger: return passenger = passenger[0] if not elevator: return elevator = elevator[0] self.world.building.set_passenger_elevator(passenger, elevator) def exception(self, player, text): if len(self.player_debug[player]['exceptions']) < 10000: self.player_debug[player]['exceptions'].append(text[:100]) def log(self, player, text): if len(self.player_debug[player]['logs']) < 10000: self.player_debug[player]['logs'].append(text[:100]) def fatal_error(self, player, text): if len(self.player_debug[player]['fatal_error']) < 10000: self.player_debug[player]['fatal_error'].append(text[:100])
def __init__(self): self.ServerVars = dict() self.specs = ConfigParser() self.last_heartbeat = time.time() self.lastseen = ConfigParser() self.config = ConfigParser() self.options_config = ConfigParser() self.ploptions_config = ConfigParser() self.wordfilter = ConfigParser() self.save_count = 1 try: self.config.read("config/main.conf") except: logging.log(logging.ERROR, "Something is messed up with your main.conf file. (Did you edit it in Notepad?)") sys.exit(1) try: self.options_config.read("config/options.conf") except: logging.log(logging.ERROR, "Something is messed up with your options.conf file. (Did you edit it in Notepad?)") sys.exit(1) try: self.ploptions_config.read("config/ploptions.conf") except: logging.log(logging.ERROR, "Something is messed up with your ploptions.conf file. (Did you edit it in Notepad?)") sys.exit(1) self.use_irc = False if (os.path.exists("config/irc.conf")): self.use_irc = True self.irc_config = ConfigParser() try: self.irc_config.read("config/irc.conf") except: logging.log(logging.ERROR, "Something is messed up with your irc.conf file. (Did you edit it in Notepad?)") sys.exit(1) self.saving = False try: self.max_clients = self.config.getint("main", "max_clients") self.server_message = self.config.get("main", "description") self.public = self.config.getboolean("main", "public") self.controller_port = self.config.get("network", "controller_port") self.controller_password = self.config.get("network", "controller_password") self.server_name = self.config.get("main", "name") if self.server_name == "iCraft Server": logging.log(logging.ERROR, "You forgot to give your server a name.") self.owner = self.config.get("main", "owner").lower() if self.owner == "yournamehere": logging.log(logging.ERROR, "You forgot to make yourself the server owner.") except: logging.log(logging.ERROR, "You don't have a main.conf file! You need to rename main.example.conf to main.conf") sys.exit(1) try: self.duplicate_logins = self.options_config.getboolean("options", "duplicate_logins") self.info_url = self.options_config.get("options", "info_url") self.away_kick = self.options_config.getboolean("options", "away_kick") self.away_time = self.options_config.getint("options", "away_time") self.colors = self.options_config.getboolean("options", "colors") self.physics_limit = self.options_config.getint("worlds", "physics_limit") self.default_name = self.options_config.get("worlds", "default_name") self.default_backup = self.options_config.get("worlds", "default_backup") self.asd_delay = self.options_config.getint("worlds", "asd_delay") self.gchat = self.options_config.getboolean("worlds", "gchat") except: logging.log(logging.ERROR, "You don't have a options.conf file! You need to rename options.example.conf to options.conf") sys.exit(1) try: self.grief_blocks = self.ploptions_config.getint("antigrief", "blocks") self.grief_time = self.ploptions_config.getint("antigrief", "time") self.backup_freq = self.ploptions_config.getint("backups", "backup_freq") self.backup_default = self.ploptions_config.getboolean("backups", "backup_default") self.backup_max = self.ploptions_config.getint("backups", "backup_max") self.backup_auto = self.ploptions_config.getboolean("backups", "backup_auto") self.enable_archives = self.ploptions_config.getboolean("archiver", "enable_archiver") self.currency = self.ploptions_config.get("bank", "currency") self.build_director = self.ploptions_config.get("build", "director") self.build_admin = self.ploptions_config.get("build", "admin") self.build_mod = self.ploptions_config.get("build", "mod") self.build_op = self.ploptions_config.get("build", "op") self.build_other = self.ploptions_config.get("build", "other") if self.backup_auto: reactor.callLater(float(self.backup_freq * 60),self.AutoBackup) except: logging.log(logging.ERROR, "You don't have a ploptions.conf file! You need to rename ploptions.example.conf to ploptions.conf") sys.exit(1) #if not os.path.exists("config/greeting.txt"): # logging.log(logging.ERROR, "You don't have a greeting.txt file! You need to rename greeting.example.txt to greeting.txt (If this error persists, you may have used Notepad.)") # sys.exit(1) #if not os.path.exists("config/rules.txt"): # logging.log(logging.ERROR, "You don't have a rules.txt file! You need to rename rules.example.txt to rules.txt (If this error persists, you may have used Notepad.)") # sys.exit(1) if self.use_irc: self.irc_nick = self.irc_config.get("irc", "nick") self.irc_pass = self.irc_config.get("irc", "password") self.irc_channel = self.irc_config.get("irc", "channel") self.irc_cmdlogs = self.irc_config.getboolean("irc", "cmdlogs") self.ircbot = self.irc_config.getboolean("irc", "ircbot") self.staffchat = self.irc_config.getboolean("irc", "staffchat") self.irc_relay = ChatBotFactory(self) if self.ircbot and not (self.irc_channel == "#icraft" or self.irc_channel == "#channel") and not self.irc_nick == "botname": reactor.connectTCP(self.irc_config.get("irc", "server"), self.irc_config.getint("irc", "port"), self.irc_relay) else: logging.log(logging.ERROR, "IRC Bot failed to connect, you could modify, rename or remove irc.conf") logging.log(logging.ERROR, "You need to change your 'botname' and 'channel' fields to fix this error or turn the bot off by disabling 'ircbot'") else: self.irc_relay = None self.default_loaded = False # Word Filter try: self.wordfilter.read("config/wordfilter.conf") except: logging.log(logging.ERROR, "Something is messed up with your wordfilter.conf file. (Did you edit it in Notepad?)") sys.exit(1) self.filter = [] try: number = int(self.wordfilter.get("filter","count")) except: logging.log(logging.ERROR, "You need to rename wordfilter.example.conf to wordfilter.conf") sys.exit(1); for x in range(number): self.filter = self.filter + [[self.wordfilter.get("filter","s"+str(x)),self.wordfilter.get("filter","r"+str(x))]] # Salt, for the heartbeat server/verify-names self.salt = hashlib.md5(hashlib.md5(str(random.getrandbits(128))).digest()).hexdigest()[-32:].strip("0") # Load up the plugins specified self.plugins_config = ConfigParser() try: self.plugins_config.read("config/plugins.conf") except: logging.log(logging.ERROR, "Something is messed up with your irc.conf file. (Did you edit it in Notepad?)") sys.exit(1) try: plugins = self.plugins_config.options("plugins") except: print ("NOTICE: You need to rename plugins.example.conf to plugins.conf") sys.exit(1); logging.log(logging.INFO, "Loading plugins...") load_plugins(plugins) # Open the chat log, ready for appending self.chatlog = open("logs/server.log", "a") self.chatlog = open("logs/chat.log", "a") # Create a default world, if there isn't one. if not os.path.isdir("worlds/%s" % self.default_name): logging.log(logging.INFO, "Generating %s world..." % self.default_name) sx, sy, sz = 64, 64, 64 grass_to = (sy // 2) world = World.create( "worlds/%s" % self.default_name, sx, sy, sz, # Size sx//2,grass_to+2, sz//2, 0, # Spawn ([BLOCK_DIRT]*(grass_to-1) + [BLOCK_GRASS] + [BLOCK_AIR]*(sy-grass_to)) # Levels ) logging.log(logging.INFO, "Generated.") # Initialise internal datastructures self.worlds = {} self.directors = set() self.admins = set() self.mods = set() self.globalbuilders = set() self.members = set() self.spectators = set() self.silenced = set() self.banned = {} self.ipbanned = {} self.lastseen = {} # Load up the contents of those. self.loadMeta() # Set up a few more things. self.queue = Queue() self.clients = {} self.usernames = {} self.console = StdinPlugin(self) self.console.start() self.heartbeat = Heartbeat(self) # Boot worlds that got loaded for world in self.worlds: self.loadWorld("worlds/%s" % world, world) # Set up tasks to run during execution reactor.callLater(0.1, self.sendMessages) reactor.callLater(1, self.printInfo) # Initial startup is instant, but it updates every 10 minutes. self.world_save_stack = [] reactor.callLater(60, self.saveWorlds) if self.enable_archives: self.loadPlugin('archives') reactor.callLater(1, self.loadArchives) gc.disable() self.cleanGarbage()
def __init__(self, configManager, frame): """""" LabelFrame.__init__(self, frame, text=configManager._file) self._counter = Label(self) World.__init__(self, configManager) self.refresh()
def terminate(self): World.terminate(self) return self.drone.land()
def resetState(self): World.resetState(self) self.drone.land() self.setup()
def __init__(self, config): World.__init__(self, config)
from core.actor.terminal import Terminal """ start like this: >>> python -i interactive.py """ while True: mos = input("load from 'map' or 'save': ") if mos in ('map', 'save'): break else: print("Input needs to be 'map' or 'save'") if mos == 'map': world = World(seed=random.randint(0, 1000)) world.load_map('2playertest') elif mos == 'save': world = World.load_savegame('testgame') else: raise EnvironmentError("Should not get here") self = Terminal(name="John") world.add_actor(self) if mos == 'map': world.distribute_settlements() def exit(): self.quit()
def train_test(display=True): world = World() poppy = Agent() poppy.cortex.display = display run(world, poppy, train=True) run(world, poppy, train=False)
'': { 'handlers': ['stdout'], 'level': 'DEBUG', }, } }) def initialize_subsystems(): subsystems = entity_registry.get_by_class(Subsystem) for subsystem in subsystems: subsystem.initialize() if __name__ == '__main__': # TODO: move core stuff initialization somewhere entity_registry.add(DefaultVectorFactory()) entity_registry.add(GameTime(1.0 / 60.0)) entity_registry.add(PygameSubsystem()) entity_registry.add(PygameGraphicsSubsystem()) entity_registry.add(PygameInputSubsystem()) initialize_subsystems() game_rules = FmGameRules() entity_registry.add(game_rules) game_rules.initialize() world = World() world.run()
def test(): """""" global w w = World() scA = MetaStatus("animal", [Animal], "uneCouleur") scH = MetaStatus("hungry", [Animal], "uneCouleur") MetaVar("fed", scA, 50, -5, {}, {"food": 1}, [(float.__le__, 40, scH), (float.__gt__, 50, scA)], {}, {}) MetaVar("fed", scH, 40, -5, {}, {"food": 1}, [(float.__gt__, 50, scA), (float.__le__, 0, MetaDeath())], {}, {}) MetaVar("sense", scH, 0, 0, {}, {"smell": 1}, [], {}, {}) a1 = Animal() a2 = Animal() scA(a1) scA(a2) scG = MetaStatus("grass", [Vegetal], "uneCouleur") MetaVar("food", scG, 10, 4, {}, {}, [(float.__le__, 0, MetaDeath())], {(float.__ge__, 20): scG}, {}) MetaVar("smell", scG, 10, 0, {"smell": -1}, {}, [], {}, {}) v1 = Vegetal() v2 = Vegetal() v3 = Vegetal() v4 = Vegetal() scG(v1) scG(v2) scG(v3) scG(v4) scM = MetaStatus("mineral", [Mineral], "uneCouleur") m1 = Mineral() m2 = Mineral() m3 = Mineral() scM(m1) scM(m2) scM(m3) w.addAgent(a1, (3, 9)) w.addAgent(a2, (2, 9)) w.addAgent(v1, (4, 2)) w.addAgent(v2, (0, 18)) w.addAgent(v3, (4, 18)) w.addAgent(v4, (2, 2)) # w.addAgent(m1, (4, 17)) # w.addAgent(m2, (1, 11)) # w.addAgent(m3, (2, 3)) print(w) print(w.__repr__())