Chess engine in zig
const std = @import("std");

const Board = @import("Board.zig");
const Search = @import("Search.zig").Search;

const uci = @import("uci.zig");
const score = @import("score.zig");

var debug = false;

pub fn main() !void {
    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();

    if (debug) {
        var gs = try Board.GameState.init(
            arena.allocator(),
            "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1", // tricky
            // "rnbqkb1r/pp1p1pPp/8/2p1pP2/1P1P4/3P3P/P1P1P3/RNBQKBNR w KQkq e6 0 1" // killer
            // "r2q1rk1/ppp2ppp/2n1bn2/2b1p3/3pP3/3P1NPP/PPP1NPB1/R1BQ1RK1 b - - 0 9", // cmk_pos
            // "2r3k1/R7/8/1R6/8/8/P4KPP/8 w - - 0 40 ", // repetition
        );
        defer gs.deinit();

        gs.show();

        var search = try Search.init(&gs, uci.EngineOptions{});

        // var ml = try Board.MoveList.init(0);
        // try gs.generateMoves(&ml);
        // score.moves(&gs, &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(.{});
    } else try uci.loop(arena.allocator());
}

const build_options = @import("build_options");
test "All" {
    _ = @import("Attacks.zig");
    _ = @import("Board.zig");
    _ = @import("Chess.zig");
    _ = @import("Search.zig");
    _ = @import("Transposition.zig");
    _ = @import("eval.zig");
    _ = @import("uci.zig");
    _ = @import("zobrist.zig");

    if (build_options.nnue) {
        _ = @import("nnue.zig");
    }

    // _ = @import("perft.zig");
}