当前位置: 首页>>代码示例>>Python>>正文


Python CallHistory.from_string方法代码示例

本文整理汇总了Python中core.callhistory.CallHistory.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python CallHistory.from_string方法的具体用法?Python CallHistory.from_string怎么用?Python CallHistory.from_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.callhistory.CallHistory的用法示例。


在下文中一共展示了CallHistory.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_identifier

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def test_from_identifier(self):
     self.assertEqual(CallHistory.from_identifier('E:EW:P').identifier(), CallHistory.from_string('P', 'E', 'E-W').identifier())
     # Test that from_identifier is forgiving of a missing trailing colon
     self.assertEqual(CallHistory.from_identifier('E:EW:').identifier(), CallHistory.from_string('', 'E', 'E-W').identifier())
     self.assertEqual(CallHistory.from_identifier('E:EW').identifier(), CallHistory.from_string('', 'E', 'E-W').identifier())
     # Test that from_identifier is forgiving of a trailing comma.
     self.assertEqual(CallHistory.from_identifier('N:NO:P,').calls_string(), "P")
开发者ID:samfin,项目名称:saycbridge,代码行数:9,代码来源:test_callhistory.py

示例2: test_bidding_rounds

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def test_bidding_rounds(self):
     self.assertEquals(CallHistory.from_string("")._bidding_rounds_count(), 0)
     self.assertEquals(CallHistory.from_string("").bidding_rounds(last_call_only=True), [['?', None, None, None]])
     self.assertEquals(CallHistory.from_string("").bidding_rounds(last_call_only=True, mark_to_bid=False), [])
     self.assertEquals(CallHistory.from_string("P").bidding_rounds(last_call_only=True), [['P', '?', None, None]])
     self.assertEquals(CallHistory.from_string("P P").bidding_rounds(last_call_only=True), [['P', 'P', '?', None]])
     self.assertEquals(CallHistory.from_string("P P", dealer_string="E").bidding_rounds(last_call_only=True), [[None, 'P', 'P', '?']])
     self.assertEquals(CallHistory.from_string("P P", dealer_string="W").bidding_rounds(last_call_only=True), [[None, None, None, 'P'], ['P', '?', None, None]])
     self.assertEquals(CallHistory.from_string("2H P 3H P").bidding_rounds(last_call_only=True), [['2H', 'P', '3H', 'P'], ['?', None, None, None]])
     self.assertEquals(CallHistory.from_string("P P P P").bidding_rounds(last_call_only=True), [['P', 'P', 'P', 'P']])
     self.assertEquals(CallHistory.from_string("P P P P", dealer_string="E").bidding_rounds(last_call_only=True), [[None, 'P', 'P', 'P'], ['P', None, None, None]])
开发者ID:samfin,项目名称:saycbridge,代码行数:13,代码来源:test_callhistory.py

示例3: from_expectation_tuple_in_group

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def from_expectation_tuple_in_group(cls, expectation, test_group):
     hand_string = expectation[0]
     assert '.' in hand_string, "_split_expectation expectes C.D.H.S formatted hands, missing '.': %s" % hand_string
     expected_call = Call.from_string(expectation[1])
     history_string = expectation[2] if len(expectation) > 2 else ""
     vulnerability_string = expectation[3] if len(expectation) > 3 else None
     hand = Hand.from_cdhs_string(hand_string)
     call_history = CallHistory.from_string(history_string, vulnerability_string=vulnerability_string)
     return cls(test_group, hand, call_history, expected_call)
开发者ID:abortz,项目名称:saycbridge,代码行数:11,代码来源:harness.py

示例4: test_copy_with_partial_history

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def test_copy_with_partial_history(self):
     history = CallHistory.from_string("P P 1N P P P")
     self.assertEquals(len(history.calls), 6)
     self.assertEquals(len(history.copy_with_partial_history(0).calls), 0)
     self.assertEquals(len(history.copy_with_partial_history(2).calls), 2)
     self.assertEquals(len(history.copy_with_partial_history(-2).calls), 4)
     partial_history = history.copy_with_partial_history(3)
     self.assertEquals(len(history.calls), 6)
     self.assertEquals(len(partial_history.calls), 3)
     partial_history.calls.append(None)  # Invalid, but fine for testing.
     self.assertEquals(len(history.calls), 6)
     self.assertEquals(len(partial_history.calls), 4)
