fenGame fn connected to zig
This commit is contained in:
parent
986e8c8334
commit
5a7b5f1642
@ -1,4 +1,10 @@
|
||||
#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
|
||||
|
||||
13
src/main.c
13
src/main.c
@ -10,6 +10,7 @@
|
||||
#include "types.h"
|
||||
#include "help.h"
|
||||
#include "eval.h"
|
||||
#include "main.h"
|
||||
|
||||
#define BUFF_SIZE 4096
|
||||
|
||||
@ -55,6 +56,13 @@ int cmain() {
|
||||
} else if (!strcmp("isready", token)) {
|
||||
printf("readyok\n");
|
||||
} else if (!strcmp("go", token)) {
|
||||
uciGo(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uciGo(game *g){
|
||||
char ltz[] = "abcdefgh";
|
||||
static move mov[1500];//big dumb buffer
|
||||
size_t cnt = 0;
|
||||
cnt += pawnMove(g,mov);
|
||||
@ -66,7 +74,7 @@ int cmain() {
|
||||
move *m = findBest(mov,cnt,g);
|
||||
if(m == NULL){
|
||||
printf("bestmove 0000\n");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
char *end = "";
|
||||
@ -84,8 +92,7 @@ int cmain() {
|
||||
}
|
||||
printf("bestmove %c%d%c%d%s", ltz[xFrom], yFrom, ltz[xTo], yTo, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
game *fenGame(char *str) {
|
||||
int rank = 7;
|
||||
|
||||
54
src/main.zig
54
src/main.zig
@ -1,8 +1,60 @@
|
||||
const std = @import("std");
|
||||
const c = @cImport({
|
||||
@cInclude("main.h");
|
||||
@cInclude("types.h");
|
||||
});
|
||||
|
||||
pub fn main() !void {
|
||||
_ = c.cmain();
|
||||
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"));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user