0

I am a beginner hobby programmer.

I am working on a small program that will take the FEN string of any chess position from the user, pass it into the Stockfish chess engine, and grab a move output from the exe once it has done its magic in finding a move.

The problem is, once I enter the FEN string into my compiled program, the command line window remains static, and outputs nothing. When I press enter, new lines simply appear, and when I enter anything other than spaces, the command line window closes.

I tried opening Task manager to check to see if Stockfish was running after the FEN string was entered, and I couldn't find it anywhere, which must mean Stockfish wasn't opened by my program to begin with.

The following code has been compiled with g++ in Windows smoothly with no error messages to be found.

After doing some research online, I have tried changing "Stockfish.exe" to "C:....(path)..\Stockfish.exe" to no avail (with loads of compilation errors too).

Am I missing something? What must I do in order for the program to actually open Stockfish and enter the FEN and UCI commands?

Many thanks!

^_^

#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;

}
manlio
  • 18,345
  • 14
  • 76
  • 126
  • How about using a a debugger and setting a breakpoint at the first line of your main function ? – EylM Jul 20 '19 at 10:37
  • `infile` and `outfile` are meaningless and do nothing. You are not starting any external engine and not passing anything to any such thing. At what point do you expect these actions should be performed? – n. m. could be an AI Jul 20 '19 at 10:46
  • Read the FEN using std::getline –  Jul 20 '19 at 11:09
  • 1
    You can't use `fstream` to receive or send commands to/from user. Use `CreateProcess` to launch the command line chess engine and spawn input and output pipes to send or/and receive info from the engine. – seccpur Jul 20 '19 at 13:16

0 Answers0