示例#1
0
 def loadMapTest(self, map_name, pc_coords, pc_sprite):
     print("* Loading map test...")
     self.unloadMap()
     self.world = World(self)
     #self.world = World(self, "Ashgrove")
     #campaign.init(self.world)
     self.world.current_map_name = map_name
     if not pc_sprite.endswith(".xml"):
         print("Incorrect sprite file name", pc_sprite)
         return
     pc_sprite_name = pc_sprite.split("\\")[-1][:-4]
     print(pc_sprite, pc_sprite_name)
     pc = self.world.addCharacterAt(pc_coords, map_name, "test_character",
                                    "test character", str(pc_sprite_name))
     self.world.enablePlayerCharacter(pc)
     self.loadObject("objects\\Sprites - Characters\\" + str(pc_sprite))
     self.loadMap(self.world.current_map_name)
     self.world.visual = WorldVisual(self, self.maplayer, self.world)
     self.view = View(self)
     #self.view.camera.getLocationRef().setLayerCoordinates(
     #			fife.ModelCoordinate(40, 0, 0))
     self.gui.showHUD()
     self.unpause(True)
     self.change_map_name = None
     self.exploration = Exploration(self)
     print("* Map loaded!")
示例#2
0
 def loadGame(self, save_name):
     self.loadMap(self.world.current_map_name)
     self.world.application = self
     self.world.visual = WorldVisual(self, self.maplayer, self.world)
     self.view = View(self)
     self.gui.showHUD()
     self.unpause(True)
     self.change_map_name = None
     self.exploration = Exploration(self)
     print("* Game loaded!")
 def performance_measure(self, x):
     """
     Apply the fitness function to individual x
     :param x: individual
     :return performance: fitness of x
     """
     # "calculate performance measure"
     performance = x.evaluate()
     # TODO: collect all the inputs generated in this run
     Exploration.add_explored(x.member)
     return performance
示例#4
0
 def newGame(self):
     self.loadMap(self.world.current_map_name)
     self.world.visual = WorldVisual(self, self.maplayer, self.world)
     self.view = View(self)
     camera_loc = self.view.camera.getLocation()
     camera_loc.setLayerCoordinates(self.world.camera_coords)
     self.view.camera.setLocation(camera_loc)
     self.gui.showHUD()
     self.unpause(True)
     self.change_map_name = None
     self.exploration = Exploration(self)
     print("* Game started!")
示例#5
0
 def changeMap(self, map_name):
     self.real_timeline.clear()
     self.world.visual.cleanUp()
     self.world.visual = None
     self.world.current_map_name = map_name
     if self.map:
         self.model.deleteMap(self.map)
     if self.imagemanager.getMemoryUsed() > 700000000:
         self.imagemanager.freeUnreferenced()
     print("Memory used by the image manager:",
           "{:,}".format(self.imagemanager.getMemoryUsed()))
     self.loadMap(self.world.current_map_name)
     self.world.visual = WorldVisual(self, self.maplayer, self.world)
     self.view = View(self)
     self.gui.showHUD()
     self.unpause(True)
     self.exploration = Exploration(self)
示例#6
0
def main():
    entrypoint = 0x401094
    fuzzed_address = set()
    queue = multiprocessing.Queue()
    process = list()

    ctx = TritonContext()
    ctx.setArchitecture(ARCH.X86_64)
    ctx.enableMode(MODE.ALIGNED_MEMORY, True)
    ctx.setAstRepresentationMode(AST_REPRESENTATION.PYTHON)

    exploration = Exploration()
    tracer = Tracer(program_name, True)
    tracer.tracer_init(ctx)

    # Sets callbacks
    tracer.add_start_callback(exploration.start)
    tracer.add_instruction_callback(exploration.get_instruction)
    tracer.add_end_callback(exploration.end)
    tracer.add_memory_callback(exploration.symbolized_memory_input)
    tracer.add_register_callback(exploration.symbolized_register_input)

    for i in range(30):
        tracer.start(ctx, 1, entrypoint)

        if exploration.fuzz_is_needed is True:
            untaken_branch = set(exploration.get_untaken_branch())
            for i in untaken_branch:
                if i not in fuzzed_address:
                    if exploration.untaken_branch[i] != 0:
                        process.append(
                            send_to_fuzz(
                                entrypoint,
                                copy.deepcopy(exploration.exploration_memory),
                                copy.deepcopy(
                                    exploration.exploration_registers),
                                copy.copy(exploration.untaken_branch[i]), i,
                                queue))
                        process[-1].start()
                        process[-1].join()

                    fuzzed_address.add(i)

            try:
                new_inputs = queue.get(block=True, timeout=5)
                exploration.add_fuzz_inputs(new_inputs[0], new_inputs[1])
            except Queue.Empty:
                print(map(hex, exploration.get_untaken_branch()))
                print("Can't find more branch")
                break

    exploration.show_exploration()
