ifstream doesn't seem to open an external exe for reading and writing

98 Views Asked by At

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;

}
0

There are 0 best solutions below