本文整理汇总了Python中dice.Dice.add_roll方法的典型用法代码示例。如果您正苦于以下问题:Python Dice.add_roll方法的具体用法?Python Dice.add_roll怎么用?Python Dice.add_roll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dice.Dice
的用法示例。
在下文中一共展示了Dice.add_roll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Table
# 需要导入模块: from dice import Dice [as 别名]
# 或者: from dice.Dice import add_roll [as 别名]
class Table(object):
def __init__(self, minimum, players, max_rolls, input_rolls):
self.players = players
self.dice = Dice()
self.input_rolls = input_rolls
self.minimum = minimum
self.max_rolls = max_rolls
# metadata
self.shooters = 1
self.rolls = 1
self.longest_roll = 0
self.points_made = 0
self.seven_outs = 0
self.come_out_naturals = 0
self.come_out_craps = 0
self.roll_history = []
self.roll_status = (0, 0, None)
self.table_status = []
def simulate(self):
while self.continue_playing():
self.shoot()
for player in self.players:
if self.continue_betting(player):
log = Log()
player.strategy(self)
log.pre_roll(self, player)
self.roll_status = self.evaluate_roll(player)
log.post_roll(self, player)
player.catalogue(self, log)
self.table_status.append(self.roll_status[2])
self.assess_post_roll()
for player in self.players:
player.collect_wager()
print player.__doc__
player.tabulate()
# self.log(player)
def evaluate_roll(self, player):
if player.point is None:
if self.dice.total in NATURALS:
delta = player.bet.assess_naturals(self.dice, player)
elif self.dice.total in CRAPS:
delta = player.bet.assess_craps(self.dice, player)
elif self.dice.total in BOXES:
delta = player.bet.assess_box(self.dice, player)
else:
raise Exception('Invalid Roll')
else:
if self.dice.total == SEVEN:
delta = player.bet.assess_seven_out(player)
elif self.dice.total == YOLEVEN:
delta = player.bet.assess_yoleven(self.dice, player)
elif self.dice.total in CRAPS:
delta = player.bet.assess_craps(self.dice, player)
elif self.dice.total in BOXES:
delta = player.bet.assess_box(self.dice, player)
else:
raise Exception('Invalid Roll')
player.log_bankroll()
return delta
def log(self, player):
line_plot(player.bankroll_history)
# pie_chart([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], self.dice.history.values())
# bar_chart([2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], self.dice.history.values(), 11)
def assess_post_roll(self):
if self.table_status and len(set(self.table_status)) != 1:
raise Exception('Invalid Roll Calculation')
self.rolls += 1
if self.table_status[0] == 'POINT':
self.points_made += 1
elif self.table_status[0] == 'SEVEN_OUT':
self.update_seven_out_stats()
elif self.table_status[0] == 'NATURALS':
self.come_out_naturals += 1
elif self.table_status[0] == 'CRAPS':
self.come_out_craps += 1
self.table_status = []
def shoot(self):
if self.input_rolls is None:
self.dice.roll()
else:
self.dice.add_roll(self.input_rolls[self.rolls - 1])
return self.dice
def continue_betting(self, player):
if self.input_rolls is None:
if player.bankroll <= 0:
return False
else:
# wait for the current shooter to seven-out
#.........这里部分代码省略.........