We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Helpful YouTube videos (UCI-Interface for Chess-Engines)
#1
The discussion of the AI championship with a playing field and separate engines reminded me of the chess engine championships of the last few decades. The ranking is determined from countless games that the engines play against each other. This is done automatically via defined interfaces (e.g. UCI interface).
My attempts to access this interface with Small Basic failed because I didn't know how Small Basic used the stdio interface.
So I looked for a C# chess engine that was as simple as possible and then wrote a Small Basic program using the source code that could at least access the UCI interface.
Searching on github I found the following video series that shows how an unknown interface can be accessed and operated using debug outputs.

https://www.youtube.com/playlist?list=PL6vJSkTaZuBtTokp8-gnTsP39GCaRS3du

The video series consists of four episodes, of which I have completed the first one and the others will probably take some time.

Definition UCI Interface: https://en.wikipedia.org/wiki/Universal_Chess_Interface

Chess program that can communicate with chess engines: https://cutechess.com/


Episode 1 : Hello World

The program CS_UCI was written in Visual Studio 2017.
It is a console application with the target framework .NET 4.5.2

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS_UCI
{
    class Program
    {
  
        static void Main(string[] args)
        {
            string[] Move = { "e7e5", "a7a6", "d7d6", "b7b5", "g8f6", "g7g6", "h7h5", "f8g7", "b8c6" };
            int Movecount = 0;
               
            while (true)
            {
                //remove leading & trailing whitecases and split using ' ' as delimiter
                string[] tokens = Console.ReadLine().Trim().Split(' ');
                //string   command = Console.ReadLine().Split(' ')[0];
                switch (tokens [0])
                {
                    case "uci":
                        Console.WriteLine("uciok");
                        break;
                    case "isready":
                        Console.WriteLine("readyok");
                        break;
                    case "go":
                        Console.WriteLine("bestmove "+ Move[Movecount]);
                        // Console.WriteLine(Move[Movecount]);
                        Movecount = Movecount + 1;
                        if (Move.Length <= Movecount)
                            { Movecount = Movecount - 1 ; }
                        break;
                    case "position":
                        // Board;
                        break;
                    default:
                        Console.WriteLine("info " +  tokens[0].ToString());
                        break;
                }
            }
        }
    }
}
After starting Cute Chess, the exe file must be defined as the engine via Settings.

Using New, you can choose any engine for white (stockfish, Dragon, etc.) or you can play yourself.

CS_UCI can now be selected for black.

The dummy moves provided for black should be enough for a few moves.
   
The corresponding Small Basic program is in Thread: https://litdev.uk/mybb/showthread.php?tid=75
[-] The following 3 users Like Scout's post:
  • AbsoluteBeginner, litdev, z-s
Reply


Messages In This Thread
Helpful YouTube videos (UCI-Interface for Chess-Engines) - by Scout - 05-22-2024, 08:36 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)