示例#7
0
        def get_services():
            try:
                self.memory = self.session.service('ALMemory')

                self.motion_service=self.session.service("ALMotion")
                self.decos_navigation_files_service=self.session.service("DecosNavigationFiles")
                self.navigation_service=self.session.service("ALNavigation")

                self.exploration = Exploration(self.navigation_service,self.motion_service,self.decos_navigation_files_service)

                self.logger.info('All services are now connected')
                self.services_connected.setValue(True)
            except RuntimeError as e:
                self.logger.warning('Still missing some service:\n {}'.format(e))
 def __init__(self) -> None:
     self.network = NetWork().to(device)
     print("Number of parameters in network:",
           count_parameters(self.network))
     self.criterion = MSELoss()
     self.optimizer = Adam(self.network.parameters(),
                           lr=0.001,
                           weight_decay=0.001)
     self.memory = ReplayBuffer(100000)
     self.remember = self.memory.remember()
     self.exploration = Exploration()
     self.explore = self.exploration.epsilonGreedy
     self.target_network = NetWork().to(device)
     self.placeholder_network = NetWork().to(device)
示例#9
0
 def __init__(self,
              game: Game,
              network: Networks,
              learner: Learners,
              exploration: Explorations,
              gamma: float = None,
              K: float = None,
              width: int = None,
              height: int = None,
              batch: int = None,
              _extra_dim: int = 0,
              **kwargs) -> None:
     self.extradim = _extra_dim
     self.batch = batch
     self.height = height
     self.width = width
     self.net = Net(
         len(game.layers) + _extra_dim, width, height, network, **kwargs)
     self.learner = Learner(self.net, learner, gamma, **kwargs)
     self.exploration = Exploration(exploration, K, **kwargs)
示例#10
0
def dfExplore(df):
    explore = Exploration(df)
    explore.scatter()
    explore.classGraph()
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        """ Set GUI to track mouse """
        QWidget.setMouseTracking(self, True)
        """
        Dynamixel bus
        TODO: add other motors here as needed with their correct address"""
        # self.dxlbus = DXL_BUS(DEVICENAME, BAUDRATE)
        # port_num = self.dxlbus.port()
        # base = DXL_XL(port_num, 1)
        # shld = DXL_XL(port_num, 2)
        # elbw = DXL_XL(port_num, 3)
        # wrst = DXL_XL(port_num, 4)
        # grip = DXL_XL(port_num, 5)
        """Objects Using Other Classes"""
        self.camera = PiCamera()
        # self.rexarm = Rexarm((base, shld, elbw, wrst, grip))
        # self.tp = TrajectoryPlanner(self.rexarm)
        self.sm = StateMachine(self.rexarm, self.tp)
        global explore_obj
        explore_obj = Exploration(self.sm)
        self.taskThread = TaskThread(self.sm)
        self.rgb_image = None
        """
        Attach Functions to Buttons & Sliders
        TODO: NAME AND CONNECT BUTTONS AS NEEDED
        """
        self.ui.btn_estop.clicked.connect(self.estop)
        self.ui.btnUser1.setText("Calibrate")
        self.ui.btnUser1.clicked.connect(
            partial(self.sm.set_current_state, "calibrate"))
        self.ui.btnUser2.setText("Moving Arm")
        self.ui.btnUser2.clicked.connect(
            partial(self.sm.set_current_state, "moving_arm"))
        self.ui.btnUser3.setText("Return Home")
        self.ui.btnUser3.clicked.connect(
            partial(self.sm.set_current_state, "arm_return_home"))
        self.ui.btnUser4.setText("Exploration")
        self.ui.btnUser4.clicked.connect(
            partial(self.sm.set_current_state, "exploration"))
        self.ui.btnUser5.setText("Swipe")
        self.ui.btnUser5.clicked.connect(
            partial(self.sm.set_current_state, "swipe"))
        self.ui.btnUser6.setText("Put back block")
        self.ui.btnUser6.clicked.connect(
            partial(self.sm.set_current_state, "put_back_block"))
        self.ui.btnUser7.setText("Moving back")
        self.ui.btnUser7.clicked.connect(
            partial(self.sm.set_current_state, "moving_back"))
        self.ui.btnUser8.setText("Reach block")
        self.ui.btnUser8.clicked.connect(
            partial(self.sm.set_current_state, "reach_block"))
        self.ui.btnUser9.setText("Moving to side")
        self.ui.btnUser9.clicked.connect(
            partial(self.sm.set_current_state, "moving_to_block_side"))

        # self.ui.btn_task1.clicked.connect(
        #   partial(self.taskThread.set_task_num, 1))
        self.ui.btn_task1.clicked.connect(partial(self.taskThread.run))
        # Button for exploration code to run
        # self.ui.explore_btn.clicked.connect(self.taskThread.start)

        self.ui.sldrBase.valueChanged.connect(self.sliderChange)
        self.ui.sldrShoulder.valueChanged.connect(self.sliderChange)
        self.ui.sldrElbow.valueChanged.connect(self.sliderChange)
        self.ui.sldrWrist.valueChanged.connect(self.sliderChange)

        self.ui.sldrWrist2.valueChanged.connect(self.sliderChange)
        self.ui.sldrGrip1.valueChanged.connect(self.sliderChange)

        self.ui.sldrMaxTorque.valueChanged.connect(self.sliderChange)
        self.ui.sldrSpeed.valueChanged.connect(self.sliderChange)
        self.ui.chk_directcontrol.stateChanged.connect(self.directControlChk)
        self.ui.rdoutStatus.setText("Waiting for input")
        """initalize manual control off"""
        self.ui.SliderFrame.setEnabled(False)
        """initalize rexarm"""
        self.rexarm.initialize()
        """Setup Threads"""
        self.videoThread = VideoThread(self.camera)
        self.videoThread.updateFrame.connect(self.setImage)
        self.videoThread.updateAprilTags.connect(self.updateAprilTags)
        self.videoThread.start()

        self.logicThread = LogicThread(self.sm)
        self.logicThread.start()

        # Moving line to button to start
        # self.taskThread.start()

        self.displayThread = DisplayThread(self.rexarm, self.sm)
        self.displayThread.updateJointReadout.connect(self.updateJointReadout)
        self.displayThread.updateEndEffectorReadout.connect(
            self.updateEndEffectorReadout)
        self.displayThread.updateStatusMessage.connect(
            self.updateStatusMessage)
        self.displayThread.start()
        """
        Setup Timer
        this runs the trackMouse function every 50ms
        """
        self._timer = QTimer(self)
        self._timer.timeout.connect(self.trackMouse)
        self._timer.start(50)
