Compare commits
2 Commits
94b501fd17
...
775228d691
| Author | SHA1 | Date | |
|---|---|---|---|
| 775228d691 | |||
| c1eade9440 |
@ -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, "fen")) return fenGame(str[pos..], alloc);
|
||||||
if (std.mem.eql(u8, tok, "startpos")) {
|
if (std.mem.eql(u8, tok, "startpos")) {
|
||||||
var game = fenGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc);
|
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 game;
|
||||||
}
|
}
|
||||||
return fenGame("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc); //this should be an error
|
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;
|
const str = alloc.alloc(u8, 5) catch unreachable;
|
||||||
mov.knightMove(game, &moves);
|
mov.knightMove(game, &moves);
|
||||||
if (moves.capacity == 0) {
|
if (moves.capacity == 0) {
|
||||||
@memcpy(str.ptr, "err");
|
@memcpy(str.ptr, "0000");
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
mov.moveTypeToStr(moves.items[0], str);
|
mov.moveTypeToStr(moves.items[0], str);
|
||||||
|
|||||||
26
src/move.zig
26
src/move.zig
@ -25,6 +25,8 @@ pub fn playMoves(game: *types.game, str: []const u8) *types.game {
|
|||||||
if (str.len < 4) return game;
|
if (str.len < 4) return game;
|
||||||
var splitItr = std.mem.splitSequence(u8, str, " ");
|
var splitItr = std.mem.splitSequence(u8, str, " ");
|
||||||
while (splitItr.next()) |moveString| {
|
while (splitItr.next()) |moveString| {
|
||||||
|
if (moveString.len < 4 or moveString[0] > 'h')
|
||||||
|
continue;
|
||||||
var move: types.move = .{ .To = 0, .From = 0, .Promo = 0 };
|
var move: types.move = .{ .To = 0, .From = 0, .Promo = 0 };
|
||||||
if (moveString.len < 4) continue;
|
if (moveString.len < 4) continue;
|
||||||
move.From = (moveString[0] - 'a') + (moveString[1] - '1') * 8;
|
move.From = (moveString[0] - 'a') + (moveString[1] - '1') * 8;
|
||||||
@ -81,8 +83,28 @@ pub fn knightMove(g: *types.game, arr: *std.ArrayList(types.move)) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn knightCalc(index: u8) u64 {
|
fn knightCalc(index: u8) u64 {
|
||||||
_ = index;
|
var moves: u64 = 0;
|
||||||
return @as(u64,1)<<32;
|
const offsets = [_]i8{ 17, -17, 15, -15, 10, -10, 6, -6 };
|
||||||
|
var cnt: u8 = undefined;
|
||||||
|
for (offsets) |off| {
|
||||||
|
if (off > 0) {
|
||||||
|
cnt = index + @abs(off);
|
||||||
|
} else if (index > @abs(off)) { //Icky bad that zig makes me do
|
||||||
|
cnt = index - @abs(off);
|
||||||
|
}
|
||||||
|
const fromFile: i32 = index % 8;
|
||||||
|
const toFile: i32 = cnt % 8;
|
||||||
|
const fromRank: i32 = index / 8;
|
||||||
|
const toRank: i32 = cnt / 8;
|
||||||
|
|
||||||
|
const fileDiff = @abs(fromFile - toFile);
|
||||||
|
const rankDiff = @abs(fromRank - toRank);
|
||||||
|
if (!((fileDiff == 1 and rankDiff == 2) or
|
||||||
|
(fileDiff == 2 and rankDiff == 1)) or cnt > 63)
|
||||||
|
continue;
|
||||||
|
moves = moves | @as(u64, 1) << @truncate(cnt);
|
||||||
|
}
|
||||||
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bitboardToMoves(start: u8, moves: u64, arr: *std.ArrayList(types.move)) void {
|
fn bitboardToMoves(start: u8, moves: u64, arr: *std.ArrayList(types.move)) void {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user