LWF4H4TMNZYUKTCVDALXQLBE3U5AXQJ3LLNUJJ7YGTLG6T2O33JAC fn parseMove(self: *const @This(), in: Str) !?BitMove {
if (words.next()) |start| {switch (start[0]) {'s' => {// startpostry self.parseFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");},'f' => {// fenconst end = std.mem.indexOf(u8, in, "moves");if (end) |e| {try self.parseFEN(in[13 .. e - 1]);for ([_]u3{ 0, 1, 2, 3, 4, 5 }) |_| {_ = words.next();}} else {try self.parseFEN(in[13..]);return;}},else => return error.InvalidPosition,}} else return error.InvalidPosition;if (words.next()) |moves| {if (moves[0] != 'm') return error.InvalidPosition;while (words.next()) |move| {const m = try self.parseMove(move);_ = self.makeMove(m, .all);}}}fn parseMove(self: @This(), in: Str) !BitMove {
// gs.show();
{// gs.show();const got = try gs.parseMove("d7c8B");try std.testing.expectEqual(Square.d7, got.source);try std.testing.expectEqual(Square.c8, got.target);try std.testing.expectEqual(Chess.PE.B, got.prom);try std.testing.expectEqual(true, got.capture);try std.testing.expectEqual(Chess.PE.P, got.piece);// _ = gs.makeMove(got, .all);// gs.show();}{// gs.show();const got = gs.parseMove("d7d8");try std.testing.expectError(error.IllegalMove, got);}}test "UCI - parsePosition" {var gs = try GameState.init(null);
try std.testing.expectEqual(Square.d7, got.?.source);try std.testing.expectEqual(Square.c8, got.?.target);try std.testing.expectEqual(Chess.PE.B, got.?.prom);try std.testing.expectEqual(true, got.?.capture);try std.testing.expectEqual(Chess.PE.P, got.?.piece);
{try gs.parsePosition("position startpos moves e2e4 e7e5");// gs.show();}