仍在学习python,偶然发现棋盘游戏《奥赛罗》使用了"AI";。[https://www.instructables.com/id/Othello-Artificial-Intelligence/][1]该游戏有两个版本——玩家对玩家和玩家对AI。我遇到的问题是玩家对AI,Other_game.py。Other_gui,玩家对玩家的工作没有问题。
错误为:
C:UsersJoeDocumentsOthelloAI-masterOthelloAI-master> python othello_game.py [erika_5.py] [nathan_ai.py]
Traceback (most recent call last):
File "othello_game.py", line 157, in <module>
player1 = AiPlayerInterface(sys.argv[1],1)
File "othello_game.py", line 36, in __init__
self.process = subprocess.Popen(['python3',filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
File "C:ProgramDataAnaconda3libsubprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "C:ProgramDataAnaconda3libsubprocess.py", line 1207, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
init编码为:
def __init__(self, filename, color):
self.color = color
self.process = subprocess.Popen(['python3',filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
name = self.process.stdout.readline().decode("ASCII").strip()
print("AI introduced itself as: {}".format(name))
self.name = name
self.process.stdin.write((str(color)+"n").encode("ASCII"))
self.process.stdin.flush()
导入语句为:
import sys
import subprocess
from threading import Timer
from othello_shared import find_lines, get_possible_moves, play_move, get_score
任何帮助都将不胜感激,只需学习子流程即可。[1] :https://www.instructables.com/id/Othello-Artificial-Intelligence/
感谢Dinesh Pundkar的回答,编辑只是添加了shell = True
:
self.process = subprocess.Popen(['python',filename], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)