コード例 #1
0
    def setup(self,
              graph,
              graph_config,
              main_app,
              max_turns,
              button_presses,
              number=-1,
              button_ratio=0.2,
              real_user=True):
        """
        Does a single run of a game - 3 stages:
        Graph learning - the main game section.
        Questionnaire - A list of questions about the graph
        Results - The result screen and summary of the data.
        :param graph_config:
        :param real_user: Bool. False if machine player
        :param number: The game number
        :param main_app: The main who called this screen
        :param max_turns: Number of steps for the game
        :param graph: The graph used in this specific game
        """
        # Init
        self.game_number = number
        self.main_app = main_app
        self.real_user = real_user
        self.score = 0

        self.graph = graph
        self.max_turns = max_turns
        main_app.discovered_graph = None
        self.graph_config = graph_config
        self.button_presses = button_presses
        self.button_ratio = button_ratio

        self.graph_game = GraphTabletDisplay(self)
コード例 #2
0
    def run_q_player(self, graph_file_path, log_file_path):
        Utils.read_game_config_file(CONFIG_FILE_PATH)
        Utils.read_graph_config_file(GRAPH_CONFIG_PATH)
        Utils.image_folder = path.join("..", Utils.image_folder)

        log.setLevel(Utils.game_config_data['Default']['log_level'])
        session_length = 1000

        graph = load_py_graph(graph_file_path)
        q_matrix = QMatrix(action_space=4, max_steps=int(Utils.game_config_data['Default']['max_turns']), nodes_in_graph=len(graph.node_list))

        with open(log_file_path,'w') as f:
            f.write("episode, score\n")
            for i in range(session_length):
                dummy_screen = DummyScreen(graph)
                game = GraphTabletDisplay(dummy_screen)
                data_handler = GameDataHandler(GRAPH_CONFIG_PATH, graph.size)
                data_handler.add_view_to_db(game.get_info_from_screen())

                rw = 0
                game.press_button(self.auto_first_press + 1)
                data_handler.add_view_to_db(game.get_info_from_screen())
                q_matrix.reinit(known_nodes=len(data_handler.get_real_nodes()))
                for j in range(1, int(Utils.game_config_data['Default']['max_turns'])):
                    log.debug("doing a step {}/{}".format(j, Utils.game_config_data['Default']['max_turns']))
                    btn = q_matrix.choose_action_epsilon_greedy()
                    game.press_button(btn + 1)
                    data_handler.add_view_to_db(game.get_info_from_screen())
                    rw = q_matrix.update_matrix(num_nodes=len(data_handler.get_real_nodes()), current_step=btn)
                log.info("Q session {}:{} - reword:{}".format(i, session_length, rw))
                f.write("{},{}\n".format(i + 1, rw))
コード例 #3
0
ファイル: GraphValidator.py プロジェクト: Omerss/GraphGame
def run_buttons_on_graph(graph, buttons):
    #log = logging.getLogger()
    #log.setLevel(Utils.game_config_data['Default']['log_level'])
    dummy_screen = DummyScreen(graph)
    game = GraphTabletDisplay(dummy_screen)
    #game.run()
    data_handler = GameDataHandler(GRAPH_CONFIG_FILE, graph.size)
    data_handler.add_view_to_db(game.get_info_from_screen())
    for i in range(int(Utils.game_config_data['Default']['max_turns'])):
        #log.debug("doing a step {}/{}".format(i, Utils.game_config_data['Default']['max_turns']))
        game.press_button(int(buttons[i]))
        data_handler.add_view_to_db(game.get_info_from_screen())

    # print ("known nodes-"+str(data_handler.get_number_of_known_nodes())+"\n")
    answer = (data_handler.get_number_of_known_nodes() == len(graph.node_list))
    return answer, data_handler.get_number_of_known_nodes()