當前位置: 首頁>>代碼示例>>Python>>正文


Python Board.get_clone方法代碼示例

本文整理匯總了Python中models.board.Board.get_clone方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.get_clone方法的具體用法?Python Board.get_clone怎麽用?Python Board.get_clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.board.Board的用法示例。


在下文中一共展示了Board.get_clone方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import get_clone [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
開發者ID:sevenleo,項目名稱:othello-reversi-python,代碼行數:62,代碼來源:board_controller.py

示例2: __init__

# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import get_clone [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
開發者ID:mateusgreg,項目名稱:TabuleiroOthello,代碼行數:49,代碼來源:board_controller.py

示例3: __init__

# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import get_clone [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)
開發者ID:frila,項目名稱:agente-minimax,代碼行數:66,代碼來源:board_controller.py


注:本文中的models.board.Board.get_clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。