When I started programming, one of my early ideas was to build a chess engine. What sounds more sophisticated for a programmer, than building something like that? It just sounds smart!

Thus entered the “Beginner Engine” which I built for Android using a YouTube tutorial by Logic Crazy. It was great to have someone who programmed in Java explaining every step of making a playable engine. Unfortunately, it had some serious flaws for use on Android. None of which was Logic Crazy’s fault, he was showing the basics of building an engine. But it couldn’t castle, and bogged down my phone every time I used it.

After learning the ropes, I decided to build the “JustChess Engine”. It no longer bogged down the system, and despite being relatively stupid, it is quite playable (except for a pesky en passant bug that I still need to fix). The problem with using the JustChess Engine is that it was written by me for my application, so it does not respond to regular engine commands, like those from the UCI, or the Universal Chess Interface. Instead it only responds to my commands that I programmed it with.

picoEngine_1

Here you can see my new engine, picoEngine, talking to Arena Chess!

Hence, I’ve decided to build a UCI compatible chess engine, so I can learn how to interface with GUI’s through UCI. Thus, I’ve started a C++ project called “picoEngine”, which literally means very small engine. You can check out the first commit on my GitLab, and here is my first bit of working code:

/* Copyright 2018 by AlaskaLinuxUser (https://thealaskalinuxuser.wordpress.com)
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <iostream>
using namespace std;

string engineName = “picoEngine A01”;
string inputString;

void inputUCI();
void inputSetOption(string setString);
void inputIsReady();
void inputUCINewGame();
void inputPosition(string posString);
void inputGo();
void inputQuit();
void inputPrint();
bool runProgram = true;

int main()
{
cout << “Waiting….”;

while(runProgram) {
getline(cin, inputString);

if (inputString == “uci”)
{
inputUCI();
}
else if (inputString.rfind(“setoption”, 0) == 0)
{
inputSetOption(inputString);
}
else if (inputString.rfind(“isready”, 0) == 0)
{
inputIsReady();
}
else if (inputString.rfind(“ucinewgame”, 0) == 0)
{
inputUCINewGame();
}
else if (inputString.rfind(“position”, 0) == 0)
{
inputPosition(inputString);
}
else if (inputString.rfind(“go”, 0) == 0)
{
inputGo();
}
else if (inputString.rfind(“quit”, 0) == 0)
{
inputQuit();
}
else if (inputString.rfind(“print”, 0) == 0)
{
inputPrint();
}
}
return 0;
}

void inputUCI()
{
cout << “id name ” << engineName << endl;
cout << “id author Alaskalinuxuser” << endl;
cout << “Apache 2.0 License.” << endl;
cout << “https://thealaskalinuxuser.wordpress.com” << endl;
// Options can go in here
cout << “option name Style type combo default Normal var Random var Normal” << endl;
// End of Options
cout << “uciok” << endl;
}
void inputSetOption(string setString)
{
cout << “Setting Options….” << endl;
// Set your options like: setoption name Hash value 32
cout << “Options set.” << endl;
}
void inputIsReady()
{
// Are we ready for input?
// Do any initialization first.
cout << “readyok” << endl;
}
void inputUCINewGame()
{
cout << “Creating New Game….” << endl;
}
void inputPosition(string posString)
{
cout << “Accepting Position….” << endl;
}
void inputGo()
{
cout << “Going….” << endl;
}
void inputQuit()
{
cout << “Quiting….” << endl;
runProgram = false;
}
void inputPrint()
{
cout << “Printing Board….” << endl;
}

I was even able to load it into Arena Chess and talk to it through the interface. Obviously it ran out of time because it can’t actually make a move, but it did respond to standard uci commands, which is great!

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *