Compare commits

..

No commits in common. "f9cdd9a259314a725c2aa17a901dec488f57e364" and "34601f9c9d8f58a006f9b383b19cf400a60ce1eb" have entirely different histories.

3 changed files with 29 additions and 94 deletions

View File

@ -1,10 +1,4 @@
#ifndef MAIN_H
#define MAIN_H
#include "types.h"
int cmain();
game *fenGame(char *str);
void playMoves(game *g, char *moves);
void uciGo(game *g);
#endif

View File

@ -10,7 +10,6 @@
#include "types.h"
#include "help.h"
#include "eval.h"
#include "main.h"
#define BUFF_SIZE 4096
@ -56,44 +55,38 @@ int cmain() {
} else if (!strcmp("isready", token)) {
printf("readyok\n");
} else if (!strcmp("go", token)) {
uciGo(g);
static move mov[1500];//big dumb buffer
size_t cnt = 0;
cnt += pawnMove(g,mov);
cnt += knightMove(g,(mov+cnt));
cnt += rookMove(g,(mov+cnt));
cnt += bishopMove(g,(mov+cnt));
cnt += kingMove(g,(mov+cnt));
cnt += queenMove(g,(mov+cnt));
move *m = findBest(mov,cnt,g);
if(m == NULL){
printf("bestmove 0000\n");
continue;
}
char *end = "";
int yTo, xTo, yFrom, xFrom;
xTo = m->To % 8;
yTo = m->To / 8 + 1;
xFrom = m->From % 8;
yFrom = m->From / 8 + 1;
long long bit = 1LL << m->From;
if (m->Promo) {
end = "q\n";
} else {
end = "\n";
}
printf("bestmove %c%d%c%d%s", ltz[xFrom], yFrom, ltz[xTo], yTo, end);
}
}
}
void uciGo(game *g){
char ltz[] = "abcdefgh";
static move mov[1500];//big dumb buffer
size_t cnt = 0;
cnt += pawnMove(g,mov);
cnt += knightMove(g,(mov+cnt));
cnt += rookMove(g,(mov+cnt));
cnt += bishopMove(g,(mov+cnt));
cnt += kingMove(g,(mov+cnt));
cnt += queenMove(g,(mov+cnt));
move *m = findBest(mov,cnt,g);
if(m == NULL){
printf("bestmove 0000\n");
return;
}
char *end = "";
int yTo, xTo, yFrom, xFrom;
xTo = m->To % 8;
yTo = m->To / 8 + 1;
xFrom = m->From % 8;
yFrom = m->From / 8 + 1;
long long bit = 1LL << m->From;
if (m->Promo) {
end = "q\n";
} else {
end = "\n";
}
printf("bestmove %c%d%c%d%s", ltz[xFrom], yFrom, ltz[xTo], yTo, end);
}
game *fenGame(char *str) {
int rank = 7;
int file = 0;

View File

@ -1,60 +1,8 @@
const std = @import("std");
const c = @cImport({
@cInclude("main.h");
@cInclude("types.h");
});
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const alloc = gpa.allocator();
const stdin = std.io.getStdIn();
var reader = stdin.reader();
while (true) {
const line = try reader.readUntilDelimiterAlloc(alloc, '\n', std.math.maxInt(usize));
defer alloc.free(line);
const l = uci(line);
try std.io.getStdOut().writer().print("{s}", .{l});
}
}
fn uci(str: []const u8) []const u8 {
const pos = std.mem.indexOfAny(u8, str, " \t\n\r") orelse str.len;
const tok = str[0..pos];
if (std.mem.eql(u8, tok, "uci")) return "id name RatChess 0.1\nid author rat<3\nuciok";
if (std.mem.eql(u8, tok, "isready")) return "readyok\n";
if (std.mem.eql(u8, tok, "go")) return "bestmove ";
if (std.mem.eql(u8, tok, "position")) _ = uciPos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
return "";
}
fn uciPos(str: []const u8) [*c]c.game {
var buffer: [256]u8 = undefined;
const len = @min(str.len, buffer.len - 1);
@memcpy(buffer[0..len], str[0..len]);
buffer[len] = 0;
const game = c.fenGame(&buffer);
return game;
}
fn uciGo() []const u8 {
return "todo";
}
test "uci uci" {
const out = uci("uci");
try std.testing.expect(std.mem.eql(u8, out, "id name RatChess 0.1\nid author rat<3\nuciok"));
}
test "uci ready" {
const out = uci("isready");
try std.testing.expect(std.mem.eql(u8, out, "readyok\n"));
}
test "uci go" {
const out = uci("go");
const pos = std.mem.indexOfAny(u8, out, " \t\n\r") orelse out.len;
try std.testing.expect(std.mem.eql(u8, out[0..pos], "bestmove"));
_ = c.cmain();
}