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


Python Game.get_next_state方法代码示例

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


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

示例1: test_get_previous_state

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import get_next_state [as 别名]
 def test_get_previous_state(self):
     game = Game(4, Game.Modes.human_human, Game.DifficultyLevels.easy,
                 True, 5)
     state = (game.mover.board, s.WHITE)
     my_state = game.get_next_state(state, (1, 0))
     game.next_move('a3')
     self.assertEqual(game.get_current_state(), my_state)
     opp_state = game.get_next_state(my_state, (2, 0))
     game.next_move('a2')
     self.assertEqual(game.get_current_state(), opp_state)
     my_prev_state = game.get_previous_state(opp_state, (2, 0))
     self.assertEqual(my_state, my_prev_state)
开发者ID:ElenaArslanova,项目名称:rev,代码行数:14,代码来源:tests.py

示例2: TestMonteCarloAI

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import get_next_state [as 别名]
class TestMonteCarloAI(unittest.TestCase):
    def setUp(self):
        self.game = Game(3, Game.Modes.human_human, Game.DifficultyLevels.hard,
                         True, 5)
        self.ai = MonteCarloAI(self.game, WHITE, Game.DifficultyLevels.hard)
        first_move = (1, 2)
        first_state = Game.get_next_state((self.game.mover.board, WHITE),
                                          first_move)
        self.root_possible_moves = self.game.mover.board.get_moves(WHITE)
        self.root = Node(first_state, first_move,
                         len(self.root_possible_moves))

    def test_get_best_move(self):
        node = Node(self.root.state, (1, 2), 2)
        children = [Node(node.state, (2, 3), 1), Node(node.state, (2, 1), 2)]
        children[0].plays, children[0].wins = 3, 2
        children[1].plays, children[1].wins = 2, 2
        for child in children:
            node.add_child(child)
        self.assertEqual(self.ai.get_best_move(node), children[0].move)
        node.children[0].plays, node.children[0].wins = 2, 1
        self.assertEqual(self.ai.get_best_move(node), children[1].move)

    def test_back_propagate(self):
        node = Node(self.root.state, (1, 2), 2)
        child = Node(node.state, (2, 3), 1)
        child.plays, child.wins = 2, 1
        node.add_child(child)
        self.assertTrue(node.plays == 0)
        self.assertTrue(node.wins == 0)
        self.ai.back_propagate(child, 1)
        self.assertTrue(child.plays == 3)
        self.assertTrue(child.wins == 2)
        self.assertTrue(node.plays == 1)
        self.assertTrue(node.wins == 1)

    def test_get_best_child(self):
        children = [Node(self.game.get_next_state(self.root.state, (1, 2)),
                    (1, 2), 3),
                    Node(self.game.get_next_state(self.root.state, (2, 1)),
                    (2, 1), 3)]
        children[0].plays, children[0].wins = 2, 1
        children[1].plays, children[1].wins = 1, 0
        self.root.plays = 3
        for child in children:
            self.root.add_child(child)
        self.assertEqual(self.ai.get_best_child(self.root), children[1])
开发者ID:ElenaArslanova,项目名称:rev,代码行数:49,代码来源:test_monteCarloAI.py

示例3: test_get_next_state

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import get_next_state [as 别名]
 def test_get_next_state(self):
     game = Game(3, Game.Modes.human_human, Game.DifficultyLevels.easy,
                 True, 5)
     state = (game.mover.board, s.WHITE)
     self.assertEqual(game.mover.board, state[0])
     next_state = game.get_next_state(state, (2, 1))
     self.assertNotEqual(game.mover.board, next_state[0])
     game.mover.board.make_move((2, 1), s.WHITE)
     self.assertEqual(game.mover.board, next_state[0])
开发者ID:ElenaArslanova,项目名称:rev,代码行数:11,代码来源:tests.py

示例4: setUp

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import get_next_state [as 别名]
 def setUp(self):
     self.game = Game(3, Game.Modes.human_human, Game.DifficultyLevels.easy,
                      True, 5)
     first_move = (1, 2)
     first_state = Game.get_next_state(
         (self.game.mover.board, WHITE), first_move)
     self.root_possible_moves = self.game.mover.board.get_moves(WHITE)
     self.root = Node(first_state, first_move,
                      len(self.root_possible_moves))
开发者ID:ElenaArslanova,项目名称:rev,代码行数:11,代码来源:test_node.py

示例5: TestNode

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import get_next_state [as 别名]
class TestNode(unittest.TestCase):
    def setUp(self):
        self.game = Game(3, Game.Modes.human_human, Game.DifficultyLevels.easy,
                         True, 5)
        first_move = (1, 2)
        first_state = Game.get_next_state(
            (self.game.mover.board, WHITE), first_move)
        self.root_possible_moves = self.game.mover.board.get_moves(WHITE)
        self.root = Node(first_state, first_move,
                         len(self.root_possible_moves))

    def test_propagate_completion(self):
        root_moves_to_expand = len(self.root_possible_moves)
        self.assertTrue(self.root.moves_left_to_expand == root_moves_to_expand)
        state = self.game.get_next_state(self.root.state, (2,  1))
        child = Node(state, (2, 1), 3)
        self.root.add_child(child)
        self.assertTrue(child.moves_left_to_expand > 0)
        child_moves_to_expand = child.moves_left_to_expand
        child.propagate_completion()
        self.assertTrue(child.moves_left_to_expand ==
                        child_moves_to_expand - 1)
        self.assertTrue(self.root.moves_left_to_expand == root_moves_to_expand)

    def test_add_child(self):
        child = self.get_child(self.root)
        self.assertFalse(self.root.children)
        self.root.add_child(child)
        self.assertTrue(len(self.root.children) == 1)
        self.assertEqual(self.root.children[0], child)

    def test_has_children(self):
        child = self.get_child(self.root)
        self.assertFalse(child.has_children())
        self.root.add_child(child)
        self.assertTrue(self.root.has_children())

    def get_child(self, node):
        possible_moves = self.game.mover.board.get_moves(node.state[1])
        move = choice(possible_moves)
        state = Game.get_next_state(self.root.state, move)
        return Node(state, move, len(state[0].get_moves(state[1])))
开发者ID:ElenaArslanova,项目名称:rev,代码行数:44,代码来源:test_node.py

示例6: get_child

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import get_next_state [as 别名]
 def get_child(self, node):
     possible_moves = self.game.mover.board.get_moves(node.state[1])
     move = choice(possible_moves)
     state = Game.get_next_state(self.root.state, move)
     return Node(state, move, len(state[0].get_moves(state[1])))
开发者ID:ElenaArslanova,项目名称:rev,代码行数:7,代码来源:test_node.py


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