fixed position command bug
All checks were successful
Verify build / verify_build (push) Successful in 1m11s

This commit is contained in:
k 2025-10-22 09:43:50 -04:00
parent c1eade9440
commit 775228d691
2 changed files with 4 additions and 2 deletions

View File

@ -53,7 +53,7 @@ fn uciPos(str: []const u8, alloc: std.mem.Allocator) *types.game {
if (std.mem.eql(u8, tok, "fen")) return fenGame(str[pos..], alloc);
if (std.mem.eql(u8, tok, "startpos")) {
var game = fenGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc);
game = mov.playMoves(game, str[pos..]);
game = mov.playMoves(game, str[(pos)..]);
return game;
}
return fenGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); //this should be an error
@ -95,7 +95,7 @@ fn uciGo(game: *types.game, alloc: std.mem.Allocator) []u8 {
const str = alloc.alloc(u8, 5) catch unreachable;
mov.knightMove(game, &moves);
if (moves.capacity == 0) {
@memcpy(str.ptr, "err");
@memcpy(str.ptr, "0000");
return str;
}
mov.moveTypeToStr(moves.items[0], str);

View File

@ -25,6 +25,8 @@ pub fn playMoves(game: *types.game, str: []const u8) *types.game {
if (str.len < 4) return game;
var splitItr = std.mem.splitSequence(u8, str, " ");
while (splitItr.next()) |moveString| {
if (moveString.len < 4 or moveString[0] > 'h')
continue;
var move: types.move = .{ .To = 0, .From = 0, .Promo = 0 };
if (moveString.len < 4) continue;
move.From = (moveString[0] - 'a') + (moveString[1] - '1') * 8;