开发者ID:samfin,项目名称:saycbridge,代码行数:14,代码来源:test_callhistory.py

示例5: test_last_to_call

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def test_last_to_call(self):
     self.assertEquals(CallHistory.from_string("").last_to_call(), None)
     self.assertEquals(CallHistory.from_string("P").last_to_call(), NORTH)
     self.assertEquals(CallHistory.from_string("1N P").last_to_call(), EAST)
     self.assertEquals(CallHistory.from_string("1N P 2C").last_to_call(), SOUTH)
     self.assertEquals(CallHistory.from_string("1N P 2C P").last_to_call(), WEST)
     self.assertEquals(CallHistory.from_string("1N P 2C P 2D").last_to_call(), NORTH)
开发者ID:samfin,项目名称:saycbridge,代码行数:9,代码来源:test_callhistory.py

示例6: test_is_passout

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def test_is_passout(self):
     self.assertEquals(CallHistory.from_string("").is_passout(), False)
     self.assertEquals(CallHistory.from_string("P").is_passout(), False)
     self.assertEquals(CallHistory.from_string("P P").is_passout(), False)
     self.assertEquals(CallHistory.from_string("P P P").is_passout(), False)
     self.assertEquals(CallHistory.from_string("P P P P").is_passout(), True)
     self.assertEquals(CallHistory.from_string("P 1N P P P").is_passout(), False)
开发者ID:samfin,项目名称:saycbridge,代码行数:9,代码来源:test_callhistory.py

示例7: _board_from_request

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
    def _board_from_request(self):
        board_number = int(self.request.get('number'))
        vulnerability_string = self.request.get('vunerability')
        hand_strings = map(str, [
            self.request.get('deal[north]'),
            self.request.get('deal[east]'),
            self.request.get('deal[south]'),
            self.request.get('deal[west]'),
        ])

        deal = Deal.from_string(' '.join(hand_strings))
        dealer_char = self.request.get('dealer')
        calls_string = self.request.get('calls_string', '')
        history = CallHistory.from_string(calls_string, dealer_char, vulnerability_string)
        return Board(board_number, deal, history)
开发者ID:abortz,项目名称:saycbridge,代码行数:17,代码来源:autobid_handler.py

示例8: _board_from_request

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
    def _board_from_request(self):
        board_number = int(self.request.get('number'))
        vulnerability_string = self.request.get('vunerability')
        hand_strings = map(str, [
            self.request.get('deal[north]'),
            self.request.get('deal[east]'),
            self.request.get('deal[south]'),
            self.request.get('deal[west]'),
        ])

        deal = Deal.from_string(' '.join(hand_strings))
        dealer_char = self.request.get('dealer')
        # Note: We keep bids_string around to I can test old requests.
        calls_string = self.request.get('calls_string') or self.request.get('bids_string') or ''
        history = CallHistory.from_string(calls_string, dealer_char, vulnerability_string)
        return Board(board_number, deal, history)
开发者ID:samfin,项目名称:saycbridge,代码行数:18,代码来源:bidder_handler.py

示例9: _board_from_request

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
    def _board_from_request(self):
        board_number = int(self.request.get("number"))
        vulnerability_string = self.request.get("vunerability")
        hand_strings = map(
            str,
            [
                self.request.get("deal[north]"),
                self.request.get("deal[east]"),
                self.request.get("deal[south]"),
                self.request.get("deal[west]"),
            ],
        )

        deal = Deal.from_string(" ".join(hand_strings))
        dealer_char = self.request.get("dealer")
        # Note: We keep bids_string around to I can test old requests.
        calls_string = self.request.get("calls_string") or self.request.get("bids_string") or ""
        history = CallHistory.from_string(calls_string, dealer_char, vulnerability_string)
        return Board(board_number, deal, history)
开发者ID:pdm55,项目名称:saycbridge,代码行数:21,代码来源:bidder_handler.py

