Compare commits
No commits in common. "47dcfcfeb0efccc9f69507978fd0f1adf7093fa8" and "a7c9f4f472226e03502bbfc11ec484250e375bd6" have entirely different histories.
47dcfcfeb0
...
a7c9f4f472
3 changed files with 8 additions and 122 deletions
35
TODO.org
35
TODO.org
|
|
@ -1,35 +0,0 @@
|
||||||
* Rewrite[25%]
|
|
||||||
- [ ] UciGo
|
|
||||||
- [ ] move gen
|
|
||||||
- [ ] pawn
|
|
||||||
- [ ] knight
|
|
||||||
- [ ] rook
|
|
||||||
- [ ] bishop
|
|
||||||
- [ ] king
|
|
||||||
- [ ] queen
|
|
||||||
- [ ] move eval
|
|
||||||
- [X] uci interface
|
|
||||||
- [-] uciPos
|
|
||||||
- [ ] fengame
|
|
||||||
- [ ] charToSet
|
|
||||||
- [X] playmoves
|
|
||||||
- [ ] types
|
|
||||||
- [ ] game
|
|
||||||
- [ ] move
|
|
||||||
- [ ] sets
|
|
||||||
* Misc [0%]
|
|
||||||
- [ ] errors
|
|
||||||
- [ ] Proper zig errors
|
|
||||||
- [ ] Proper error handleing
|
|
||||||
- [ ] Speed up
|
|
||||||
- [ ] GPU move gen
|
|
||||||
- [ ] GPU move eval
|
|
||||||
- [ ] clean code
|
|
||||||
- [ ] split code into smaller files
|
|
||||||
- [ ] remove "//this is bad" comments for good code
|
|
||||||
- [ ] more zig stiled controle flow
|
|
||||||
- [ ] uci Config
|
|
||||||
* Bugs
|
|
||||||
** C move gen broken
|
|
||||||
** C findBest slow
|
|
||||||
** FenGame failes to set white to move
|
|
||||||
11
src/main.zig
11
src/main.zig
|
|
@ -43,7 +43,7 @@ fn uci(str: []const u8, game: *types.game, alloc: std.mem.Allocator) types.uciRe
|
||||||
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, alloc) };
|
if (std.mem.eql(u8, tok, "go")) return .{ .move = uciGo(game, alloc) };
|
||||||
if (std.mem.eql(u8, tok, "position")) return .{ .game = uciPos(str[(pos + 1)..], alloc) };
|
if (std.mem.eql(u8, tok, "position")) return .{ .game = uciPos(str[(pos + 1)..], alloc) };
|
||||||
if (std.mem.eql(u8, tok, "quit")) return .{ .exit = {} };
|
if (std.mem.eql(u8, tok, "exit")) return .{ .exit = {} };
|
||||||
return .{ .pass = {} };
|
return .{ .pass = {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,17 +93,11 @@ fn uciGo(game: *types.game, alloc: std.mem.Allocator) []u8 {
|
||||||
var moves = std.ArrayList(types.move).init(alloc);
|
var moves = std.ArrayList(types.move).init(alloc);
|
||||||
defer moves.deinit();
|
defer moves.deinit();
|
||||||
const str = alloc.alloc(u8, 5) catch unreachable;
|
const str = alloc.alloc(u8, 5) catch unreachable;
|
||||||
mov.pawnMove(game, &moves);
|
|
||||||
mov.rookMove(game, &moves);
|
|
||||||
mov.knightMove(game, &moves);
|
mov.knightMove(game, &moves);
|
||||||
mov.bishipMove(game, &moves);
|
|
||||||
mov.kingMove(game, &moves);
|
|
||||||
mov.quenMove(game, &moves);
|
|
||||||
if (moves.capacity == 0) {
|
if (moves.capacity == 0) {
|
||||||
@memcpy(str.ptr, "0000");
|
@memcpy(str.ptr, "0000");
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
mov.moveTypeToStr(moves.items[0], str);
|
mov.moveTypeToStr(moves.items[0], str);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
@ -147,9 +141,7 @@ test "uci position" {
|
||||||
defer _ = gpa.deinit();
|
defer _ = gpa.deinit();
|
||||||
const alloc = gpa.allocator();
|
const alloc = gpa.allocator();
|
||||||
const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc);
|
const game = uciPos("fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", alloc);
|
||||||
const gameb = uciPos("startpos", alloc);
|
|
||||||
defer alloc.destroy(game);
|
defer alloc.destroy(game);
|
||||||
defer alloc.destroy(gameb);
|
|
||||||
|
|
||||||
const out = uci("position startpos", game, alloc);
|
const out = uci("position startpos", game, alloc);
|
||||||
defer alloc.destroy(out.game);
|
defer alloc.destroy(out.game);
|
||||||
|
|
@ -157,5 +149,4 @@ test "uci position" {
|
||||||
try std.testing.expect(out.game.whiteToMove == true);
|
try std.testing.expect(out.game.whiteToMove == true);
|
||||||
try std.testing.expect(out.game.white.king != 0);
|
try std.testing.expect(out.game.white.king != 0);
|
||||||
try std.testing.expect(out.game.black.king != 0);
|
try std.testing.expect(out.game.black.king != 0);
|
||||||
try std.testing.expectEqualDeep(game, gameb);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
84
src/move.zig
84
src/move.zig
|
|
@ -106,61 +106,13 @@ pub fn charToSet(g: *types.game, chr: u8) *u64 {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pawnMove(game: *types.game, arr: *std.ArrayList(types.move)) void {
|
// pub fn pawnMove(arr: std.ArrayList(c.move)) void {
|
||||||
_ = game;
|
// const move = c.move{ .From = 8, .To = 16, .Promo = 0 };
|
||||||
_ = arr;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bishipMove(game: *types.game, arr: *std.ArrayList(types.move)) void {
|
pub fn sqrScan(rook: u64, hit: u64, flip: bool) u64 {
|
||||||
_ = game;
|
const vecLut: [64]u64 = undefined; //todo comptime init
|
||||||
_ = arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn kingMove(game: *types.game, arr: *std.ArrayList(types.move)) void {
|
|
||||||
_ = game;
|
|
||||||
_ = arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn quenMove(game: *types.game, arr: *std.ArrayList(types.move)) void {
|
|
||||||
const set = if (game.whiteToMove) &game.white.queen else &game.black.queen;
|
|
||||||
const full = fullSet(&game.white) | fullSet(&game.black);
|
|
||||||
var val = set.*;
|
|
||||||
const n = @popCount(val);
|
|
||||||
for (0..n) |_| {
|
|
||||||
const pos = @ctz(val);
|
|
||||||
const bit = @as(u64, 1) << @truncate(pos);
|
|
||||||
var moves = sqrScan(bit, full, false);
|
|
||||||
moves |= @bitReverse(sqrScan(bit, full, true));
|
|
||||||
val = val ^ (@as(u64, 1) << @truncate(pos));
|
|
||||||
|
|
||||||
bitboardToMoves(pos, moves, arr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn rookMove(game: *types.game, arr: *std.ArrayList(types.move)) void {
|
|
||||||
const set = if (game.whiteToMove) &game.white.rooks else &game.black.rooks;
|
|
||||||
const full = fullSet(&game.white) | fullSet(&game.black);
|
|
||||||
var val = set.*;
|
|
||||||
const n = @popCount(val);
|
|
||||||
for (0..n) |_| {
|
|
||||||
const pos = @ctz(val);
|
|
||||||
const bit = @as(u64, 1) << @truncate(pos);
|
|
||||||
var moves = sqrScan(bit, full, false);
|
|
||||||
moves |= @bitReverse(sqrScan(bit, full, true));
|
|
||||||
val = val ^ (@as(u64, 1) << @truncate(pos));
|
|
||||||
|
|
||||||
bitboardToMoves(pos, moves, arr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrScan(rook: u64, hit: u64, flip: bool) u64 {
|
|
||||||
const vecLut: [64]u64 = comptime blk: {
|
|
||||||
var value: [64]u64 = undefined;
|
|
||||||
for (0..64) |i| {
|
|
||||||
value[i] = vecCalc(@truncate(i));
|
|
||||||
}
|
|
||||||
break :blk value;
|
|
||||||
};
|
|
||||||
var center = rook;
|
var center = rook;
|
||||||
var hits = hit;
|
var hits = hit;
|
||||||
if (flip) {
|
if (flip) {
|
||||||
|
|
@ -175,36 +127,14 @@ fn sqrScan(rook: u64, hit: u64, flip: bool) u64 {
|
||||||
var min: u64 = vec;
|
var min: u64 = vec;
|
||||||
for (0..n) |_| {
|
for (0..n) |_| {
|
||||||
const pos = @ctz(attackedBits);
|
const pos = @ctz(attackedBits);
|
||||||
const bit = @as(u64, 1) << @truncate(pos);
|
const bit = @as(u64, 1) << pos;
|
||||||
attackedBits = attackedBits & ~bit;
|
attackedBits = attackedBits & ~bit;
|
||||||
if (bit - 1 < min) min = bit - 1;
|
if (bit - 1 < min) min = bit - 1;
|
||||||
}
|
}
|
||||||
min = min & (~center);
|
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vecCalc(i: u8) u64 {
|
|
||||||
var ret: u64 = 0;
|
|
||||||
const col = i % 8;
|
|
||||||
|
|
||||||
// "West" ray
|
|
||||||
for (1..8) |n| {
|
|
||||||
if (i < n or (i - n) % 8 != col)
|
|
||||||
break;
|
|
||||||
ret = ret | @as(u64, 1) << (i - n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// "North" ray
|
|
||||||
for (1..8) |n| {
|
|
||||||
const new_pos = i + (n * 8);
|
|
||||||
if (new_pos > 63)
|
|
||||||
break;
|
|
||||||
ret = ret | @as(u64, 1) << new_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn knightMove(g: *types.game, arr: *std.ArrayList(types.move)) void {
|
pub fn knightMove(g: *types.game, arr: *std.ArrayList(types.move)) void {
|
||||||
const moveLut: [64]u64 = comptime blk: {
|
const moveLut: [64]u64 = comptime blk: {
|
||||||
var value: [64]u64 = undefined;
|
var value: [64]u64 = undefined;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue