本文整理汇总了Python中game.game.Game.score方法的典型用法代码示例。如果您正苦于以下问题:Python Game.score方法的具体用法?Python Game.score怎么用?Python Game.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game.game.Game
的用法示例。
在下文中一共展示了Game.score方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBoard
# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import score [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)
示例2: SpinnyStrategy
# 需要导入模块: from game.game import Game [as 别名]
# 或者: from game.game.Game import score [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))