示例10: get

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
    def get(self):
        interpreter = InterpreterProxy()
        calls_string = self.request.get('calls_string') or ''
        dealer_char = self.request.get('dealer') or ''
        vulnerability_string = self.request.get('vulnerability') or ''
        call_history = CallHistory.from_string(calls_string, dealer_char, vulnerability_string)

        knowledge_string, rule = interpreter.knowledge_string_and_rule_for_last_call(call_history)
        explore_dict = {
            'knowledge_string': knowledge_string,
        }
        explore_dict.update(self._json_from_rule(rule, call_history.calls[-1]))
        self.response.headers["Content-Type"] = "application/json"
        self.response.headers["Cache-Control"] = "public"

        expires_date = datetime.datetime.utcnow() + datetime.timedelta(days=1)
        expires_str = expires_date.strftime("%d %b %Y %H:%M:%S GMT")
        self.response.headers.add_header("Expires", expires_str)

        self.response.out.write(json.dumps(explore_dict))
开发者ID:samfin,项目名称:saycbridge,代码行数:22,代码来源:explore_handler.py

示例11: get

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
    def get(self):
        interpreter = BidInterpreter()
        calls_string = self.request.get('calls_string') or ''
        dealer_char = self.request.get('dealer') or ''
        vulnerability_string = self.request.get('vulnerability') or ''
        history = CallHistory.from_string(calls_string, dealer_char, vulnerability_string)

        existing_knowledge, knowledge_builder = interpreter.knowledge_from_history(history)
        matched_rules = knowledge_builder.matched_rules()
        explore_dict = {
            'knowledge_string': existing_knowledge.rho.pretty_one_line(include_last_call_name=False) if existing_knowledge else None,
        }
        explore_dict.update(self._json_from_rule(matched_rules[-1], history.calls[-1]))
        self.response.headers["Content-Type"] = "application/json"
        self.response.headers["Cache-Control"] = "public"

        expires_date = datetime.datetime.utcnow() + datetime.timedelta(days=1)
        expires_str = expires_date.strftime("%d %b %Y %H:%M:%S GMT")
        self.response.headers.add_header("Expires", expires_str)

        self.response.out.write(json.dumps(explore_dict))
开发者ID:pdm55,项目名称:saycbridge,代码行数:23,代码来源:explore_handler.py

示例12: _assert_opener

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def _assert_opener(self, history_string, dealer, opener):
     self.assertEquals(CallHistory.from_string(history_string, position_char(dealer)).opener(), opener)
开发者ID:samfin,项目名称:saycbridge,代码行数:4,代码来源:test_callhistory.py

示例13: history_iglob

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
    def history_iglob(self, glob_string):
        glob_string = self._normalize_glob_string(glob_string)
        glob_string, last_token = self._split_before_last_token(glob_string)
        histories = self.history_iglob(glob_string) if self._has_wildcards(glob_string) else [CallHistory.from_string(glob_string)]
        call_generator = self._match_pattern_over if self._has_wildcards(last_token) else self._glob_helper

        for history in histories:
            # If we already have 3 passes in a row, there is nothing more we an add to this history.
            if history.is_complete():
                continue
            for call in call_generator(history, last_token):
                yield history.copy_appending_call(call)
开发者ID:abortz,项目名称:saycbridge,代码行数:14,代码来源:callexplorer.py

示例14: _rule_for_last_call

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def _rule_for_last_call(self, call_history_string):
     history = CallHistory.from_string(call_history_string)
     knowledge, knowledge_builder = self.interpreter.knowledge_from_history(history)
     matched_rules = knowledge_builder.matched_rules()
     return matched_rules[-1]
开发者ID:samfin,项目名称:saycbridge,代码行数:7,代码来源:interpreter_unittest.py

示例15: _hand_knowledge_from_last_call

# 需要导入模块: from core.callhistory import CallHistory [as 别名]
# 或者: from core.callhistory.CallHistory import from_string [as 别名]
 def _hand_knowledge_from_last_call(self, call_history_string):
     history = CallHistory.from_string(call_history_string)
     knowledge, _ = self.interpreter.knowledge_from_history(history)
     return knowledge.rho
开发者ID:samfin,项目名称:saycbridge,代码行数:6,代码来源:interpreter_unittest.py


注:本文中的core.callhistory.CallHistory.from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。