Compare commits

..

No commits in common. "ce19f8793a56c595a07008e54c5ef3fc45a74f93" and "db63b547645c2c4ac2a38f618a55d60cf21e323e" have entirely different histories.

2 changed files with 18 additions and 21 deletions

View File

@ -177,8 +177,8 @@ void setup() {
board_init(); board_init();
Serial.begin(115200); Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
//perft_test(); perft_test();
//bench(); bench();
} }
void loop() { void loop() {

35
Uci.h
View File

@ -1,13 +1,11 @@
#ifndef __UCI_H_INC #ifndef __UCI_H_INC
#define __UCI_H_INC #define __UCI_H_INC
#define PS2(s) ([]{ static const char c[] PROGMEM = (s); return &c[0]; }())
typedef void uci_return; typedef void uci_return;
typedef uci_return (*uci_handler)(); typedef uci_return (*uci_handler)();
struct uci_cmd { struct uci_cmd {
const char* command; char* command;
uci_handler handler; uci_handler handler;
}; };
@ -24,28 +22,27 @@ uci_return uci_unknown() {
} }
const uci_cmd UCI_COMMANDS[] = { const uci_cmd UCI_COMMANDS[] = {
{PS2("uci"), &uci_hello}, {"uci", &uci_hello},
{PS2("debug"), &uci_unimpl}, {"debug", &uci_unimpl},
{PS2("isready"), &uci_unimpl}, {"isready", &uci_unimpl},
{PS2("setoption"), &uci_unimpl}, {"setoption", &uci_unimpl},
{PS2("ucinewgame"), &uci_unimpl}, {"ucinewgame", &uci_unimpl},
{PS2("position"), &uci_unimpl}, {"position", &uci_unimpl},
{PS2("go"), &uci_unimpl}, {"go", &uci_unimpl},
{PS2("stop"), &uci_unimpl}, {"stop", &uci_unimpl},
{PS2("ponderhit"), &uci_unimpl}, {"ponderhit", &uci_unimpl},
{PS2("quit"), &uci_unimpl}, {"quit", &uci_unimpl},
}; };
const uci_cmd UCI_INVALID = {PS2(""), &uci_unknown}; const uci_cmd UCI_INVALID = {"", &uci_unknown};
uci_cmd get_uci_command(const char* command) { uci_cmd get_uci_command(char* command) {
size_t command_num = sizeof(UCI_COMMANDS) / sizeof(uci_cmd); size_t command_num = sizeof(UCI_COMMANDS) / sizeof(uci_cmd);
for(size_t i = 0; i < command_num; i++) { for(int i = 0; i < command_num; i++) {
size_t ci = 0; int ci = 0;
uci_cmd to_try = UCI_COMMANDS[i]; uci_cmd to_try = UCI_COMMANDS[i];
while(true) { while(true) {
char reference = pgm_read_byte_near(to_try.command + ci); if(to_try.command[ci] != command[ci]) {
if(reference != command[ci]) {
break; break;
} }
if(command[ci] == '\0') { if(command[ci] == '\0') {