bpaul-chess

UCI chess engine to replace Omelette Chess Engine
Log | Files | Refs | README

commit 39584d0b1de27185b5ef80bcbfa707f2e4a436c6
parent 9b65fb6f2496f124db4ae84d1a2a0f0c421d0bf7
Author: benjamin paul <bpaul@bpaul.xyz>
Date:   Fri,  6 Aug 2021 22:44:12 +1000

Basic uci commands

Diffstat:
Msrc/main.c | 33++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -1,5 +1,14 @@ +#include <string.h> +#include <stdbool.h> #include <stdio.h> +#define VERSION "v0.0.1" + +bool +cmd(const char *buf, const char *command) { + return strncmp(buf, command, strlen(command)) == 0; +} + int main() { /* If your computer does not have enough RAM to support a 2KiB buffer, it @@ -7,13 +16,27 @@ main() { * * A 2048 character buffer may be too small for a position command, a * setoption command or a go searchmoves command. The position command is - * the only command out of these which may actually be used of such size. + * the only command out of these which may be used in an actual setting. * For it to be the case that the command is too big, there must be - * (2048-17)/5 moves being the buffer size minus the length of "position - * startpos" divided by the size of a move, being 4 characters and a space. - * This means that with this buffer size, a game cannot go on for longer - * than 406 moves. */ + * (2048-17)/5 moves made being the buffer size minus the length of + * "position startpos" divided by the size of a move, being 4 characters + * and a space. This means that with this buffer size, a game cannot go on + * for longer than 406 moves. */ char buf[2048]; + for (;;) { + fgets(buf, 2048, stdin); + + if (cmd(buf, "uci")) { + printf("id name bpaul-chess %s\n", VERSION); + puts("id author Benjamin Paul"); + puts("uciok"); + } else if (cmd(buf, "isready")) { + puts("readyok"); + } else if (cmd(buf, "quit")) { + break; + } + } + return 0; }