jankwins

Connect4 proof of concept in jank

View on GitHub

jankwins

Connect4 in jank, the native Clojure dialect: you play red against the computer in a window drawn with cairo and shown by SDL3.

jankwins

It is a port of connect4, which is written in Clojure. The rules and the minimax search with alpha-beta pruning are that project’s code, with one function added to report the winning four; the window is new.

Requirements

macOS with Homebrew, and:

brew install jank-lang/jank/jank sdl3 cairo

Written against jank 0.1-alpha. The Makefile expects Homebrew under /opt/homebrew.

Running

make run      # run from source (slow to start, handy while changing things)
make build    # compile target/jankwins, a native executable
make app      # wrap it as target/jankwins.app, to double-click on this Mac
make test     # tests for the rules and the game state
make smoke    # open the real window, feed it a click, check the computer replies
make shot     # render sample positions to target/shot-*.png without a window

Playing

You are red and move first. Click a column to drop a piece; the faint disc shows where it will land. The computer plays cyan, searching three moves deep. When the game ends, the winning four are ringed; click anywhere to play again. Escape or closing the window quits.

Layout

src/jankwins/game.jank   board, rules and search (from connect4)
src/jankwins/ui.jank     the game state and how clicks and time change it
src/jankwins/draw.jank   paints a state with cairo
src/jankwins/main.jank   the SDL window and event loop
test/                    clojure.test tests for game and ui
dev/                     the smoke and snapshot tools
packaging/Info.plist     what `make app` puts in the bundle

game and ui are plain jank with no C calls. draw and main call cairo and SDL3 directly through jank’s C++ interop, with no wrapper library.