zigster64 / zig-zag-zoe

Multiplayer TicTacToe - in Zig - using HTMX for that zero-javascript experience
http://zig-zag-zoe.com
MIT License
21 stars 1 forks source link
game htmx multiplayer-game tictactoe tictactoe-game zig zig-package

zig-zag-zoe

Multiplayer TicTacToe - in Zig - using HTMX for that zero-javascript experience

Online demo here http://zig-zag-zoe.com

.. (running on a t4g-nano instance on AWS - Linux ARM64, using less than 2mb memory for the whole container)

Uses Latest Zig 0.12.0 official release

screenshot

Install

Get Zig - https://ziglang.org/download/

ZigZagZoe now tracks :

Last successful build / test using 0.12.0-dev.2139+e025ad7b4

Is not currently working with the non-blocking / async branch of http.zig

git clone https://github.com/zigster64/zig-zag-zoe.git
cd zig-zag-zoe
zig build

Build and Run

zig build

.. or

zig build run

Now point your browsers at http://localhost:3000

.. or the equivalent address on the local network

On boot, the system will print a list of valid URLs that should be able to find the game.

Note that for multi-user play, you must bring up multiple browser tabs. Works best if you spawn a couple of new windows from the browser, and shrink them so they can sit side by side.

How to Play

Please visit teh Wiki / User Manual at

https://github.com/zigster64/zig-zag-zoe/wiki/Zig-Zag-Zoe-%E2%80%90-Zero-Wing-Edition

Bugs

There are a few lingering bugs that I havent got around to fixing yet.

Audio support on iOS + Safari is a lost cause - can fix it, but it requires a lot of JS code, and I figure that is outside the scope of a nice clean Zig application that Im trying to build here.

Also appreciate any other thrashing / trying to break the application, as it all helps make the Zig http ecosystem much more robust. Thanks.

Contributions

Yep, thats cool. Just go through the regular channels

If you have questions or RFCs - you can either post them as an issue here, or discuss on Zig discord.

Dont be too sad if it takes > 48hr for me to respond though ... will do my best.

More Modes and Gameplay ideas

Thinking up some new random modes to add to make the game harder - ideas most welcome.

Whats Interesting, from a Code point of view ?

This code is interesting, and worth a read for the following reasons :

Actually makes for a half decent templating tool, without having to find and import a templating lib.

ie

response.print("I can use {[name]s} and {[address]s} in a fmt.print statement, and it references fields from the struct passed ", .{
  .name = "Johnny Ziggy",
  .address = "22 Zig Street, Zigville, 90210"
});

Thats pretty good - dont really need a templating engine to do most things like that then, can just use std.fmt.print.

In fact, this is better than using a template engine, because you can store the HTML in actual .html files ... which means your editor goes into full HTML mode!

Otherwise, need to come up with yet another JSX like thing, and then write a bunch of editor tooling to understand it. Yuk !

Keep it simple I reckon, just use std.fmt, and just use .html files.

Not sure if its worth adding a templating lib - at least to do loops and some basic flow control, because its often much much better to take the full power of a real language instead, and just emit formatted fragments.

Go has a pretty comprehensive and well done Text Templating tool in the stdlib, but its quite a pain to use and impossible to debug when thing do go wrong, compared to doing the hard stuff in a real language.

HTMX thoughts

Yeah, its pretty cool, worth adding to your toolbelt. Not sure its really a 'replacement' for SPA type apps - I think it might be painful for larger apps. Not sure, havnt tried yet.

What it is 100% excellent for though is for doing apps where there is a lot of shared state between users. (Like a turn based game !) In that case, doing everything on the server, and not having any state at all on the frontend to sync, is really ideal. Its a good fit to this sort of problem.

Its super robust. You can do horrible things like reboot the backend, or hard refresh the front end(s) ... and it maintains state without a hiccup, and without needing any exception handling code at all. Very nice. It would be a nightmare doing this in react.

There are some very complex things you could do with a turn-based-multiplayer-game type of model though (doesnt have to be a game even) And being able to do that without touching JS, or writing a tonne of code to synch state on the frontends is really nice.

Its also a reasonable model for doing shared state between GUI frontends, just using the HTTP/SSE protocol too. Its just HTTP requests, so the networking is totally portable.