示例#12
0
    def get_exploration_stats(cls, event_name, exploration_id):
        """Retrieves statistics for the given event name and exploration id."""

        if event_name == STATS_ENUMS.exploration_visited:
            event_key = 'e.%s' % exploration_id
            counter = Counter.get_by_id(event_key)
            if not counter:
                return 0
            return counter.value

        if event_name == STATS_ENUMS.exploration_completed:
            event_key = 'c.%s' % exploration_id
            counter = Counter.get_by_id(event_key)
            if not counter:
                return 0
            return counter.value

        if event_name == STATS_ENUMS.rule_hit:
            result = {}

            exploration = Exploration.get(exploration_id)
            for state_key in exploration.states:
                state = state_key.get()
                result[state.id] = {
                    'name': state.name,
                    'rules': {}
                }
                for handler in state.widget.handlers:
                    for rule in handler.rules:
                        rule_name = create_rule_name(rule)
                        event_key = 'default.%s.%s.%s' % (exploration_id, state.id, rule_name)

                        journal = Journal.get_by_id(event_key)

                        if journal:
                            top_ten = collections.Counter(
                                journal.values).most_common(10)
                        else:
                            top_ten = []

                        result[state.id]['rules'][rule_name] = {
                            'answers': top_ten,
                        }

            return result

        if event_name == STATS_ENUMS.state_hit:
            result = {}

            exploration = Exploration.get(exploration_id)
            for state_key in exploration.states:
                state = state_key.get()
                event_key = 's.%s.%s' % (exploration_id, state.id)

                counter = Counter.get_by_id(event_key)
                if not counter:
                    count = 0
                else:
                    count = counter.value

                result[state.id] = {
                    'name': state.name,
                    'count': count,
                }
            return result
