当前位置: 首页>>代码示例>>Python>>正文


Python File.print方法代码示例

本文整理汇总了Python中File.File.print方法的典型用法代码示例。如果您正苦于以下问题:Python File.print方法的具体用法?Python File.print怎么用?Python File.print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File.File的用法示例。


在下文中一共展示了File.print方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: game_type

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import print [as 别名]
	def game_type(self):
		mode = None
		end = 0

		File.prompt("Is this a test?")
		File.print("y) yes, this is a test")
		File.print("n) no, start a new game")
		mode = input("Select (Y/n): ")

		File.prompt("MAX NUMBER OF MOVES?")
		end = input("Input (default 35): ")

		if re.match(r"[Nn]|no|NO", mode):
			File.prompt("NEW GAME")
			mode = True
		else:
			File.prompt("TEST MODE ACTIVATED")
			mode = False

		if not re.match(r"[1-99]", end):
			end = 35
		else:
			File.prompt("NOTE: GAME ENDS IN " + end + " MOVES")

		return mode, end
开发者ID:mittman,项目名称:pycheckmate,代码行数:27,代码来源:Game.py

示例2: ask_piece

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import print [as 别名]
	def ask_piece(self, board, player_x, player_y, remain):
		File.prompt("ADD PIECE TO BOARD?")

		i = 0
		for p in remain:
			i += 1
			File.print(str(i) + ") " + p)

		n = len(remain)
		option = input("Select [1-" + str(n) + "]: ")
		try:
			option = int(option)
		except ValueError: self.ask_piece(board, player_x, player_y, remain)

		if option <= n and option > 0 and n > 1:
			piece_name = remain[option-1]
			self.insert_piece(board, piece_name, player_x, player_y)
			remain.pop(option-1)
			self.ask_piece(board, player_x, player_y, remain)
		elif option <= n and option > 0:
			piece_name = remain[option-1]
			self.insert_piece(board, piece_name, player_x, player_y)
			remain.pop(option-1)
		else:
			File.error("Try again")
			self.ask_piece(board, player_x, player_y, remain)
开发者ID:mittman,项目名称:pycheckmate,代码行数:28,代码来源:Game.py

示例3: move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import print [as 别名]
	def move(self, board, player):
		self.root_node = None
		if not board.find_legal_moves(board.player_y.pieces['K']):
			File.prompt("GAME OVER")
			exit(0)
		else:
			self.root_node = State(board)
			if player.id == 'x':
				self.create_state_tree(board, player, 0, self.root_node, True)
			else:
				self.create_state_tree(board, player, 0, self.root_node, False)
				
			best_state = self.root_node.children_nodes[0]
			if player.id == 'x':
				for s in self.root_node.children_nodes:
					if s.value <= best_state.value:
						best_state = s
			else:
				for s in self.root_node.children_nodes:
					if s.value >= best_state.value:
						best_state = s

			piece = player.pieces[best_state.piece_to_move.type]
			moveH = best_state.new_coords[0]
			moveV = best_state.new_coords[1]
			File.print('\n')
			File.prompt("Best move " + player.id + piece.type + " to " + str(moveH) + "," + str(moveV))
			board.make_move(player, piece, best_state.new_coords)
开发者ID:mittman,项目名称:pycheckmate,代码行数:30,代码来源:Ai.py

示例4: display

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import print [as 别名]
 def display(self):
     for p in self.player_x.pieces.values():
         self.state[p.row][p.col] = p.player + p.type
     for p in self.player_y.pieces.values():
         self.state[p.row][p.col] = p.player + p.type
     if self.move_log == "":
         self.state[0][3] = str(0)
     else:
         self.state[0][3] = str(self.player_x.turn)
     File.print("")
     File.print("\n".join("".join(["{:3}".format(item) for item in row]) for row in self.state))
开发者ID:mittman,项目名称:pycheckmate,代码行数:13,代码来源:Board.py

示例5: opponent_move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import print [as 别名]
	def opponent_move(self, player, board):
		horizontal = 0
		vertical = 0
		piece = player.pieces['K']

		if player.id == 'x':
			File.prompt("Move which PlayerX piece?")
			File.print("1) Rook")
			File.print("2) King")

			option = input("Select [1-2]: ")
			try:
				option = int(option)
			except ValueError:
				File.error("Try again")
				self.opponent_move(player, board)

			if option == 1:
				piece = player.pieces['R']
			elif option == 2:
				piece = player.pieces['K']
			else:
				File.error("Try again")
				self.opponent_move(player, board)

		legal_moves = board.find_legal_moves(piece)

		if len(legal_moves) == 0:
			File.print('')
			File.prompt("No legal moves for " + player.id + piece.type)
			board.display()
			File.prompt("Game Over")
			exit(0)

		for move in legal_moves:	#put X's where valid moves are
			horizontal, vertical = move
			board.state[horizontal][vertical] = '+'

		board.display()

		validInput = False
		while not validInput:
			if piece.type == 'K':
				name = "King"
			elif piece.type == 'R':
				name = "Rook"

			File.prompt("Move " + name + " to coordinates")
			horizontal= input("Horizontal [1-8]: ")
			vertical= input("Vertical [1-8]: ")
			try:	#validate input
				horizontal = int(horizontal)
				vertical = int(vertical)
			except ValueError: validInput = False
			for move in legal_moves:	#check if moves match a legal move
				temp_hor, temp_vert = move
				if horizontal == temp_hor and vertical == temp_vert:
					validInput = True
			if validInput != True:
				File.error("Please select a legal move.")


		for move in legal_moves:	#put *'s back where X's were
			temp_hor, temp_vert = move
			board.state[temp_hor][temp_vert] = '*'
		board.make_move(player,piece, (horizontal, vertical))

		board.move_log = piece.player + piece.type + ' to ' + \
						str(horizontal) + ',' + str(vertical)
开发者ID:mittman,项目名称:pycheckmate,代码行数:71,代码来源:Ai.py


注:本文中的File.File.print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。