Compare commits
2 Commits
34601f9c9d
...
f9cdd9a259
| Author | SHA1 | Date | |
|---|---|---|---|
| f9cdd9a259 | |||
| 5a7b5f1642 |
@ -1,4 +1,10 @@
|
|||||||
#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,6 +10,7 @@
|
|||||||
#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
|
||||||
|
|
||||||
@ -55,6 +56,13 @@ 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);
|
||||||
@ -66,7 +74,7 @@ int cmain() {
|
|||||||
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");
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *end = "";
|
char *end = "";
|
||||||
@ -83,10 +91,9 @@ int cmain() {
|
|||||||
end = "\n";
|
end = "\n";
|
||||||
}
|
}
|
||||||
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;
|
||||||
int file = 0;
|
int file = 0;
|
||||||
|
|||||||
54
src/main.zig
54
src/main.zig
@ -1,8 +1,60 @@
|
|||||||
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 {
|
||||||
_ = 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