~macaptain/lkdo-chess

f747faa3854d8b337509530928436ef5d9116b86 — Michael Captain 3 years ago
Initial commit
3 files changed, 53 insertions(+), 0 deletions(-)

A .gitignore
A build.zig
A src/main.zig
A  => .gitignore +1 -0
@@ 1,1 @@
zig-cache/

A  => build.zig +27 -0
@@ 1,27 @@
const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
    // Standard target options allows the person running `zig build` to choose
    // what target to build for. Here we do not override the defaults, which
    // means any target is allowed, and the default is native. Other options
    // for restricting supported target set are available.
    const target = b.standardTargetOptions(.{});

    // Standard release options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("lkdo", "src/main.zig");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
}

A  => src/main.zig +25 -0
@@ 1,25 @@
const std = @import("std");

const VERSION = "0.0.1";

fn uci_loop() !void {
    const stdin = std.io.getStdIn().reader();
    const stdout = std.io.getStdOut().writer();
    var line_buf: [2000]u8 = undefined;
    while (true) {
        const uci_in = (try stdin.readUntilDelimiterOrEof(line_buf[0..], '\n')).?;
        if (std.mem.eql(u8, uci_in, "uci")) {
            try stdout.print("id name LKDO v{}\n", .{VERSION});
            try stdout.print("id author macaptain\n", .{});
            try stdout.print("uciok\n", .{});
        } else if (std.mem.eql(u8, uci_in, "quit")) {
            return;
        } else if (std.mem.eql(u8, uci_in, "isready")) {
            try stdout.print("readyok\n", .{});
        }
    }
}

pub fn main() !void {
    try uci_loop();
}