本文整理匯總了Python中models.board.Board.play方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.play方法的具體用法?Python Board.play怎麽用?Python Board.play使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.board.Board
的用法示例。
在下文中一共展示了Board.play方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import play [as 別名]
class BoardController:
def __init__(self):
self.board = Board(None)
self.view = ConsoleBoardView(self.board)
def init_game(self):
# self.white_player = Core1Player(Board.WHITE)
self.white_player = HumanPlayer(Board.WHITE)
self.black_player = Core2Player(Board.BLACK)
# self.black_player = RandomPlayer(Board.BLACK)
self.atual_player = self.black_player
finish_game = 0
self.view.update_view()
while finish_game != 2:
#raw_input("")
atual_color = self.atual_player.color
print 'Jogador: ' + atual_color +' ('+ self.atual_player.name() +')'
if self.board.valid_moves(atual_color).__len__() > 0:
self.board.play(self.atual_player.play(self.board.get_clone()), atual_color)
self.view.update_view()
finish_game = 0
else:
print 'Sem movimentos para o jogador: ' + atual_color
finish_game += 1
self.atual_player = self._opponent(self.atual_player)
return self._end_game()
def _end_game(self):
score = self.board.score()
print ''
print'-----------------PLACAR DESTA RODADA---------------------'
print self.white_player.name() , " = " , score[0]
print self.black_player.name() , " = " , score[1]
if score[0] > score[1]:
print ""
print 'Jogador ' + self.white_player.name() + ' Ganhou'
return 1
elif score[0] < score[1]:
print ""
print 'Jogador ' + self.black_player.name() + ' Ganhou'
return 2
else:
print ""
print 'Jogo terminou empatado'
return 0
print'---------------------------------------------'
def _opponent(self, player):
if player.color == Board.WHITE:
return self.black_player
return self.white_player
示例2: __init__
# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import play [as 別名]
class BoardController:
def __init__(self):
self.board = Board(None)
self.view = ConsoleBoardView(self.board)
def init_game(self):
self.white_player = CornerPlayer(Board.WHITE)
self.black_player = RandomPlayer(Board.BLACK)
self.atual_player = self.black_player
finish_game = 0
self.view.update_view()
while finish_game != 2:
raw_input("")
atual_color = self.atual_player.color
print 'Jogador: ' + atual_color
if self.board.valid_moves(atual_color).__len__() > 0:
self.board.play(self.atual_player.play(self.board.get_clone()), atual_color)
self.view.update_view()
finish_game = 0
else:
print 'Sem movimentos para o jogador: ' + atual_color
finish_game += 1
self.atual_player = self._opponent(self.atual_player)
self._end_game()
def _end_game(self):
score = self.board.score()
if score[0] > score[1]:
print ""
print 'Jogador ' + Board.WHITE + ' Ganhou'
elif score[0] < score[1]:
print ""
print 'Jogador ' + Board.BLACK + ' Ganhou'
else:
print ""
print 'Jogo terminou empatado'
def _opponent(self, player):
if player.color == Board.WHITE:
return self.black_player
return self.white_player
示例3: __init__
# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import play [as 別名]
class BoardController:
def __init__(self):
self.board = Board(None)
self.view = ConsoleBoardView(self.board)
def init_game(self):
self.white_player = self._select_player(Board.WHITE)
self.black_player = self._select_player(Board.BLACK)
self.atual_player = self.black_player
finish_game = 0
self.view.update_view()
while finish_game != 2:
raw_input("")
atual_color = self.atual_player.color
print 'Jogador: ' + atual_color
if self.board.valid_moves(atual_color).__len__() > 0:
self.board.play(self.atual_player.play(self.board.get_clone()), atual_color)
self.view.update_view()
finish_game = 0
else:
print 'Sem movimentos para o jogador: ' + atual_color
finish_game += 1
self.atual_player = self._opponent(self.atual_player)
self._end_game()
def _end_game(self):
score = self.board.score()
if score[0] > score[1]:
print ""
print 'Jogador ' + self.white_player.__class__.__name__ + '('+Board.WHITE+') Ganhou'
elif score[0] < score[1]:
print ""
print 'Jogador ' + self.black_player.__class__.__name__ + '('+Board.BLACK+') Ganhou'
else:
print ""
print 'Jogo terminou empatado'
def _opponent(self, player):
if player.color == Board.WHITE:
return self.black_player
return self.white_player
def _select_player(self, color):
players = glob.glob('./models/players/*_player.py')
print 'Selecione um dos players abaixo para ser o jogador '+color
for idx, player in enumerate(players):
print idx.__str__() + " - " + player
player = raw_input("Digite o numero do player que voce deseja: ")
module_globals = {}
execfile(players[int(player)], module_globals)
print module_globals.keys()
return module_globals[module_globals.keys()[len(module_globals.keys()) - 1]](color)