示例#13
0
class Application(CEGUIApplicationBase, PychanApplicationBase):
    def __init__(self, settings):
        #self.ar = []
        #for i in xrange(512):
        #	self.ar.append(' ' * memtest.MEGA)
        #self.a = ' ' * memtest.MEGA * 1024
        #memtest.alloc_max_str()
        #memtest.alloc_max_array()

        print("* Initializing application...")
        super(Application, self).__init__(settings)
        self.settings = settings
        self.model = self.engine.getModel()
        self.mapLoader = fife.MapLoader(self.model, self.engine.getVFS(),
                                        self.engine.getImageManager(),
                                        self.engine.getRenderBackend())
        self.objectLoader = fife.ObjectLoader(
            self.model, self.engine.getVFS(), self.engine.getImageManager(),
            self.engine.getAnimationManager())
        #		self.atlasLoader = fife.AtlasLoader(self.model,
        #									self.engine.getVFS(),
        #									self.engine.getImageManager())

        self.map = None
        self.world = None
        self.view = None
        self.change_res = False

        self.eventmanager = self.engine.getEventManager()
        self.mouselistener = MouseListener(self)
        self.keylistener = KeyListener(self)
        self.eventmanager.addMouseListenerFront(self.mouselistener)
        self.eventmanager.addKeyListenerFront(self.keylistener)
        self.soundmanager = self.engine.getSoundManager()
        self.soundmanager.init()
        self.imagemanager = self.engine.getImageManager()
        print("* Application initialized!")

        self.gui = GUI(self)
        self.real_timeline = RealTimeline()
        self.engine.getTimeManager().registerEvent(self.real_timeline)
        self.game_speed = 1

        #print self.engine.getRenderBackend().isDepthBufferEnabled()

        #		self.loadAtlas("objects/nature.xml")
        print("* Loading objects...")
        for import_object in importobjects.import_list:
            self.loadObject(import_object)
        if self.settings.get("gameplay", "PreloadSprites", True):
            self.imagemanager.reloadAll()
        print("* Objects loaded!")

        self.sounds = {}
        self.music = None
        self.music_name = ""
        #self.music = self.soundmanager.createSoundEmitter("music/SFT-Two Mapple Inn.ogg")
        #		self.sound_attack = self.soundmanager.createSoundEmitter("sfx/attack-1.ogg")
        #self.music.looping = True
        if not self.settings.get("FIFE", "PlaySounds"):
            self.soundmanager.setVolume(0.0)
        #self.music.play()

        self.cursor = self.imagemanager.load("gui/cursors/Mousecursor01.png")
        self.cursor.setXShift(-4)
        #self.imagemanager.free("gui/cursors/Mousecursor01.png")
        #self.imagemanager.reload("gui/cursors/Mousecursor01.png")
        self.map_cursor = self.imagemanager.load(
            "gui/cursors/Mousecursor02.png")
        self.map_cursor.setXShift(-29)
        self.map_cursor.setYShift(-29)
        #self.null_image = self.imagemanager.loadBlank(1, 1)
        #self.engine.getCursor().set(self.null_image)
        #self.engine.getCursor().setDrag(self.cursor, -4, 0)
        self.engine.getCursor().set(self.cursor)

        self.unloadMap()

        self.lastmem = 0

    def createListener(self):
        self._listener = Listener(self)
        return self._listener

    def playSound(self, sound):
        if sound not in self.sounds:
            self.sounds[sound] = self.soundmanager.createEmitter("sfx/" +
                                                                 sound +
                                                                 ".ogg")
        self.sounds[sound].play()

    def loadObject(self, filename, pingpong=False, object_name=""):
        if self.objectLoader.isLoadable(filename):
            self.objectLoader.load(filename)
        else:
            print("WARNING: Can't load", filename)

    def loadAtlas(self, filename):
        if self.atlasLoader.isLoadable(filename):
            self.atlasLoader.load(filename)
        else:
            print("WARNING: Can't load", filename)

    def loadMap(self, map_name):
        print("* Loading objects for map", map_name)
        for import_object in importobjects.import_by_map.get(map_name, ()):
            self.loadObject(import_object)
        if self.settings.get("gameplay", "PreloadSprites", True):
            self.imagemanager.reloadAll()
        print("* Objects loaded!")
        filename = str("maps/" + map_name + ".xml")
        if self.mapLoader.isLoadable(filename):
            print("* Loading map", map_name)
            self.map = self.mapLoader.load(filename)
            self.camera = self.map.getCamera("main_camera")
            self.maplayer = self.map.getLayer("buildings_layer")
            #print "imagemanager.reloadAll()"
            #self.imagemanager.reloadAll()
            print("* Map loaded!")
        else:
            print("WARNING: Can't load map")
        if music.music_by_map.get(map_name,
                                  self.music_name) != self.music_name:
            self.music_name = music.music_by_map[map_name]
            if self.music:
                self.music.stop()
            self.music = self.soundmanager.createEmitter("music/" +
                                                         self.music_name +
                                                         ".ogg")
            self.music.setLooping(True)
            self.music.play()

    def unloadMap(self):
        self.real_timeline.clear()
        if self.world:
            self.world.visual.cleanUp()
        if self.map:
            self.model.deleteMap(self.map)
        if self.imagemanager.getMemoryUsed() > 700000000:
            self.imagemanager.freeUnreferenced()
        print("Memory used by the image manager:",
              "{:,}".format(self.imagemanager.getMemoryUsed()))
        self.map = None
        self.world = None
        self.view = None
        self.change_map_name = None
        self.combat = None
        self.cutscene = None
        self.exploration = None

    def gameOver(self):
        self.unloadMap()
        self.gui.showMainMenu()

    def newGame(self):
        self.loadMap(self.world.current_map_name)
        self.world.visual = WorldVisual(self, self.maplayer, self.world)
        self.view = View(self)
        camera_loc = self.view.camera.getLocation()
        camera_loc.setLayerCoordinates(self.world.camera_coords)
        self.view.camera.setLocation(camera_loc)
        self.gui.showHUD()
        self.unpause(True)
        self.change_map_name = None
        self.exploration = Exploration(self)
        print("* Game started!")

    def loadMapTest(self, map_name, pc_coords, pc_sprite):
        print("* Loading map test...")
        self.unloadMap()
        self.world = World(self)
        #self.world = World(self, "Ashgrove")
        #campaign.init(self.world)
        self.world.current_map_name = map_name
        if not pc_sprite.endswith(".xml"):
            print("Incorrect sprite file name", pc_sprite)
            return
        pc_sprite_name = pc_sprite.split("\\")[-1][:-4]
        print(pc_sprite, pc_sprite_name)
        pc = self.world.addCharacterAt(pc_coords, map_name, "test_character",
                                       "test character", str(pc_sprite_name))
        self.world.enablePlayerCharacter(pc)
        self.loadObject("objects\\Sprites - Characters\\" + str(pc_sprite))
        self.loadMap(self.world.current_map_name)
        self.world.visual = WorldVisual(self, self.maplayer, self.world)
        self.view = View(self)
        #self.view.camera.getLocationRef().setLayerCoordinates(
        #			fife.ModelCoordinate(40, 0, 0))
        self.gui.showHUD()
        self.unpause(True)
        self.change_map_name = None
        self.exploration = Exploration(self)
        print("* Map loaded!")

    def saveGame(self, save_name):
        self.world.refresh()
        serializer.save(self.world, "saves/" + save_name + ".sav")
        print("* Game saved!")

    def loadGame(self, save_name):
        self.loadMap(self.world.current_map_name)
        self.world.application = self
        self.world.visual = WorldVisual(self, self.maplayer, self.world)
        self.view = View(self)
        self.gui.showHUD()
        self.unpause(True)
        self.change_map_name = None
        self.exploration = Exploration(self)
        print("* Game loaded!")

    def changeMap(self, map_name):
        self.real_timeline.clear()
        self.world.visual.cleanUp()
        self.world.visual = None
        self.world.current_map_name = map_name
        if self.map:
            self.model.deleteMap(self.map)
        if self.imagemanager.getMemoryUsed() > 700000000:
            self.imagemanager.freeUnreferenced()
        print("Memory used by the image manager:",
              "{:,}".format(self.imagemanager.getMemoryUsed()))
        self.loadMap(self.world.current_map_name)
        self.world.visual = WorldVisual(self, self.maplayer, self.world)
        self.view = View(self)
        self.gui.showHUD()
        self.unpause(True)
        self.exploration = Exploration(self)

    def prepareChangeMap(self, map_name):
        if map_name == self.world.current_map_name:
            return
        print("* Changing map...")
        self.pause(True)
        self.gui.loading.showFade(lambda: self.prepareChangeMap2(map_name),
                                  map=map_name)

    def prepareChangeMap2(self, map_name):
        self.change_map_name = map_name

    def prepareNewGame(self):
        print("* Starting new game...")
        self.unloadMap()
        self.world = World(self)
        #self.world = World(self, "Ashgrove")
        Campaign.init(self.world)
        #self.real_timeline.addTimer(Timer("new game", 50, 1, self.newGame))
        self.gui.loading.showFade(self.newGame,
                                  map=self.world.current_map_name)

    def prepareLoadGame(self, save_name):
        self.unloadMap()
        self.world = serializer.load("saves/" + save_name + ".sav")
        #self.real_timeline.addTimer(Timer("load game", 50, 1, self.loadGame, args=save_name))
        self.gui.loading.showFade(lambda: self.loadGame(save_name),
                                  map=self.world.current_map_name)

    def prepareLoadMapTest(self, map_name, pc_coords, pc_sprite):
        self.gui.loading.showFade(
            lambda: self.loadMapTest(map_name, pc_coords, pc_sprite),
            map=map_name)

    def setTimeMultiplier(self, multiplier):
        self.real_timeline.multiplier = multiplier
        self.model.setTimeMultiplier(multiplier)

    def unpause(self, init=False):
        if init:
            self._paused = False
            self.force_paused = False
        self.world.visual.game_timeline.paused = False
        self.setTimeMultiplier(self.game_speed)

    def pause(self, override=False):
        if override:
            self._paused = True
        self.world.visual.game_timeline.paused = True
        self.setTimeMultiplier(0)

    def togglePause(self):
        if self.force_paused:
            return
        if self._paused:
            self._paused = False
            self.unpause()
        else:
            self._paused = True
            self.pause()

    @property
    def paused(self):
        return self._paused or self.force_paused

    def forcePause(self):
        gui_pause = (self.gui.dialogue.window.isVisible()
                     or self.gui.game_menu.window.isVisible()
                     or self.gui.preferences.window.isVisible()
                     or self.gui.help.window.isVisible()
                     or self.gui.save_load.window.isVisible()
                     or self.gui.book.window.isVisible()
                     or self.gui.journal.window.isVisible()
                     or self.gui.character_sheet.window.isVisible()
                     or self.gui.inventory.window.isVisible()
                     or self.gui.looting.window.isVisible()
                     or self.gui.weapon_info.window.isVisible()
                     or self.gui.loading.window.isVisible())
        #if gui_pause and not self.force_paused:
        if gui_pause or self._paused:
            self.pause()
        #if not gui_pause and self.force_paused and not self._paused:
        else:
            self.unpause()
        self.force_paused = gui_pause  # obsolete?

    @property
    def current_character(self):
        return self.world.player_character

    def startCombat(self, combatants, surprised=[]):
        for character in self.world.characters:
            if character.visual:
                character.visual.idle()
        self.combat = Combat(self, combatants, surprised=surprised)
        self.combat.beginTurn()

    def startCutscene(self, Cutscene):
        self.cutscene = Cutscene(self)
        self.gui.hideAll()

    def startDialogue(self, dialogue, npc=None, pc=None):
        if isinstance(dialogue, str):
            dialogue = loadDialogue(dialogue)
        self.gui.dialogue.start(
            DialogueState(dialogue, self.world, npc=npc, pc=pc))

    def changeRes(self):
        self.change_res = True
        self.engine.getCursor().setNativeImageCursorEnabled(
            self.settings.get("FIFE", "NativeImageCursor", False))

    def changeRes2(self):
        #PyCEGUIOpenGLRenderer.OpenGLRenderer.grabTextures(
        #	PyCEGUI.System.getSingleton().getRenderer())
        self.change_res = False
        old_mode = self.engine.getRenderBackend().getCurrentScreenMode()
        new_mode = self.engine.getDeviceCaps().getNearestScreenMode(
            int(
                self.settings.get("FIFE", "ScreenResolution",
                                  "1024x768").split("x")[0]),
            int(
                self.settings.get("FIFE", "ScreenResolution",
                                  "1024x768").split("x")[1]),
            self.settings.get("FIFE", "BitsPerPixel", "0"),
            self.settings.get("FIFE", "RenderBackend", "OpenGL"),
            self.settings.get("FIFE", "FullScreen", False))
        if (old_mode.getWidth() == new_mode.getWidth()
                and old_mode.getHeight() == new_mode.getHeight()
                and old_mode.isFullScreen() == new_mode.isFullScreen()
                and self.engine.getRenderBackend().isVSyncEnabled()
                == self.settings.get("FIFE", "VSync", True)):
            return
        self.engine.getRenderBackend().setVSyncEnabled(
            self.settings.get("FIFE", "VSync", True))
        self.engine.changeScreenMode(new_mode)
        if not self.view:
            return
        self.camera.setViewPort(
            fife.Rect(0, 0,
                      self.engine.getRenderBackend().getScreenWidth(),
                      self.engine.getRenderBackend().getScreenHeight()))
        self.camera.refresh()
        #PyCEGUIOpenGLRenderer.OpenGLRenderer.restoreTextures(
        #	PyCEGUI.System.getSingleton().getRenderer())
        #PyCEGUI.System.getSingleton().notifyDisplaySizeChanged(PyCEGUI.Sizef(
        #	int(self.settings.get("FIFE", "ScreenResolution", "1024x768").split("x")[0]),
        #	int(self.settings.get("FIFE", "ScreenResolution", "1024x768").split("x")[1])))

    def _pump(self):
        if self.change_res:
            self.changeRes2()
            return
        if self.imagemanager.getMemoryUsed() != self.lastmem:
            print("Memory used by the image manager:",
                  "{:,}".format(self.imagemanager.getMemoryUsed()))
            #memtest.alloc_max_str()
            #memtest.alloc_max_array()
            self.lastmem = self.imagemanager.getMemoryUsed()
        #if self.imagemanager.getMemoryUsed() > 800000000:
        #	self.imagemanager.freeUnreferenced()
        self.gui.pump()
        #if self.world:
        if self.view:
            self.forcePause()
            if self.change_map_name and (self.world.current_map_name !=
                                         self.change_map_name):
                self.changeMap(self.change_map_name)
                #memtest.alloc_max_str()
                #memtest.alloc_max_array()
            elif self.cutscene:
                if not self.cutscene.pump():
                    self.cutscene = None
                    self.gui.hud.show()
                #try:
                #	self.cutscene.pump()
                #except StopIteration:
                #	self.cutscene = None
                #	self.gui.hud.show()
            elif self.combat:
                self.combat.pump()
            elif self.exploration and not self.paused:
                self.exploration.pump(self.real_timeline.last_frame_time)
        #if self.world:
        #	if self.world.visual:
        if self.view:
            self.view.pump()
        self.gui.pump2()
        if self._listener.quitrequested:
            self.quit()
