Skip to content

Commit c9fe54d

Browse files
committed
Add option to display version
1 parent 3f99166 commit c9fe54d

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ bot client for [mini-RTS-game](https://github.com/pwalig/mini-RTS-server)
55
```
66
git clone https://github.com/pwalig/mini-RTS-zig-bot.git
77
cd mini-RTS-zig-bot
8-
zig build
8+
zig build -Doptimize=ReleaseSmall
99
```
10+
Optionally set `-Doptimize=ReleaseFast`.
11+
`ReleaseSmall` is prefered due to fairly large delay between game ticks, meaning zig-bot does not need to be super performant.
12+
1013
For information about installing zig see: https://ziglang.org/learn/getting-started/
1114

1215
# Run

src/client.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ pub const Client = struct {
8282
@intFromEnum(Message.Type.no) => {
8383
if (self.state == State.Connected) {
8484
const last = self.name.len - 1;
85-
if (self.name[last] == '~') return error.UnableToNameSelf;
85+
if (self.name[last] == '~') {
86+
try std.io.getStdOut().writer().print("unable to set a name\nlook into mini-rts-server .config file and make sure characters z, i, g, b, o, t are set as valid name characters or contact your mini-rts-server administrator\nalso make sure not too many zigbots are playing at the same time\n", .{});
87+
return error.UnableToNameSelf;
88+
}
8689
self.name[last] += 1;
8790
try self.send("n");
8891
try self.send(&self.name);

src/main.zig

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const print = std.debug.print;
44

55
const Client = @import("client.zig").Client;
66

7-
const buffsize = 50;
7+
const version = "1.0.0";
88

99
pub fn main() !void {
1010
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
@@ -13,17 +13,22 @@ pub fn main() !void {
1313

1414
var args = try std.process.ArgIterator.initWithAllocator(allocator);
1515
defer args.deinit();
16-
// The first (0 index) Argument is the path to the program.
16+
1717
const program_name = args.next() orelse "mini-RTS-zig-bot";
1818

1919
const host_value = args.next() orelse {
20-
print("usage {s} <host> <port> \n", .{program_name});
21-
return error.NoPort;
20+
print("no host name or ip address provided\nusage {s} <host> <port>\n", .{program_name});
21+
return;
2222
};
2323

24+
if (std.mem.eql(u8, host_value, "--version") or std.mem.eql(u8, host_value, "-v")) {
25+
try std.io.getStdOut().writer().print("{s}\n", .{version});
26+
return;
27+
}
28+
2429
const port_value = args.next() orelse {
25-
print("usage {s} <host> <port> \n", .{program_name});
26-
return error.NoPort;
30+
print("no port provided\nusage {s} <host> <port>\n", .{program_name});
31+
return;
2732
};
2833
const port = try std.fmt.parseInt(u16, port_value, 10);
2934

0 commit comments

Comments
 (0)