def __init__(self, *_, libretro='data/gambatte_libretro.dll', rom='data/pokeblue.gb', state='data/pokeblue.state', draw_pad=True, scale_factor=2): Game.__init__(self) # load the libretro core and feed the emulator a ROM self.emu = retro.core.EmulatedSystem(libretro) self.emu.load_game_normal(open(rom, 'rb').read(), path=rom) self.name = self.emu.name # load a starting state if one was provided try: with open(state or '', 'rb') as f: self.Thaw(f.read()) except IOError: pass # scaling self.scale_factor = int(scale_factor) # showing what buttons are active self.pad = 0 self.pad_overlay = SnesPadDrawing(name='SUPER SYNC') if draw_pad else None # register rendering and input-reading callbacks self._register_video_refresh() # disabled until there's a decent audio implementation # retro.portaudio_audio.set_audio_sample_internal(self.emu) retro.simple_input.set_input_internal(self.emu) # unplug player 2 controller so we don't get twice as many input state callbacks self.emu.set_controller_port_device(1, retro.DEVICE_NONE) # limit FPS self.clock = pygame.time.Clock() self.limit_fps = True
def __init__(self, args={}): Game.__init__(self, args, defaultargs, validargs) self.GenerateValidInputs(args['inputmask']) # load the libretro core and feed the emulator a ROM self.emu = core.EmulatedSNES(args['libretro']) self.emu.load_cartridge_normal(open(args['rom'], 'rb').read()) # load a starting state if one was provided if args['initstate']: try: f = open(args['initstate'], 'rb') self.emu.unserialize(f.read()) except IOError: pass # register drawing and input-reading callbacks self.snesfb = None if self.args['video']: self.snesfb = pygame.Surface(self.emu.get_av_info()['base_size']) pgvid.set_video_refresh_surface(self.emu, self.snesfb) siminp.set_input_internal(self.emu) # unplug player 2 controller so we don't get twice as many input state callbacks self.emu.set_controller_port_device(1, retro.DEVICE_NONE) # only bother with the overhead of audio if it's requested audtype = self.args['audio'] #if audtype == 'wave': waveaud.set_audio_sink(self.emu, 'superopti.wav') if audtype == 'pygame': pgaud.set_audio_sample_internal(self.emu) elif audtype == 'array': self.emu.set_audio_sample_cb(self._audio_sample_cb) # don't put anything in the work ram until the emulator can self.wram = None self.soundbuf = array('H', []) self.pad = 0 self._Heuristic = None try: sys.path.append('./heuristics') self._Heuristic = __import__(self.args['heuristic']).Heuristic except: print 'SuperOpti: could not load given heuristic, falling back to blind' # number of frames to let a single input persist self.granularity = self.args['granularity'] # maximum length of inputs before making a new 'keyframe' state self.tweening = self.args['tweening'] self.keyframe = None self.inputs_since_keyframe = [] # showing what buttons are active self.padoverlay = None if self.args['padoverlay']: self.padoverlay = SnesPadDrawing(name='SUPEROPTI')
def __init__(self, args = {}): Game.__init__(self, args, defaultargs, validargs) self.GenerateValidInputs(args['inputmask']) # load the libretro core and feed the emulator a ROM self.emu = core.EmulatedSNES(args['libretro']) self.emu.load_cartridge_normal(open(args['rom'], 'rb').read()) # load a starting state if one was provided if args['initstate']: try: f = open(args['initstate'], 'rb') self.emu.unserialize(f.read()) except IOError: pass # register drawing and input-reading callbacks self.snesfb = None if self.args['video']: self.snesfb = pygame.Surface(self.emu.get_av_info()['base_size']) pgvid.set_video_refresh_surface(self.emu, self.snesfb) siminp.set_input_internal(self.emu) # unplug player 2 controller so we don't get twice as many input state callbacks self.emu.set_controller_port_device(1, retro.DEVICE_NONE) # only bother with the overhead of audio if it's requested audtype = self.args['audio'] #if audtype == 'wave': waveaud.set_audio_sink(self.emu, 'superopti.wav') if audtype == 'pygame': pgaud.set_audio_sample_internal(self.emu) elif audtype == 'array': self.emu.set_audio_sample_cb(self._audio_sample_cb) # don't put anything in the work ram until the emulator can self.wram = None self.soundbuf = array('H', []) self.pad = 0 self._Heuristic = None try: sys.path.append('./heuristics') self._Heuristic = __import__(self.args['heuristic']).Heuristic except: print 'SuperOpti: could not load given heuristic, falling back to blind' # number of frames to let a single input persist self.granularity = self.args['granularity'] # maximum length of inputs before making a new 'keyframe' state self.tweening = self.args['tweening'] self.keyframe = None self.inputs_since_keyframe = [] # showing what buttons are active self.padoverlay = None if self.args['padoverlay']: self.padoverlay = SnesPadDrawing(name='SUPEROPTI')
def __init__(self, args = {}): Game.__init__(self, args, defaultargs, validargs) self.inputs = { 'hat0_up': 0b0001, 'hat0_down': 0b0010, 'hat0_left': 0b0100, 'hat0_right': 0b1000 } # parse map lines = open(self.args['map'], 'r').read().strip('\n').split('\n') self.w, self.h = (max(len(l) for l in lines), len(lines)) # all floor tiles at first # world[x][y] corresponds to lines[y][x] here. self.world = [[floor for i in xrange(self.h)] for j in xrange(self.w)] # generating the surface as we go along too self.surf = pygame.Surface((self.w, self.h)) self.surf.fill(floor_color) self.boxes = set() self.holes = set() for y in xrange(self.h): for x in xrange(len(lines[y])): char = lines[y][x] xy = (x, y) if char in '#': self.world[x][y] = wall self.surf.set_at(xy, wall_color) elif char in 'p@': self.xpos, self.ypos = xy elif char in 'P+': self.xpos, self.ypos = xy self.holes.add(xy) self.surf.set_at(xy, hole_color) elif char in 'b$`': self.boxes.add(xy) elif char in '.^': self.holes.add(xy) self.surf.set_at(xy, hole_color) elif char in 'B*': self.boxes.add(xy) self.holes.add(xy) self.surf.set_at(xy, hole_color) # performance hack for boxhole in self.boxes & self.holes: if self.TrappedBox(boxhole): self.boxes.remove(boxhole) self.holes.remove(boxhole) x, y = boxhole self.world[x][y] = wall self.surf.set_at(boxhole, boxhole_color) self.holes = frozenset(self.holes)
def __init__(self, args={}): Game.__init__(self, args, defaultargs, validargs) if 'seed' in self.args: random.seed(self.args['seed']) # God does not play dice self.inputs = { 'hat0_up': 0b0001, 'hat0_down': 0b0010, 'hat0_left': 0b0100, 'hat0_right': 0b1000 } xmax, ymax = self.args['screen'] self.w, self.h = (xmax, ymax) # all wall tiles at first self.world = [[wall for i in xrange(ymax)] for j in xrange(xmax)] # generating the surface as we go along too self.surf = pygame.Surface((xmax, ymax)) self.surf.fill(wall_color) x, y = (1, ymax / 2) # start on left side in the middle # create our "Player" self.xpos = x self.ypos = y # carve out the world self.world[x][ y] = floor # place the floor tile, thereby demolishing the walls self.surf.set_at((x, y), floor_color) # do the same thing in the visual map # wander around until we hit the right side, # but leave a border of wall around the outside while x < xmax - 1: step = random.randint(0, 1) * 2 - 1 if random.randint(0, 1) == 1: x += step else: y += step # avoid crossing boundaries, except the right side # (if we hit the right edge, we're done!) if y == 0: y = 1 elif y == ymax - 1: y = ymax - 2 if x == 0: x = 1 # we check for x out of the right side in the 'while' condition. self.world[x][y] = floor self.surf.set_at((x, y), floor_color)
def __init__(self, args = {}): Game.__init__(self, args, defaultargs, validargs) if 'seed' in self.args: random.seed(self.args['seed']) # God does not play dice self.inputs = { 'hat0_up': 0b0001, 'hat0_down': 0b0010, 'hat0_left': 0b0100, 'hat0_right': 0b1000 } xmax, ymax = self.args['screen'] self.w, self.h = (xmax, ymax) # all wall tiles at first self.world = [[wall for i in xrange(ymax)] for j in xrange(xmax)] # generating the surface as we go along too self.surf = pygame.Surface((xmax,ymax)) self.surf.fill(wall_color) x, y = (1, ymax/2) # start on left side in the middle # create our "Player" self.xpos = x self.ypos = y # carve out the world self.world[x][y]=floor # place the floor tile, thereby demolishing the walls self.surf.set_at((x,y), floor_color) # do the same thing in the visual map # wander around until we hit the right side, # but leave a border of wall around the outside while x < xmax-1: step = random.randint(0,1)*2 - 1 if random.randint(0,1) == 1: x+=step else: y+=step # avoid crossing boundaries, except the right side # (if we hit the right edge, we're done!) if y == 0: y=1 elif y == ymax-1: y=ymax-2 if x == 0: x=1 # we check for x out of the right side in the 'while' condition. self.world[x][y] = floor self.surf.set_at((x,y), floor_color)
def __init__(self, args = {}): Game.__init__(self, args, defaultargs, validargs) self.program = '' self.current_output = '' self.desired_output = self.args['output'] self.iter_max = self.args['max_loop'] self.bit_mask = (1 << self.args['bits_per_cell']) - 1 # , is omitted because it could just produce a BF implementation of cat self.inputs = { 'hat0_up': '+', 'hat0_down': '-', 'hat0_left': '<', 'hat0_right': '>', 0: '.', 1: '[', 2: ']' } pygame.font.init() self.pg_font = pygame.font.Font(None, 16)
def __init__(self, args={}): Game.__init__(self, args, defaultargs, validargs) self.program = '' self.current_output = '' self.desired_output = self.args['output'] self.iter_max = self.args['max_loop'] self.bit_mask = (1 << self.args['bits_per_cell']) - 1 # , is omitted because it could just produce a BF implementation of cat self.inputs = { 'hat0_up': '+', 'hat0_down': '-', 'hat0_left': '<', 'hat0_right': '>', 0: '.', 1: '[', 2: ']' } pygame.font.init() self.pg_font = pygame.font.Font(None, 16)