Uci engine not recognized

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Machariel
Posts: 5
Joined: Thu Jun 15, 2023 12:10 am
Full name: Valmont Bosman

Uci engine not recognized

Post by Machariel »

Hello beloved coders. My first post - I don't think there's an introduction section and I won't steal your time here.

I was taking my first chess programming steps. But both CuteChess and well as Fritz 18 GUI won't recognize the basic setup of my engine. The protocols don't seem to communicate as the application itself isn't even accepted. I don't think it's the code (you decide). Is there something in some options I have to do to make the application better compatible perhaps? Here's the code, it's C#, the environment is Visual Studio 2022 (updated yesterday june 14th) on a Windows 10 machine:

Code: Select all

using System.Diagnostics;

 public class Program
{
    private static void Main(string[] args)
    {
        while (true)
        {
            string command = Console.ReadLine().Trim();
            switch (command)
            {
                case "uci":
                    Console.WriteLine("uciok");
                    break;
                default:
                    Debugger.Launch();
                    break;
            }
        }
    }
}
User avatar
Ras
Posts: 2695
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Uci engine not recognized

Post by Ras »

Machariel wrote: Thu Jun 15, 2023 1:56 pmBut both CuteChess and well as Fritz 18 GUI won't recognize the basic setup of my engine.
Maybe they try to read the name of the engine and author, but you don't send them. UCI lists that as mandatory.

Code: Select all

case "uci":
    Console.WriteLine("id name Yourenginename Yourversion");
    Console.WriteLine("id author Valmont Bosman");
    Console.WriteLine("uciok");
    break;
And then, the GUI will probably send isready to your engine, to which the engine must answer readyok - but your code doesn't do that. Note that the GUI may also send isready during engine calculations, and you must answer that as well, i.e. during engine search.
Rasmus Althoff
https://www.ct800.net
User avatar
Machariel
Posts: 5
Joined: Thu Jun 15, 2023 12:10 am
Full name: Valmont Bosman

Re: Uci engine not recognized

Post by Machariel »

I tried a million times, the engine is simply not recognized. There's no protocol exchange to begin with. I think there's something with compiling. There's nothing wrong with the code itself I believe.

Code: Select all

using System.Diagnostics;

 public class Program
{
    private static void Main(string[] args)
    {
        while (true)
        {

            string command = Console.ReadLine().Trim();
            switch (command)
            {
                case "uci":
                    Console.WriteLine("id name Yourenginename Yourversion");
                    Console.WriteLine("id author Valmont Bosman");
                    Console.WriteLine("uciok");
                    break;
                default:
                    Debugger.Launch();
                    break;
            }
        }
    }
}
User avatar
Ras
Posts: 2695
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: Uci engine not recognized

Post by Ras »

Machariel wrote: Thu Jun 15, 2023 2:16 pmI tried a million times, the engine is simply not recognized. There's no protocol exchange to begin with. I think there's something with compiling.
You can try opening a terminal window and starting the engine within that window. Then enter uci and see whether you get the expected output from the engine. If you have any other UCI engine on your system, you can try the same with that engine and see how it looks in comparison.
Rasmus Althoff
https://www.ct800.net
User avatar
Machariel
Posts: 5
Joined: Thu Jun 15, 2023 12:10 am
Full name: Valmont Bosman

Re: Uci engine not recognized

Post by Machariel »

I did that. It works fine. It's something in the compile I think. There's nothing wrong with the code.
At worst I have a warning "Warning CS8603 Possible null reference return." It's related to GetLine(), since it can return a NULL in theory. But there's nothing I can do about it. I don't believe this is it.
I tried code like this, and it should totally work, but it doesn't. Even when I attach the debugger using

Code: Select all

                    default:
                        Debugger.Launch();
                        break;
It won't work so I can read any messages if they are sent.

Code: Select all

private static void Main(string[] args)
        {
            while (true)
            {
                string input = ReadInput();

                if (input == null)
                    break;


                string[] tokens = input.Trim().Split();

                if (tokens.Length == 0)
                    continue;


                switch (tokens[0])
                {
                    case "uci":
                        Console.WriteLine($"id name Valmont Bosman");
                        Console.WriteLine($"id author Uci2");
                        Console.WriteLine("uciok");
                        break;
                    case "isready":
                        Console.WriteLine("readyok");
                        break;
                    case "position":
                        break;
                    case "go":
                        break;
                    case "ucinewgame":
                        break;
                    case "stop":
                        break;
                    case "quit":
                        break;
                    case "setoption":
                        break;
                    default:
                        Console.WriteLine("UNKNOWN INPUT");
                        return;
                }
            }
        }

        private static string ReadInput()
        {
            return Console.ReadLine();
        }
    }
User avatar
Machariel
Posts: 5
Joined: Thu Jun 15, 2023 12:10 am
Full name: Valmont Bosman

Re: Uci engine not recognized

Post by Machariel »

Interesting breakthrough:
It works if I create this in .net Framework 4.7.2, but not in .net Core 6 or 7!
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Uci engine not recognized

Post by hgm »

Are you sure the things your engine prints immediately appear in the output, instead of being buffered?
Joost Buijs
Posts: 1632
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Uci engine not recognized

Post by Joost Buijs »

I never used .NET, but I think the console output needs to be flushed after each Console.WriteLine() with: Console.Out.Flush(); Otherwise these WriteLine() statements will be buffered.
User avatar
Machariel
Posts: 5
Joined: Thu Jun 15, 2023 12:10 am
Full name: Valmont Bosman

Re: Uci engine not recognized

Post by Machariel »

I forgot to update this. Tough day today. Anyway, for .net Core one needs to copy the config file and the dll to the working directory. In .net Framework, this wasn't' necessary. When deploying, one needs to compile this as one file. Those two methods are the solutions.

I figured it out by programming quickly my own overarching app which loaded the "engine" (there was nothing in it but the basic UCI functionality) and used the UCI protocol to communicate with it.

To those who tried to help, thank you. Enjoy the weekend.