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


Python File.prompt方法代码示例

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


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

示例1: game_type

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [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: insert_piece

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [as 别名]
	def insert_piece(self, board, piece_name, player_x, player_y):
		File.prompt("STARTING POSITION FOR " + piece_name + " ?")

		moveH = input("Horizontal [1-8]: ")
		moveH = int(moveH)
		while moveH < 1 or moveH > 8:
			File.error("expected [1-8]")
			moveH = input("Horizontal [1-8]: ")
			moveH = int(moveH)

		moveV = input("Vertical [1-8]: ")
		moveV = int(moveV)
		while moveV < 1 or moveV > 8:
			File.error("expected [1-8]")
			moveV = input("Vertical [1-8]: ")
			moveV = int(moveV)

		if board.state[moveH][moveV] != '*':
			File.error("space occupied")
			exit(2)

		if piece_name == "PlayerX King":
			piece_id = Piece(player_x, 'K', moveH, moveV)
			player_x.add_piece(piece_id)
		elif piece_name == "PlayerX Rook":
			piece_id = Piece(player_x, 'R', moveH, moveV)
			player_x.add_piece(piece_id)
		elif piece_name == "PlayerY King":
			piece_id = Piece(player_y, 'K', moveH, moveV)
			player_y.add_piece(piece_id)
		else:
			File.error("expected valid piece")
			exit(3)

		File.prompt("OK " + piece_name + " to " + str(moveH) + "-" + str(moveV))
开发者ID:mittman,项目名称:pycheckmate,代码行数:37,代码来源:Game.py

示例3: ai_move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [as 别名]
    def ai_move(self, player):
        if player.id == "x":
            key = random.randint(0, 1)
            if key == 0 or "R" not in player.pieces:
                piece = player.pieces["K"]
            else:
                piece = player.pieces["R"]
        else:
            piece = player.pieces["K"]

        legal_moves = self.find_legal_moves(piece)

        ### if len(legal_moves) == 0: *CHECKMATE OR TIE* ###
        if len(legal_moves) == 0:
            File.prompt("game over")
            exit(0)
        if len(legal_moves) == 1:
            new_destination = legal_moves[0]
        else:
            new_destination = legal_moves[random.randint(0, len(legal_moves) - 1)]

            # move:
        self.make_move(player, piece, (new_destination[0], new_destination[1]))

        self.move_log = piece.player + piece.type + " to " + str(new_destination[0]) + "," + str(new_destination[1])
开发者ID:mittman,项目名称:pycheckmate,代码行数:27,代码来源:Board.py

示例4: ask_piece

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [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

示例5: move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [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

示例6: interactive

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [as 别名]
def interactive(ply):
    g = Game()
    mode, end = g.game_type()
    end = int(end)

    if mode:  # mode is true means new game
        player_x = Player("x")
        player_y = Player("y")
        b = Board(player_x, player_y)
        ai = Ai(ply)
        remain = ["PlayerX King", "PlayerX Rook", "PlayerY King"]
        g.ask_piece(b, player_x, player_y, remain)
        b.display()

        File.prompt("Who am I, PlayerX or PlayerY?")
        localPlayer = input("Player [x/y]: ")
        if re.match(r"[Xx]", localPlayer):
            localPlayer = "x"
        else:
            localPlayer = "y"

            # if local player is playerX, PlayerX is our ai moves
            # PlayerY is opponents moves inputted by us
        if localPlayer == "x":
            for i in range(0, end):
                # b.ai_move(player_x)
                ai.move(b, player_x)
                b.display()
                File.debug(ai.value(b))
                File.debug(ai.number_of_states)
                ai.opponent_move(player_y, b)
                b.display()
        else:
            for i in range(0, end):
                ai.opponent_move(player_x, b)
                b.display()
                # b.ai_move(player_y)
                ai.move(b, player_y)
                b.display()
                File.debug(ai.value(b))
                File.debug(ai.number_of_states)
    else:
        player_x = Player("x")
        player_y = Player("y")
        b = Board(player_x, player_y)
        File.test_file(b, g, player_x, player_y)

        ai = Ai(ply)

        # AI random moves test:
        for i in range(0, end):
            ai.move(b, player_x)
            b.display()
            File.debug(ai.value(b))
            File.debug(ai.number_of_states)
            ai.move(b, player_y)
            b.display()
            File.debug(ai.value(b))
            File.debug(ai.number_of_states)
开发者ID:mittman,项目名称:pycheckmate,代码行数:61,代码来源:main.py

示例7: add_or_move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [as 别名]
	def add_or_move(self, board, player, piece_id, moveH, moveV, num):
		if num == 1:
			new_piece = Piece(player, piece_id, moveH, moveV)
			if player.id == 'x':
				player.add_piece(new_piece)
			elif player.id == 'y':
				player.add_piece(new_piece)
			else:
				File.error("invalid player")
		else:
			if board.state[moveH][moveV] != player.id + piece_id:
				print('\n\n')
				File.prompt("MOVE " + player.id + piece_id + " to " + str(moveH) + "," + str(moveV))
				board.player_move(player, piece_id, moveH, moveV)
开发者ID:mittman,项目名称:pycheckmate,代码行数:16,代码来源:Game.py

示例8: make_move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [as 别名]
    def make_move(self, player, piece, new_coords, testing=False):
        new_row = new_coords[0]
        new_col = new_coords[1]
        # If playerY eats playerX's rook:
        if (
            "R" in self.player_x.pieces
            and new_row == self.player_x.pieces["R"].row
            and new_col == self.player_x.pieces["R"].col
        ):
            del self.player_x.pieces["R"]
            if not testing:
                File.prompt("PlayerX rook captured")
                File.prompt("Stalemate")
                exit(0)

        self.state[piece.row][piece.col] = "*"
        piece.prev_coords = (piece.row, piece.col)
        piece.row = new_coords[0]
        piece.col = new_coords[1]
        self.state[0][0] = "player" + piece.player.upper()
        self.state[piece.row][piece.col] = piece.player + piece.type
        self.piece_positions = self.new_positions()
        player.turn += 1
        self.move_log = piece.player + piece.type + " to " + str(new_row) + "," + str(new_col)
开发者ID:mittman,项目名称:pycheckmate,代码行数:26,代码来源:Board.py

示例9: opponent_move

# 需要导入模块: from File import File [as 别名]
# 或者: from File.File import prompt [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.prompt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。