コード例 #1
0
ファイル: worlds.py プロジェクト: zwcdp/ParlAI
    def parley(self):
        """Alternate taking turns, until both agents have made a choice
        (indicated by a turn starting with <selection>)
        """
        if self.first_turn:
            # Use NegotiationTeacher to load data for us
            data = self.task.episodes[self.num_negotiations %
                                      len(self.task.episodes)].strip().split()
            self.num_negotiations += 1

            for agent, tag in zip(self.agents, ['input', 'partner_input']):
                (book_cnt, book_val, hat_cnt, hat_val, ball_cnt,
                 ball_val) = get_tag(data, tag)
                action = {}
                action['text'] = WELCOME_MESSAGE.format(book_cnt=book_cnt,
                                                        book_val=book_val,
                                                        hat_cnt=hat_cnt,
                                                        hat_val=hat_val,
                                                        ball_cnt=ball_cnt,
                                                        ball_val=ball_val)

                action['items'] = {
                    "book_cnt": book_cnt,
                    "book_val": book_val,
                    "hat_cnt": hat_cnt,
                    "hat_val": hat_val,
                    "ball_cnt": ball_cnt,
                    "ball_val": ball_val
                }

                agent.observe(validate(action))
            self.first_turn = False
        else:
            self.turns += 1

            for _index, agent in enumerate(self.agents):
                if agent in self.choices:
                    # This agent has already made a choice
                    continue

                try:
                    act = agent.act(timeout=None)
                except TypeError:
                    act = agent.act()  # not MTurkAgent

                for other_agent in self.agents:
                    if other_agent != agent:
                        other_agent.observe(validate(act))

                if act["text"].startswith("<selection>") and self.turns > 1:
                    # Making a choice
                    self.choices[agent] = act["text"]
                    self.selection = True
                    if len(self.choices) == len(self.agents):
                        self.first_turn = True
                        self.episodeDone = True
                elif act['episode_done']:
                    # Action is not selection but episode ended due to
                    # disconnection or timeout or returned hit
                    self.episodeDone = True
コード例 #2
0
ファイル: worlds.py プロジェクト: ahiroto/ParlAI
    def parley(self):
        """Alternate taking turns, until both agents have made a choice
        (indicated by a turn starting with <selection>)
        """
        if self.first_turn:
            # Use NegotiationTeacher to load data for us
            data = self.task.episodes[
                self.num_negotiations % len(self.task.episodes)
            ].strip().split()
            self.num_negotiations += 1

            for agent, tag in zip(self.agents, ['input', 'partner_input']):
                (book_cnt, book_val, hat_cnt,
                 hat_val, ball_cnt, ball_val) = get_tag(data, tag)
                action = {}
                action['text'] = WELCOME_MESSAGE.format(
                    book_cnt=book_cnt, book_val=book_val,
                    hat_cnt=hat_cnt, hat_val=hat_val,
                    ball_cnt=ball_cnt, ball_val=ball_val)

                action['items'] = {"book_cnt": book_cnt, "book_val": book_val,
                                   "hat_cnt": hat_cnt, "hat_val": hat_val,
                                   "ball_cnt": ball_cnt, "ball_val": ball_val}

                agent.observe(validate(action))
            self.first_turn = False
        else:
            self.turns += 1

            for _index, agent in enumerate(self.agents):
                if agent in self.choices:
                    # This agent has already made a choice
                    continue

                try:
                    act = agent.act(timeout=None)
                except TypeError:
                    act = agent.act()  # not MTurkAgent

                for other_agent in self.agents:
                    if other_agent != agent:
                        other_agent.observe(validate(act))

                if act["text"].startswith("<selection>") and self.turns > 1:
                    # Making a choice
                    self.choices[agent] = act["text"]
                    self.selection = True
                    if len(self.choices) == len(self.agents):
                        self.first_turn = True
                        self.episodeDone = True
                elif act['episode_done']:
                    # Action is not selection but episode ended due to disconnection or timeout or returned hit
                    self.episodeDone = True