我对 Python 很陌生,我下载了一个代码来帮助我玩纸牌游戏,我修复了一些小错误,但这是我遇到的主要错误。这是错误:
“用法:FFVIII_CardGame_AI2.py [-h] -f FILEPATH -d DEPTH -s STARTING_PLAYER FFVIII_CardGame_AI2.py:错误:需要以下参数:-f、-d、-s"
这是代码部分:
def gamestate_from_file(filepath):
"""
Generate a GameState object from a file
"""
with open(filepath) as f:
dataMap = yaml.safe_load(f)
gamestate = GameState()
gamestate.current_player = dataMap["Current_Player"]
for card_id in dataMap["Cards"]:
card_details = dataMap["Cards"][card_id]
card = Card(
symbol=card_details["symbol"],
owner=card_details["owner"],
top=card_details["top"],
left=card_details["left"],
right=card_details["right"],
bottom=card_details["bottom"],
)
position = card_details["position"]
if position == "Hand":
gamestate.players[card_details["owner"]].hand[card_details["symbol"]] = card
else:
gamestate.board[position] = card
return gamestate
def is_valid_file(parser, arg):
if not os.path.exists(arg):
parser.error("The file %s does not exist!" % arg)
return arg
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"-f",
dest="filepath",
required=True,
help="Filepath of GameState file (gamestate.yaml)",
type=lambda x: is_valid_file(parser, x),
)
parser.add_argument(
"-d",
dest="depth",
required=True,
help="Max tree depth of Minimax tree",
type=int,
)
parser.add_argument(
"-s",
dest="starting_player",
required=True,
type=str,
help="Starting Player ('P' for Player, or 'O' for Opponent)",
)
return parser.parse_args()
任何帮助将不胜感激。
我认为您提供的代码很好,或者至少是我所看到的。也许您可以提供更多详细信息,例如您的命令是什么。因为通常该错误是由于缺少特定的命令行参数导致的