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


Python Game.board方法代码示例

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


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

示例1: TestBoard

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import board [as 别名]
class TestBoard(unittest.TestCase):
    def setUp(self):
        self.basic_game = Game(board=None, rnd=random.Random(1))

    def test_constructor(self):
        self.assertEqual(self.basic_game.score(), 0)
        game = Game(rnd=random.Random(1))
        self.assertEqual(game.board(), self.basic_game.board())

    def test_smash(self):
        # This doesn't comprehensively test smashing because
        # the tests for Board mostly did that already.
        for direction in DIRECTIONS:
            board = Board()
            board = board.update((1, 1), 2)
            game = Game(rnd=random.Random(1), board=board)
            self.assertTrue(game.smash(direction))
            self.assertEqual(game.board()[1, 1], 0)
        for direction in DIRECTIONS:
            board = Board()
            board = board.update((0, 0), 2)
            game = Game(rnd=random.Random(1), board=board)
            if direction in {UP, LEFT}:
                self.assertFalse(game.smash(direction))
            else:
                self.assertTrue(game.smash(direction))
                self.assertEqual(game.board()[0, 0], 0)
开发者ID:ggould256,项目名称:twentyfortyeight,代码行数:29,代码来源:test_game.py

示例2: test_smash

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import board [as 别名]
 def test_smash(self):
     # This doesn't comprehensively test smashing because
     # the tests for Board mostly did that already.
     for direction in DIRECTIONS:
         board = Board()
         board = board.update((1, 1), 2)
         game = Game(rnd=random.Random(1), board=board)
         self.assertTrue(game.smash(direction))
         self.assertEqual(game.board()[1, 1], 0)
     for direction in DIRECTIONS:
         board = Board()
         board = board.update((0, 0), 2)
         game = Game(rnd=random.Random(1), board=board)
         if direction in {UP, LEFT}:
             self.assertFalse(game.smash(direction))
         else:
             self.assertTrue(game.smash(direction))
             self.assertEqual(game.board()[0, 0], 0)
开发者ID:ggould256,项目名称:twentyfortyeight,代码行数:20,代码来源:test_game.py

示例3: add_n_examples

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import board [as 别名]
    def add_n_examples(self, strategy, rnd, n,
                       starting_positions_dataset=None):
        """Runs games and adds them to the dataset until at least @p n
        examples have been added.  Returns the number of examples added.

        If @p starting_positions_dataset is set, games will be started from
        a randomly selected position from that dataset rather than from a
        blank board."""
        print("Adding", n, "examples to dataset.")
        added = 0
        while added < n:
            starting_game = None
            if starting_positions_dataset:
                random_position = starting_positions_dataset.nth_example(
                    rnd.randint(0,
                                starting_positions_dataset.num_examples() - 1))
                starting_game = Game(Board.from_vector(random_position))
                if not starting_game.board().can_move():
                    continue
            num_added = self.add_game(strategy, rnd, starting_game)
            if (added // 10000) != ((num_added + added) // 10000):
                print("Added %d so far..." % (num_added + added))
            added += num_added
        return added
开发者ID:ggould256,项目名称:twentyfortyeight,代码行数:26,代码来源:data.py

示例4: test_constructor

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import board [as 别名]
 def test_constructor(self):
     self.assertEqual(self.basic_game.score(), 0)
     game = Game(rnd=random.Random(1))
     self.assertEqual(game.board(), self.basic_game.board())
开发者ID:ggould256,项目名称:twentyfortyeight,代码行数:6,代码来源:test_game.py

示例5: SpinnyStrategy

# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import board [as 别名]
    strategy = None
    if args.strategy == "spinny":
        strategy = SpinnyStrategy()
    elif args.strategy == "random":
        strategy = RandomStrategy()
    else:
        from strategy.nn.nn_strategy import ModelStrategy
        strategy = ModelStrategy(args.strategy, verbose_period=5000)

    total = 0
    for i in range(args.number_of_games):
        game = Game()
        running = True
        while running:
            turn_outcome = game.do_turn(
                strategy.get_move(game.board(), game.score()))
            if args.verbose:
                game.pretty_print()
            running = (turn_outcome != GAMEOVER)
        strategy.notify_outcome(game.board(), game.score())
        if not args.summary:
            print(game.score())
        total += game.score()
        if not (i % 25):
            print("...", i, "/", args.number_of_games)
    if args.summary:
        print("Strategy %s had average score %f after %d games" %
              (args.strategy,
               (total / args.number_of_games), args.number_of_games))
开发者ID:ggould256,项目名称:twentyfortyeight,代码行数:31,代码来源:demo.py


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