本文整理汇总了Python中Game.Game.play_round方法的典型用法代码示例。如果您正苦于以下问题:Python Game.play_round方法的具体用法?Python Game.play_round怎么用?Python Game.play_round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game.Game
的用法示例。
在下文中一共展示了Game.play_round方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTwoPlayer
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import play_round [as 别名]
class TestTwoPlayer(unittest.TestCase):
def setUp(self):
self.players = [FakePlayer(), FakePlayer()]
self.game = Game(self.players, verbose=False)
def test_two_turns(self):
# Starting conditions in game engine
self.assertEqual(self.game.players[0].food, 300)
self.assertEqual(self.game.players[1].rep, 0.0)
# Make sure data sent to player classes is right
# Note that after this point, self.players[0] is not
# necessarily self.game.players[0] because of shuffling
self.game.play_round()
self.assertEqual(self.players[0].food, 302)
self.assertEqual(self.players[0].rep, 0)
self.game.play_round()
self.assertEqual(self.players[0].food, 304)
self.assertEqual(self.players[0].rep, 1.0)
# Test that Game is sending the correct arguments to BasePlayers
self.assertEqual(self.players[0].hunt_choices_args,
(2, 302, 1.0, 1, [1.0]))
self.assertEqual(self.players[0].hunt_outcomes_args, ([0],))
self.assertEqual(self.players[0].round_end_args, (2, 1, 2))
# Test that Game stayed synched with Player.
self.assertEqual(self.players[0].food, self.game.players[0].food)
self.assertEqual(self.players[0].rep, self.game.players[0].rep)
def test_full_game(self):
#Make sure the game runs to completion without errors
self.game.play_game()
def test_m(self):
self.assertEqual(self.game.calculate_m(), 1)
self.assertEqual(self.game.m_bonus, 2)
示例2: Pushover
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import play_round [as 别名]
stdinFileDesc = sys.stdin.fileno()
# save stdin's tty attributes so I can reset it later
oldStdinTtyAttr = termios.tcgetattr(stdinFileDesc)
if __name__ == '__main__':
# introduce some players in the game
players = [Player(), Pushover(), Freeloader(), Alternator(), MaxRepHunter(), Random(.2),
Random(.8), TitForTatter()]
game = Game(players)
print('==== Round-stepped game, press q to quit and any other key to continue ====\n')
try:
print('Press any key to exit...')
while True:
try:
game.play_round()
except StopIteration:
break
# set the input mode of stdin so that it gets added to char by char rather than line by line
tty.setraw(stdinFileDesc)
# read 1 byte from stdin (indicating that a key has been pressed)
c = sys.stdin.read(1)
# reset stdin to its normal behavior
termios.tcsetattr(stdinFileDesc, termios.TCSADRAIN, oldStdinTtyAttr)
if c == 'q':
print('\n==== Game finished by the user, goodbye! ====')
break
finally:
# reset stdin to its normal behavior
termios.tcsetattr(stdinFileDesc, termios.TCSADRAIN, oldStdinTtyAttr)