Skip to content
ezekielelvisPublic

About

A multiplayer, turn-based tank game for the browser. It is played on a hex grid with fog of war and a shrinking arena.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

tank-ops

A multiplayer, turn-based tank game for the browser. Hex grid, fog of war, a shrinking arena, and simultaneous orders: both players plan, then the turn resolves. Client in TypeScript (canvas), server in Go (websockets).

scene from the game

Play

You need Go 1.22+, TypeScript (tsc) and make.

make run          # builds the client, serves on http://localhost:8000

Open it in a browser, then either

  • pick easy, medium or hard bot to play the computer, or
  • type a room code and join room; share the code with a friend who joins the same room.

Controls

mouse / touch keyboard
select and move a tank press a tank, drag along hexes tab picks a tank, q e a d z c step (same key back undoes)
fire hold on a tank, drag to aim f, then q e a d z c to aim
clear a tank's orders backspace
send turn send turn button enter
pan, zoom drag, wheel, pinch arrow keys, + -
sound mute button m (remembered)
help how to play button h

q e are up-left and up-right, a d left and right, z c down-left and down-right. A screen reader announces selections, orders and what happened each turn. The game pauses for 30 seconds if your connection drops, and a refreshed page rejoins the game it was in.

How a turn works

  1. Give each tank one order: move (drag a path up to 5 hexes) or fire (pick one of six directions, range 3).
  2. Press send turn. When both players have sent (or the 90 s turn timer runs out) the turn resolves.
  3. One player's orders resolve before the other's, and the order flips every turn. Nobody is told who is first.
  4. You only see enemies within 2 hexes of one of your tanks. Shots are stopped by obstacles and tanks.
  5. After a few turns the outer ring of the arena starts collapsing. Tanks on a collapsing ring are destroyed.
  6. Last side with a tank wins.

The computer opponent

The bot plays by the same rules and sees only what you see. Levels:

level behaviour
easy advances on the enemy and shoots when lined up (misses some chances)
medium scores every move and shot: threats, cover, spread, the closing arena
hard medium's shortlist, tested against many guesses of the enemy's position and orders using the real game rules, two turns deep. It also works out who resolves first from the turn results.

go test -run TestBotStrength ./internal/bot plays them against each other.

Development

make test         # fast tests with the race detector
make test-full    # also the slow bot-vs-bot strength comparison
make check        # vet, tests, and a TypeScript type check

Environment variables for the server: ADDR (default localhost:8000), STATIC_DIR (default web/dist), PPROF_ADDR (off unless set).

Layout:

cmd/tank-ops/        the executable: reads env vars, wires the HTTP server
internal/game/       the rules, with no networking
    vector.go          hex coordinates and distance
    results.go         orders (TankAction) and the events a turn produces
    state.go           GameState: resolving turns, visibility, shrinking
    config.go          what clients are told at the start of a game
    maps.go            the arenas and how to add one
    sim.go             a small API for simulating and inspecting positions
internal/bot/        the computer opponent
    bot.go             Bot: Start / Observe / Plan, difficulty levels
    view.go            what the bot knows (a player's-eye view of the results)
    geometry.go        lines of fire, reachability
    easy.go medium.go hard.go   one file per policy
internal/server/     websockets and rooms
    hub.go             accepts connections, finds or creates rooms
    player.go          one connection's state machine
    room.go            one game's state machine, turn timer, reconnect
    botplayer.go       lets a bot sit in a room like a human
    messages.go        the wire format and input validation
    ratelimit.go metrics.go
web/src/             the client; web/dist is served as-is after tsc
tools/gen_assets/    generators for the sprites and sounds
docs/protocol.md     the websocket protocol (build your own client or bot)

Regenerating art and sound

All sprites and sound effects are generated by scripts in this repo, so they are original and covered by the project license.

pip install pillow numpy
python3 tools/gen_assets/gen_sprites.py   # web/dist/assets/sprites.png + web/src/sprites.ts
python3 tools/gen_assets/gen_sounds.py    # web/dist/assets/sounds.wav

Contributing

See CONTRIBUTING.md. Ideas for first contributions: new maps in internal/game/maps.go, keyboard controls, better bot behaviour, accessibility. The full roadmap is in docs/IMPROVEMENT_PLAN.md.

License

MIT. This covers the code and the generated art and sound.

Deploying

docker build -t tank-ops .
docker run -p 8000:8000 tank-ops

Put a TLS-terminating reverse proxy in front for public use, and set TRUST_PROXY=1 so rate limits see real client addresses. Other settings: CONNECT_RATE (new connections per second per IP, default 2), CONNECT_BURST (10), MAX_CONNS_PER_IP (20). /healthz is a liveness check and /metrics exposes Prometheus counters (rooms, games, resumes, refusals). Don't expose /metrics publicly if you don't want the numbers public; block it in the proxy.

About

A multiplayer, turn-based tank game for the browser. It is played on a hex grid with fog of war and a shrinking arena.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages