Compare commits
No commits in common. "f9cdd9a259314a725c2aa17a901dec488f57e364" and "34601f9c9d8f58a006f9b383b19cf400a60ce1eb" have entirely different histories.
f9cdd9a259
...
34601f9c9d
@ -1,10 +1,4 @@
|
|||||||
#ifndef MAIN_H
|
#ifndef MAIN_H
|
||||||
#define MAIN_H
|
#define MAIN_H
|
||||||
#include "types.h"
|
|
||||||
|
|
||||||
int cmain();
|
int cmain();
|
||||||
game *fenGame(char *str);
|
|
||||||
void playMoves(game *g, char *moves);
|
|
||||||
void uciGo(game *g);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
13
src/main.c
13
src/main.c
@ -10,7 +10,6 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "help.h"
|
#include "help.h"
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
#define BUFF_SIZE 4096
|
#define BUFF_SIZE 4096
|
||||||
|
|
||||||
@ -56,13 +55,6 @@ int cmain() {
|
|||||||
} else if (!strcmp("isready", token)) {
|
} else if (!strcmp("isready", token)) {
|
||||||
printf("readyok\n");
|
printf("readyok\n");
|
||||||
} else if (!strcmp("go", token)) {
|
} else if (!strcmp("go", token)) {
|
||||||
uciGo(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void uciGo(game *g){
|
|
||||||
char ltz[] = "abcdefgh";
|
|
||||||
static move mov[1500];//big dumb buffer
|
static move mov[1500];//big dumb buffer
|
||||||
size_t cnt = 0;
|
size_t cnt = 0;
|
||||||
cnt += pawnMove(g,mov);
|
cnt += pawnMove(g,mov);
|
||||||
@ -74,7 +66,7 @@ void uciGo(game *g){
|
|||||||
move *m = findBest(mov,cnt,g);
|
move *m = findBest(mov,cnt,g);
|
||||||
if(m == NULL){
|
if(m == NULL){
|
||||||
printf("bestmove 0000\n");
|
printf("bestmove 0000\n");
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *end = "";
|
char *end = "";
|
||||||
@ -92,7 +84,8 @@ void uciGo(game *g){
|
|||||||
}
|
}
|
||||||
printf("bestmove %c%d%c%d%s", ltz[xFrom], yFrom, ltz[xTo], yTo, end);
|
printf("bestmove %c%d%c%d%s", ltz[xFrom], yFrom, ltz[xTo], yTo, end);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
game *fenGame(char *str) {
|
game *fenGame(char *str) {
|
||||||
int rank = 7;
|
int rank = 7;
|
||||||
|
|||||||
54
src/main.zig
54
src/main.zig
@ -1,60 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const c = @cImport({
|
const c = @cImport({
|
||||||
@cInclude("main.h");
|
@cInclude("main.h");
|
||||||
@cInclude("types.h");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
_ = c.cmain();
|
||||||
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"));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user