R5F5KMWWZ4VS67CSIWRNRM4LNPPXVXSQZLHEZMT6XZODV4AK2MBQC
NCFUC2F34HIV6BZYYMMHIGQOD6G6BUJZYY4RINPCAKGCSVCC46DAC
I4AKZYZM5LOD7SNZRNWY34KWOHE34QPEWO6TIGHYMJACXOJKBMPQC
X3FYJUNL5ORLRC7TW3C5OMNZOX4JEWL73RXOQZLRKLAUBVNARIMAC
RNEXG5IFDKMHSUR6RMNTI3Y32ORLVMZ6UJYKHLV2XBMT2QONBTVQC
2TRWSYAHRLVT2V6FGRNHKYQZKFDCMKMJOI2G3HYMOVLSJMGSBFDQC
XRCSCQWQKVYASIMAJO7JVUJXHXE44FZROCJPBW2BR7EE4RPEIBKAC
HNCUAGWTMX3UHH2KFTUM3M6Q4CC33M6PVE5DWZWFG5UM2Y7J2ZKAC
FRUDIRWXGFOZERET3DNUNAZ5HSA3G32JZX6WMIXNGZOACTTCRIQAC
A46B5KNQFPTZEIL2JZKD2CQELGU3COE6FGTV2ABS5U7DVTVDGEBQC
GLTWBA5NKQIHAL23SWKCFOZQH62W6B3LX4RC5GFQUEQUIYN4OKSAC
3N3FYEBBZ6RLFCFKG2FNHHRDUZBOVBAAXAHBUPSOB3FN5HMWLVDAC
var pv_length: [64]usize = [_]usize{0} ** 64;
var pv_table: [64][64]BitMove = [_][64]BitMove{[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** 64} ** 64;
var nodes: usize = undefined;
var pv_length: [MAX_PLY]usize = undefined;
var pv_table: [MAX_PLY][MAX_PLY]BitMove = undefined;
const scr = try negamax(gs, ALPHA, BETA, depth);
// clear helper data for search
{
score.killer_moves = [_][MAX_PLY]BitMove{
[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** MAX_PLY,
} ** 2;
score.history_moves = [_][64]usize{[_]usize{0} ** 64} ** 12;
pv_length = [_]usize{0} ** MAX_PLY;
pv_table = [_][MAX_PLY]BitMove{
[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** MAX_PLY,
} ** MAX_PLY;
nodes = 0;
}
// loop over the pv_line
var count: usize = 0;
while (count < pv_length[0]) : (count += 1) {
// print PV move
const m = pv_table[0][count];
const move = try std.fmt.allocPrint(
gs.allocator,
"{s}{s} ",
.{ @tagName(m.source), @tagName(m.target) },
);
try ret.appendSlice(move);
if (current_depth == depth) {
try print_info(gs, scr, current_depth, true);
} else {
try print_info(gs, scr, current_depth, false);
}
const bestmove = try std.fmt.allocPrint(gs.allocator, "bestmove {s}{s}{s}\n", .{
@tagName(pv_table[0][0].source),
@tagName(pv_table[0][0].target),
if (pv_table[0][0].prom != .none) @tagName(pv_table[0][0].prom) else "",
});
try ret.appendSlice(bestmove);
// TO BE REMOVED BELOW THIS LINE...
// ---------------------------------------------------- //
// clear helper data for search
{
score.killer_moves = [_][MAX_PLY]BitMove{
[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** MAX_PLY,
} ** 2;
score.history_moves = [_][64]usize{[_]usize{0} ** 64} ** 12;
pv_length = [_]usize{0} ** MAX_PLY;
pv_table = [_][MAX_PLY]BitMove{
[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** MAX_PLY,
} ** MAX_PLY;
nodes = 0;
}
}
fn print_info(gs: *const GameState, scr: isize, depth: usize, best: bool) !void {
var ret = std.ArrayList(u8).init(gs.allocator);
defer ret.deinit();
const info = try std.fmt.allocPrint(
gs.allocator,
"info score cp {d} depth {d} nodes {d} pv ",
.{ scr, depth, nodes },
);
try ret.appendSlice(info);
// loop over the pv_line
var count: usize = 0;
while (count < pv_length[0]) : (count += 1) {
// print PV move
const m = pv_table[0][count];
const move = try std.fmt.allocPrint(
gs.allocator,
"{s}{s} ",
.{ @tagName(m.source), @tagName(m.target) },
);
try ret.appendSlice(move);
}
try ret.append('\n');
if (best) {
const bestmove = try std.fmt.allocPrint(gs.allocator, "bestmove {s}{s}{s}\n", .{
@tagName(pv_table[0][0].source),
@tagName(pv_table[0][0].target),
if (pv_table[0][0].prom != .none) @tagName(pv_table[0][0].prom) else "",
});
try ret.appendSlice(bestmove);
}
_ = try std.io.getStdOut().write(ret.items);
// Killer moves
pub var killer_moves: [2][KILLER_MAX]BitMove = .{
[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** KILLER_MAX,
[_]BitMove{@bitCast(BitMove, @as(BitMoveType, 0))} ** KILLER_MAX,
};
pub var history_moves: [12][64]usize = [_][64]usize{[_]usize{0} ** 64} ** 12;
std.debug.print("{s}", .{try search.bestMove(&gs, 5)});
// var ml = try Board.MoveList.init(0);
// try gs.generateMoves(&ml);
// std.sort.sort(Board.MovePrio, ml.slice(), {}, comptime Board.MovePrio.moreThan);
// for (ml.slice()) |mp| {
// mp.move.show();
// std.debug.print("{d}\n", .{mp.score});
// }
try search.bestMove(&gs, 5);