playMoves called corectly
This commit is contained in:
parent
da8eb581e3
commit
93e7ff61e0
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
int cmain();
|
int cmain();
|
||||||
game *fenGame(char *str);
|
game *fenGame(char *str);
|
||||||
void playMoves(game *g, char *moves);
|
game *playMoves(game *g, char *moves);
|
||||||
char* uciGo(game *g);
|
char* uciGo(game *g);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
#define BUFF_SIZE 4096
|
#define BUFF_SIZE 4096
|
||||||
|
|
||||||
game *fenGame(char *str);
|
game *fenGame(char *str);
|
||||||
void playMoves(game *g, char *moves);
|
game *playMoves(game *g, char *moves);
|
||||||
long long *findSet(game *g, long long bit);
|
long long *findSet(game *g, long long bit);
|
||||||
long long *charToSet(game *g, char c);
|
long long *charToSet(game *g, char c);
|
||||||
|
|
||||||
@ -73,8 +73,8 @@ char* uciGo(game *g){
|
|||||||
cnt += queenMove(g,(mov+cnt));
|
cnt += queenMove(g,(mov+cnt));
|
||||||
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 "";
|
return "0000";
|
||||||
}
|
}
|
||||||
|
|
||||||
char *end = "";
|
char *end = "";
|
||||||
@ -134,7 +134,7 @@ game *fenGame(char *str) {
|
|||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
void playMoves(game *g, char *moves) {
|
game* playMoves(game *g, char *moves) {
|
||||||
char *moveStr;
|
char *moveStr;
|
||||||
moveStr = strtok_r(moves, " ", &moves);
|
moveStr = strtok_r(moves, " ", &moves);
|
||||||
moveStr = strtok_r(moves, " ", &moves);
|
moveStr = strtok_r(moves, " ", &moves);
|
||||||
@ -146,5 +146,6 @@ void playMoves(game *g, char *moves) {
|
|||||||
makeMove(g, &m);
|
makeMove(g, &m);
|
||||||
moveStr = strtok_r(moves, " ", &moves);
|
moveStr = strtok_r(moves, " ", &moves);
|
||||||
}
|
}
|
||||||
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
33
src/main.zig
33
src/main.zig
@ -57,19 +57,38 @@ fn uci(str: []const u8, game: *c.game) uciRet {
|
|||||||
if (std.mem.eql(u8, tok, "uci")) return .{ .text = "id name RatChess 0.1\nid author rat<3\nuciok\n" };
|
if (std.mem.eql(u8, tok, "uci")) return .{ .text = "id name RatChess 0.1\nid author rat<3\nuciok\n" };
|
||||||
if (std.mem.eql(u8, tok, "isready")) return .{ .text = "readyok\n" };
|
if (std.mem.eql(u8, tok, "isready")) return .{ .text = "readyok\n" };
|
||||||
if (std.mem.eql(u8, tok, "go")) return .{ .move = uciGo(game) };
|
if (std.mem.eql(u8, tok, "go")) return .{ .move = uciGo(game) };
|
||||||
if (std.mem.eql(u8, tok, "position")) return .{ .game = uciPos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") };
|
if (std.mem.eql(u8, tok, "position")) return .{ .game = uciPos(str[(pos + 1)..]) };
|
||||||
if (std.mem.eql(u8, tok, "exit")) return .{ .exit = {} };
|
if (std.mem.eql(u8, tok, "exit")) return .{ .exit = {} };
|
||||||
return .{ .pass = {} };
|
return .{ .pass = {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uciPos(str: []const u8) [*c]c.game {
|
fn uciPos(str: []const u8) [*c]c.game {
|
||||||
|
const pos = std.mem.indexOfAny(u8, str, " \t\n\r") orelse str.len;
|
||||||
|
const tok = str[0..pos];
|
||||||
|
var game = fenGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
|
if (std.mem.eql(u8, tok, "fen")) return fenGame(str[pos..]);
|
||||||
|
if (std.mem.eql(u8, tok, "startpos")) {
|
||||||
|
game = playMoves(game, str[pos..]);
|
||||||
|
}
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fenGame(str: []const u8) [*c]c.game {
|
||||||
var buffer: [256]u8 = undefined;
|
var buffer: [256]u8 = undefined;
|
||||||
const len = @min(str.len, buffer.len - 1);
|
const len = @min(str.len, buffer.len - 1);
|
||||||
@memcpy(buffer[0..len], str[0..len]);
|
@memcpy(buffer[0..len], str[0..len]);
|
||||||
buffer[len] = 0;
|
buffer[len] = 0;
|
||||||
|
|
||||||
const game = c.fenGame(&buffer);
|
return c.fenGame(&buffer);
|
||||||
return game;
|
}
|
||||||
|
|
||||||
|
fn playMoves(game: [*c]c.game, str: []const u8) [*c]c.game {
|
||||||
|
var buffer: [2560]u8 = undefined; //this is bad
|
||||||
|
const len = @min(str.len, buffer.len - 1);
|
||||||
|
@memcpy(buffer[0..len], str[0..len]);
|
||||||
|
buffer[len] = 0;
|
||||||
|
|
||||||
|
return c.playMoves(game, &buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uciGo(game: *c.game) []const u8 {
|
fn uciGo(game: *c.game) []const u8 {
|
||||||
@ -77,25 +96,25 @@ fn uciGo(game: *c.game) []const u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "uci uci" {
|
test "uci uci" {
|
||||||
const game = uciPos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
const out = uci("uci", game);
|
const out = uci("uci", game);
|
||||||
try std.testing.expect(out == .text);
|
try std.testing.expect(out == .text);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "uci ready" {
|
test "uci ready" {
|
||||||
const game = uciPos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
const out = uci("isready", game);
|
const out = uci("isready", game);
|
||||||
try std.testing.expect(out == .text);
|
try std.testing.expect(out == .text);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "uci go" {
|
test "uci go" {
|
||||||
const game = uciPos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
const out = uci("go", game);
|
const out = uci("go", game);
|
||||||
try std.testing.expect(out == .move);
|
try std.testing.expect(out == .move);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "uci position" {
|
test "uci position" {
|
||||||
const game = uciPos("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
||||||
const out = uci("position startpos", game);
|
const out = uci("position startpos", game);
|
||||||
try std.testing.expect(out == .game);
|
try std.testing.expect(out == .game);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user