本文整理汇总了Python中game_state.GameState.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.from_string方法的具体用法?Python GameState.from_string怎么用?Python GameState.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game_state.GameState
的用法示例。
在下文中一共展示了GameState.from_string方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_serialization
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_serialization(self):
for s in self.SERIALIZATION_FIXTURES:
self.assertEqual(repr(GameState.from_string(s)), s, "Invalid deserialize & serialize transformation")
for _ in range(10):
game_state = GameStateFactory.build_with_creatures()
s = repr(game_state)
self.assertEqual(repr(GameState.from_string(s)), s, "Invalid deserialize & serialize transformation")
示例2: test_equality
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_equality(self):
game_state1 = GameStateFactory.build_with_creatures(9)
game_state2 = GameStateFactory.build_with_creatures(8)
self.assertNotEqual(game_state1, game_state2)
game_state2.battleground = game_state1.battleground
self.assertEqual(game_state1, game_state2)
game_state1 = GameState.from_string("20/20 (1/0): vs 1/2")
game_state2 = GameState.from_string("20/20 (1/0): vs 1/2")
self.assertEqual(game_state1, game_state2)
示例3: test_get_next_states
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_get_next_states(self):
for fixture in self.NEXT_STATES_FIXTURES:
game_state = GameState.from_string(fixture[0])
expected_next_states = fixture[1]
iterator = self.strategy.get_next_states(game_state)
next_states = map(repr, iterator)
self.assertEqual(set(expected_next_states), set(next_states),
'incorrect get_next_states for %r' % game_state)
示例4: test_dfs_walk
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_dfs_walk(self):
strategy = BruteForceStrategy()
for game_state_string, expected_outcome in self.GET_OUTCOME_TESTS:
game_state = GameState.from_string(game_state_string)
dfs_walk = DFSWalk(strategy)
outcome = dfs_walk.walk(game_state)
self.assertEqual(outcome, expected_outcome,
'incorrect outcome for %s' % game_state)
示例5: main
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def main():
string = sys.argv[1]
print '=== Analyzing GameTree for %s ===' % string
root = GameState.from_string(string)
strategy = BruteForceStrategy()
dfs_walk = DFSWalk(strategy)
outcome = dfs_walk.walk(root)
print 'Outcome of %s is %+d' % (root, outcome)
print 'Iterated through %d nodes' % len(dfs_walk.visited)
示例6: test_is_over
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_is_over(self):
game_state = GameState.from_string("20/20 (0/0): vs ")
self.assertFalse(game_state.is_over)
with self.assertRaises(ValueError):
game_state.outcome
game_state = GameState.from_string("0/20 (0/0): vs ")
self.assertTrue(game_state.is_over)
self.assertEqual(game_state.outcome, Outcome.Loss)
game_state = GameState.from_string("1/-2 (0/0): vs ")
self.assertTrue(game_state.is_over)
self.assertEqual(game_state.outcome, Outcome.Win)
game_state = GameState.from_string("1/-2 (0/1): vs ")
self.assertTrue(game_state.is_over)
self.assertEqual(game_state.outcome, Outcome.Loss)
game_state = GameState.from_string("0/0 (0/0): vs ")
self.assertTrue(game_state.is_over)
self.assertEqual(game_state.outcome, Outcome.Draw)
示例7: _prepare_game_state
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def _prepare_game_state(self, string):
game_state = GameState.from_string(string)
uids = [t[0] for t in game_state.battleground.creatures_with_uids]
uids.sort()
uids.insert(0, game_state)
return uids
示例8: test_untap
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_untap(self):
game_state = GameState.from_string("20/20 (0/0): 2/3 (T), 4/6 (T) vs ")
game_state.untap()
expected_state = "20/20 (0/0): 2/3, 4/6 vs "
self.assertEqual(repr(game_state), expected_state)
示例9: test_hashable
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def test_hashable(self):
string = "20/20 (1/0): vs 1/2"
S = set()
S.add(GameState.from_string(string))
game_state = GameState.from_string(string)
self.assertIn(game_state, S)
示例10: assertGameState
# 需要导入模块: from game_state import GameState [as 别名]
# 或者: from game_state.GameState import from_string [as 别名]
def assertGameState(self, game_state, expected_state_string):
expected_game_state = GameState.from_string(expected_state_string)
self.assertEqual(game_state, expected_game_state)