示例#14
0
#print(probleme.nombre_piece_mal_placees(etat_initial))

# Dijkstra
#fonction_score = lambda noeud: noeud.g
fonction_score = lambda noeud: noeud.g

#Greedy

#A*

###############################################
# Exploration (générique)
###############################################

#exploration = Exploration(probleme=probleme, critere=fonction_score)
exploration = Exploration(probleme=probleme, critere=fonction_score)

temps_debut = time.process_time()
chemin = exploration.explorer()
temps_fin = time.process_time()

###############################################
# Résultat
###############################################
print("=====================================================")
etapes = -1
X_rech = []
Y_rech = []
print("État initial :\t" + str(probleme.etat_initial))
if len(chemin) > 0:
    last = None
示例#15
0
 def __init__(self,
              exploration='epsilonGreedy',
              memory=10000,
              discount=0.99,
              uncertainty=True,
              uncertainty_weight=1,
              update_every=200,
              double=True,
              use_distribution=True,
              reward_normalization=False,
              encoder=None,
              hidden_size=40,
              state_difference=True,
              state_difference_weight=1,
              **kwargs) -> None:
     self.uncertainty = uncertainty
     self.hidden_size = hidden_size
     self.network = NetWork(self.hidden_size).to(device)
     self.createEncoder(encoder)
     self.network.hasEncoder = self.hasEncoder
     print("Number of parameters in network:",
           count_parameters(self.network))
     self.criterion = MSELoss()
     self.memory = ReplayBuffer(int(memory))
     self.remember = self.memory.remember()
     self.exploration = Exploration()
     if exploration == 'greedy':
         self.explore = self.exploration.greedy
     elif exploration == 'epsilonGreedy':
         self.explore = self.exploration.epsilonGreedy
     elif exploration == 'softmax':
         self.explore = self.exploration.softmax
     elif exploration == 'epsintosoftmax':
         self.explore = self.exploration.epsintosoftmax
     self.target_network = NetWork(self.hidden_size).to(device)
     self.target_network.hasEncoder = self.hasEncoder
     self.placeholder_network = NetWork(self.hidden_size).to(device)
     self.placeholder_network.hasEncoder = self.hasEncoder
     self.gamma, self.f = discount, 0
     self.update_every, self.double, self.use_distribution = update_every, double, use_distribution
     self.counter = 0
     self.reward_normalization = reward_normalization
     self.state_difference = state_difference
     self.true_state_trace = None
     self.uncertainty_weight = uncertainty_weight
     self.state_difference_weight = state_difference_weight
     if encoder is not None:
         self.optimizer_value = Adam(
             list(self.network.fromEncoder.parameters()) +
             list(self.network.lstm.parameters()) +
             list(self.network.linear.parameters()),
             lr=1e-4,
             weight_decay=1e-5)
     else:
         self.optimizer_value = Adam(list(self.network.color.parameters()) +
                                     list(self.network.conv1.parameters()) +
                                     list(self.network.lstm.parameters()) +
                                     list(self.network.linear.parameters()),
                                     lr=1e-4,
                                     weight_decay=1e-5)
     if self.uncertainty:
         self.optimizer_exploration = Adam(list(
             self.network.exploration_network.parameters()),
                                           lr=1e-4,
                                           weight_decay=1e-5)
     if self.state_difference:
         self.optimizer_state_avoidance = Adam(list(
             self.network.state_difference_network.parameters()),
                                               lr=1e-4,
                                               weight_decay=1e-5)
     self.onpolicy = True
