1

I want to make this clear: I want to connect MY chess GUI to chess UCI. GUI -> Engine. Universal chess UCI will stdout a 'bestmove' that can then be carried out by the chess GUI. But the only problem I'm having is getting my GUI to attach itself to this separate program and get the stdout call. I've tried _popen and system but those two functions close the program as soon as something is called. Here's what I mean by that:

system(stockfish.exe position startpos moves e2e4);
system(stockfish.exe go depth 10);

output:
Stockfish 091021 by the Stockfish developers (see AUTHORS file)
Stockfish 091021 by the Stockfish developers (see AUTHORS file)
info string NNUE evaluation using nn-13406b1dcbe0.nnue enabled
info depth 1 seldepth 1 multipv 1 score cp 38 nodes 20 nps 6666 tbhits 0 time 3 pv d2d4
info depth 2 seldepth 2 multipv 1 score cp 82 nodes 50 nps 12500 tbhits 0 time 4 pv e2e4 a7a6
info depth 3 seldepth 3 multipv 1 score cp 65 nodes 122 nps 24400 tbhits 0 time 5 pv g1f3 h7h6 d2d4
info depth 4 seldepth 4 multipv 1 score cp 41 nodes 456 nps 65142 tbhits 0 time 7 pv g1f3 d7d5 d2d4 c7c6
info depth 5 seldepth 5 multipv 1 score cp 22 nodes 1409 nps 117416 tbhits 0 time 12 pv c2c4 e7e5 d2d4 e5d4 d1d4
info depth 6 seldepth 6 multipv 1 score cp 25 nodes 1973 nps 123312 tbhits 0 time 16 pv g1f3 c7c5 c2c4 g8f6 d2d4 c5d4 f3d4
info depth 7 seldepth 7 multipv 1 score cp 39 nodes 2804 nps 140200 tbhits 0 time 20 pv g1f3 d7d5 e2e3 e7e6 c2c4 d5c4 f1c4
info depth 8 seldepth 10 multipv 1 score cp 49 nodes 8782 nps 141645 tbhits 0 time 62 pv e2e4 c7c5 b1c3 d7d6 g1e2 e7e5 c3d5
info depth 9 seldepth 12 multipv 1 score cp 36 nodes 17265 nps 140365 tbhits 0 time 123 pv e2e4 c7c6 d2d4 d7d5 b1d2 d5e4 d2e4 g8f6 e4f6 e7f6
info depth 10 seldepth 13 multipv 1 score cp 47 nodes 21380 nps 149510 tbhits 0 time 143 pv e2e4 c7c5 b1c3 d7d6 g1e2 e7e5 e2g3 c8e6 c3d5
bestmove e2e4 ponder c7c5

stockfish is ran twice indicated by the two "Stockfish 091021 by the Stockfish developers (see AUTHORS file)" and my output is e2e4 clearly indicated it has ignored my start position. I've also tried this function that I found on stackoverflow but was reached with the same problem.

std::string exec(const char* cmd) {
    char buffer[128];
    std::string result = "";
    FILE* pipe = _popen(cmd, "r");
    if (!pipe) throw std::runtime_error("popen() failed!");
    try {
        while (!feof(pipe)) {
            if (fgets(buffer, 128, pipe) != NULL)
                result += buffer;
        }
    }
    catch (...) {
        _pclose(pipe);
        throw;
    }
    _pclose(pipe);
    return result;
}

void main() {
    std::cout << exec("C:/Users/kurtk/source/Chess/Project1/Project1/stock/stockfish.exe position startpos moves e2e4");
    std::cout << exec("C:/Users/kurtk/source/Chess/Project1/Project1/stock/stockfish.exe go depth 10");
}

output:
Stockfish 091021 by the Stockfish developers (see AUTHORS file)
Stockfish 091021 by the Stockfish developers (see AUTHORS file)
info string NNUE evaluation using nn-13406b1dcbe0.nnue enabled
info depth 1 seldepth 1 multipv 1 score cp 38 nodes 20 nps 20000 tbhits 0 time 1 pv d2d4
info depth 2 seldepth 2 multipv 1 score cp 82 nodes 50 nps 50000 tbhits 0 time 1 pv e2e4 a7a6
info depth 3 seldepth 3 multipv 1 score cp 65 nodes 122 nps 61000 tbhits 0 time 2 pv g1f3 h7h6 d2d4
info depth 4 seldepth 4 multipv 1 score cp 41 nodes 456 nps 152000 tbhits 0 time 3 pv g1f3 d7d5 d2d4 c7c6
info depth 5 seldepth 5 multipv 1 score cp 22 nodes 1409 nps 201285 tbhits 0 time 7 pv c2c4 e7e5 d2d4 e5d4 d1d4
info depth 6 seldepth 6 multipv 1 score cp 25 nodes 1973 nps 197300 tbhits 0 time 10 pv g1f3 c7c5 c2c4 g8f6 d2d4 c5d4 f3d4
info depth 7 seldepth 7 multipv 1 score cp 39 nodes 2804 nps 200285 tbhits 0 time 14 pv g1f3 d7d5 e2e3 e7e6 c2c4 d5c4 f1c4
info depth 8 seldepth 10 multipv 1 score cp 49 nodes 8782 nps 168884 tbhits 0 time 52 pv e2e4 c7c5 b1c3 d7d6 g1e2 e7e5 c3d5
info depth 9 seldepth 12 multipv 1 score cp 36 nodes 17265 nps 169264 tbhits 0 time 102 pv e2e4 c7c6 d2d4 d7d5 b1d2 d5e4 d2e4 g8f6 e4f6 e7f6
info depth 10 seldepth 13 multipv 1 score cp 47 nodes 21380 nps 156058 tbhits 0 time 137 pv e2e4 c7c5 b1c3 d7d6 g1e2 e7e5 e2g3 c8e6 c3d5
bestmove e2e4 ponder c7c5

I've also tried running the program as one line instead and putting '\n' in between separate commands but that doesn't work either. What am I missing?

blah blah
  • 11
  • 2

1 Answers1

0

I am not sure if this question is still ongoing, but since you're on windows you can use windows.h. You can also base it off of this video https://www.youtube.com/watch?v=_4EuZI8Q8cs. At around 3:00, they start to implement stockfish onto their chess GUI written using SFML.