本文整理汇总了Python中bag.Bag.num_letters_left方法的典型用法代码示例。如果您正苦于以下问题:Python Bag.num_letters_left方法的具体用法?Python Bag.num_letters_left怎么用?Python Bag.num_letters_left使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bag.Bag
的用法示例。
在下文中一共展示了Bag.num_letters_left方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from bag import Bag [as 别名]
# 或者: from bag.Bag import num_letters_left [as 别名]
class Game:
"""Game where everything comes together"""
def __init__(self, players, computers, dictionary='sowpods.txt'):
"""Sets up initial game state with player names given"""
self.bag = Bag()
self.board = Board()
self.player_order = players + sorted(computers.keys())
self.computers = computers
self.players = {}
for player in players:
self.players[player] = Player(player,self)
for computer in computers:
self.players[computer] = AI(computer, self, computers[computer])
self.turn = 0
self.played = False
self.dictionary = Dictionary(dictionary)
def display(self, compact=True):
"""displays home screen with board and player scores"""
if compact:
self.board.display_compact()
else:
self.board.display()
for player in self.players.values():
player.display()
print ''
print "Letters left: ", self.bag.num_letters_left()
print ''
sys.stdout.flush()
def display_rack(self, player):
"""displays the rack of player"""
self.players[player].display_rack()
def display_player_screen(self, compact=True):
"""Displays the screen each player will see when it is their turn"""
self.display(compact)
curr_player = self.player_order[self.turn % len(self.player_order)]
raw_input(curr_player + ": Press enter to see your letters")
print '\n' + curr_player + "'s letters:"
self.display_rack(curr_player)
def save_game(self):
'''Save the game in its current to a file'''
# save bag, board, and player_order
with open('bag.data', 'wb') as save_file:
pickle.dump(self.bag(), save_file)
with open('board.data', 'wb') as save_file:
pickle.dump(self.board(), save_file)
with open('player_order.data', 'wb') as save_file:
pickle.dump(self.player_order, save_file)
# save players
numAI = 1
for index, player in enumerate(self.players):
if self.players[player].isAI:
player_data = [player, \
self.players[player].rack(), \
self.players[player].score, \
self.computers[player]]
with open('AI_' + str(numAI) + '.data', 'wb') as save_file:
pickle.dump(player_data, save_file)
numAI += 1
else:
player_data = [player, \
self.players[player].rack(), \
self.players[player].score]
with open('player' + str(index + 1) + '.data', 'wb') as save_file:
pickle.dump(player_data, save_file)
# save turn, num_players, num_computers
with open('game_info.data', 'wb') as save_file:
num_real_players = len(self.players) - len(self.computers)
pickle.dump([self.turn, num_real_players, len(self.computers)], \
save_file)