我是一个业余爱好程序员。
我正在开发一个小程序,它将从用户那里获得任何国际象棋位置的FEN字符串,将其传递到Stockfish国际象棋引擎中,并在找到成功的法宝后立即从exe中获取一个法宝输出。
问题是,一旦我在编译后的程序中输入FEN字符串,命令行窗口就会保持静态,并且什么也不输出。当我按Enter键时,只会出现新行,而当我输入空格以外的任何内容时,命令行窗口将关闭。
我尝试打开任务管理器,以检查在输入FEN字符串后Stockfish是否正在运行,但我在任何地方都找不到它,这必须意味着我的程序没有打开Stockfish。
以下代码已在Windows中使用g ++顺利编译,没有发现错误消息。
在进行了一些在线研究之后,我尝试将“ Stockfish.exe”更改为“ C:....(路径).. \ Stockfish.exe”无济于事(同样有很多编译错误)。
我想念什么吗?为了使程序真正打开Stockfish并输入FEN和UCI命令,我必须怎么做?
非常感谢!
^ _ ^
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
using namespace std;
int main() {
cout << "Welcome to the Chess Puzzle Solver 1.0!" << endl;
cout << "Please enter the FEN string of the position you'd like to solve." << endl;
cout << "" << endl;
cout << "Example: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1" << endl;
cout << "[The starting position] ^" << endl;
cout << "" << endl;
string userStartingFEN;
cin >> userStartingFEN;
// Opening Stockfish to do the main stuff!
ifstream inFile;
ofstream outFile;
inFile.open("Stockfish.exe", ios::in | ios::out);
outFile.open("Stockfish.exe", ios::in | ios::out);
string uciCommand1;
uciCommand1 = "uci";
string uciCommand2;
uciCommand2 = "setoption name Threads value 4";
string uciCommand3;
uciCommand3 = "setoption name Contempt value 0";
string uciCommand4;
uciCommand4 = "setoption name Hash value 64";
cin >> uciCommand1;
cin >> uciCommand2;
cin >> uciCommand3;
cin >> uciCommand4;
cout << "I will say this if the parameters were set." << endl;
// Entering the user's wanted position
string inputtingFEN;
inputtingFEN = "position fen ";
cin >> inputtingFEN >> userStartingFEN;
string checkMe;
checkMe = "UCI and Position all set!";
cout << checkMe << endl;
inFile.close();
outFile.close();
return 0;
}