示例#16
0
    def test_exploration_class(self):
        """Test the Exploration class."""
        exploration = Exploration(id='The exploration hash id')

        # A new exploration should have a default title property.
        self.assertEqual(exploration.title, 'New exploration')

        # A new exploration should have a default is_public property.
        self.assertEqual(exploration.is_public, False)

        # An Exploration must have properties 'category' and 'init_state' set.
        with self.assertRaises(BadValueError):
            exploration.put()
        exploration.category = 'The category'
        with self.assertRaises(BadValueError):
            exploration.put()

        # The 'init_state' property must be a valid State.
        with self.assertRaises(BadValueError):
            exploration.init_state = 'The State'
        state = State(id='The state hash id')
        state.put()
        exploration.init_state = state.key

        # The 'states' property must be a list.
        with self.assertRaises(BadValueError):
            exploration.states = 'A string'
        # TODO(emersoj): We should put the initial state in the states list it should not be empty
        exploration.states = []

        # The 'states property must be a list of State keys.
        with self.assertRaises(BadValueError):
            exploration.states = ['A string']
        with self.assertRaises(BadValueError):
            exploration.states = [state]
        exploration.states = [state.key]

        # The 'parameters' property must be a list of Parameter objects.
        with self.assertRaises(BadValueError):
            exploration.parameters = 'A string'
        exploration.parameters = []
        parameter = Parameter(name='theParameter', obj_type='Int')
        with self.assertRaises(BadValueError):
            exploration.parameters = [parameter.key]
        exploration.parameters = [parameter]

        # The 'is_public' property must be a boolean.
        with self.assertRaises(BadValueError):
            exploration.is_public = 'true'
        exploration.is_public = True

        # The 'image_id' property must be a string.
        image = Image(id='The image')
        with self.assertRaises(BadValueError):
            exploration.image_id = image
        with self.assertRaises(BadValueError):
            exploration.image_id = image.key
        exploration.image_id = 'A string'

        # The 'editors' property must be a list of User objects.
        with self.assertRaises(BadValueError):
            exploration.editors = 'A string'
        exploration.editors = []
        with self.assertRaises(BadValueError):
            exploration.editors = ['A string']
        user = User(email='*****@*****.**')
        exploration.editors = [user]

        # Put and Retrieve the exploration.
        exploration.put()
        retrieved_exploration = Exploration.get_by_id('The exploration hash id')
        self.assertEqual(retrieved_exploration.category, 'The category')
        self.assertEqual(retrieved_exploration.init_state, state.key)
        self.assertEqual(retrieved_exploration.title, 'New exploration')
        self.assertEqual(retrieved_exploration.states, [state.key])
        self.assertEqual(retrieved_exploration.parameters, [parameter])
        self.assertEqual(retrieved_exploration.is_public, True)
        self.assertEqual(retrieved_exploration.image_id, 'A string')
        self.assertEqual(retrieved_exploration.editors, [user])

        # The Exploration class has a 'create' class method.
        exploration2 = Exploration.create(user, 'A title', 'A category', 'A exploration_id')
        exploration2.put()

        # The Exploration class has a 'get' class method.
        retrieved_exploration2 = Exploration.get('A exploration_id')
        self.assertEqual(exploration2, retrieved_exploration2)

        # An Exploration has a 'delete' method.
        exploration2.delete()
        with self.assertRaises(Exception):
            retrieved_exploration2 = Exploration.get('A exploration_id')
        # The get() should fail silently when strict == False.
        retrieved_exploration2 = Exploration.get(
            'A exploration_id', strict=False)
        self.assertIsNone(retrieved_exploration2)

        # An Exploration has a 'is_demo_exploration' method.
        demo = Exploration(id='0')
        self.assertEqual(demo.is_demo_exploration(), True)
        notdemo1 = Exploration(id='a')
        self.assertEqual(notdemo1.is_demo_exploration(), False)
        notdemo2 = Exploration(id='abcd')
        self.assertEqual(notdemo2.is_demo_exploration(), False)

        # Ad Exploration has a 'as_yaml' method.
        exploration3 = Exploration.create(user, 'A title', 'A category', 'A different exploration_id')
        self.assertEqual(exploration3.as_yaml(), """Activity 1:
  content: []
  param_changes: []
  widget:
    handlers:
    - name: submit
      rules:
      - dest: Activity 1
        feedback: []
        inputs: {}
        name: Default
        param_changes: []
    params: {}
    sticky: false
    widget_id: Continue
""")