去佐克
用Go编写的Z-Machine解释器,运行经典的Infocom文本冒险游戏。带有三个前端:命令行播放器、基于浏览器的web UI和允许AI代理自主玩游戏的MCP服务器。
斯科特·贝克,https://github.com/scottmbaker/
基于 MojoZork 的 Ryan C.Gordon。
仅支持Z-Machine版本3的故事文件。佐克1(zork1.dat)包括在内。AI工具(Claude Code、Google Antigravity、Microsoft Copilot)已被用于执行该项目中的一些任务。
______________________________________________________________________
建筑
make # builds _build/zork, _build/web, _build/mcp
make play # play Zork 1 interactively in the terminal
make test # runs the full Zork 1 walkthrough and verifies a score of 350/350
make walkthrough # runs the full Zork 1 walkthrough and prints the output
make clean # removes all built files需要Go 1.21+。
码头工人
make docker-build # builds image tagged smbaker/go-zork
docker run -it smbaker/go-zork # play interactively
docker run -p 8080:8080 smbaker/go-zork ./web # web UI
docker run -p 8081:8081 smbaker/go-zork ./mcp --mode sse # MCP SSE server要推送到Docker Hub:
make docker-push # tags as docker.io/smbaker/go-zork:1.0.0 and pushes______________________________________________________________________
程序
_build/zork --CLI播放器
直接在终端中播放。
Usage: zork [options] [story_file]
Options:
-seed int RNG seed (0 = current time)
-save string save file path (default "save.dat")./_build/zork zork1.dat
./_build/zork -seed 42 zork1.dat______________________________________________________________________
_build/web --浏览器用户界面
通过HTTP提供两个基于web的UI。每个浏览器选项卡都有自己的独立游戏会话。
Usage: web [options]
Options:
-story string story file path (default "zork1.dat")
-save string save file path (default "save.dat")
-port string listen address (default ":8080")./_build/web --story zork1.dat --port :8080| 路线 | 描述 |
|---|---|
/terminal | 全屏xterm.js终端(黑底绿,经典外观) |
/chat | 轻量级聊天风格UI,无外部依赖 |
/ws | WebSocket端点(每个连接一个ZMachine goroutine) |
/ | 重定向到 /terminal |
______________________________________________________________________
_build/mcp --MCP服务器
将Zork动词暴露为 模型上下文协议 AI代理(Claude等)可以玩游戏。支持stdio和SSE传输。
Usage: mcp [options]
Options:
-story string story file path (default "zork1.dat")
-save string save file path (default "save.dat")
-mode string transport: stdio or sse (default "stdio")
-port string listen address for SSE mode (default ":8081")
-log print all game input/output to stdoutstdio模式(克劳德桌面,本地代理)
./_build/mcp --story zork1.dat --mode stdio增添 claude_desktop_config.json:
{
"mcpServers": {
"zork": {
"command": "/path/to/_build/mcp",
"args": ["--story", "/path/to/zork1.dat", "--log"]
}
}
}SSE模式(远程代理、HTTP客户端)
./_build/mcp --story zork1.dat --mode sse --port :8081MCP工具
| 工具 | 参数 | 说明 |
|---|---|---|
get_intro | -- | 返回开场场景(先呼叫) |
restart | -- | 将游戏重置为开始 |
look | -- | 描述当前位置 |
inventory | -- | 列出携带物品 |
score | -- | 显示分数和移动计数 |
wait | -- | 等一下 |
pray | -- | 祈祷 |
verbose / brief / superbrief | -- | 设置描述的详细程度 |
north south east west | -- | 向主要方向移动 |
northeast northwest southeast southwest | -- | 沿对角线移动 |
up / down | -- | 垂直移动 |
examine take drop open close | object | 与单个对象交互 |
read eat drink turn_on turn_off | object | 更多单对象操作 |
push pull climb move | object | 物理操作 |
light extinguish wave ring rub | object | 特殊互动 |
cross echo enter exit smell listen | object | 环境相互作用 |
wind | object | 给发条装置上发条 |
put | item, container | 将物品放入/放在容器中 |
attack | target, weapon (可选) | 攻击生物 |
throw | item, target | 向目标投掷物品 |
give | item, recipient | 将物品赋予角色 |
unlock / lock | object, key | 用钥匙锁定或解锁 |
turn | object, tool | 用工具转动物体(例如带扳手的螺栓) |
tie | item, target | 将物品绑在某物上 |
insert | item, container | 将物品插入容器 |
say | text, to (可选) | 说点什么 |
command | text | 发送任何原始命令(包罗万象) |
这 --log 标志对于观看AI游戏很有用:所有命令和响应都会实时打印到stdout。
______________________________________________________________________
Helm 图表
Helm图表提供于 helm/go-zork/ 用于将web或MCP服务器部署到Kubernetes。
安装
# Web UI (default)
helm install zork helm/go-zork
# MCP SSE server
helm install zork helm/go-zork \
--set mode=mcp
# Expose via NodePort
helm install zork helm/go-zork \
--set service.type=NodePort \
--set service.nodePort=31080
# Expose via Ingress
helm install zork helm/go-zork \
--set ingress.enabled=true \
--set ingress.host=zork.example.com核心价值观
| 值 | 默认值 | 描述 |
|---|---|---|
image.repository | smbaker/go-zork | 容器映像存储库 |
image.tag | 1.0.0 | 图像标签 |
mode | web | 要运行的服务器: web 或 mcp |
web.port | 8080 | Web服务器容器端口 |
mcp.port | 8081 | MCP服务器容器端口 |
mcp.log | false | 将游戏成绩单打印到stdout |
service.type | ClusterIP | Kubernetes服务类型 |
service.port | 80 | 服务端口 |
service.nodePort | "" | 类型为时的节点端口号(30000–32767) NodePort |
ingress.enabled | false | 创建Ingress资源 |
ingress.host | "" | 入口主机名 |
replicaCount | 1 | pod副本数量 |
______________________________________________________________________
建筑
pkg/zork/ Z-Machine interpreter (version 3)
cmd/zork/ CLI front-end
cmd/web/ HTTP + WebSocket server; terminal.html and chat.html embedded via go:embed
cmd/mcp/ MCP server (stdio + SSE via mark3labs/mcp-go)Z-Machine完全通过Go通道进行通信:
z.InputChan <-chan string // lines of user input sent to the interpreter
z.OutputChan chan<- []byte // output chunks produced by the interpreter
done <-chan error // closed when the game ends所有三个前端都遵循相同的模式:将它们的传输(stdin/stdout、WebSocket或MCP工具调用)桥接到这两个通道。MCP服务器通过互斥体串行化并发工具调用,因此每个命令/响应对都是原子性的。
______________________________________________________________________
测试
make test运行完整的Zork 1演练(walkthrough.txt)使用固定的RNG种子,并断言最终得分为350/350(最大值)。
