Hacker News 中文摘要

RSS订阅

这款游戏仅13KiB,兼容Windows、Linux及浏览器 -- This game is a single 13 KiB file that runs on Windows, Linux and in the Browser

文章摘要

一款仅13KB大小的游戏文件,可同时在Windows、Linux和浏览器中运行,展示了跨平台编程的巧妙实现。

文章总结

标题:一款仅13KB的单文件游戏,兼容Windows、Linux及浏览器平台

作者:Kamila Szewczyk 发布日期:2026年1月11日

核心内容:

  1. 项目背景
  • 受Justine Tunney的cosmopolitan libc项目启发
  • 挑战目标:开发一个<16KB的单文件游戏,兼容Windows/Linux/浏览器三平台
  1. 游戏特性
  • 经典贪吃蛇玩法,全平台统一规则
  • 控制方式:方向键/WASD,支持ESC退出/R重置/P暂停
  • 计分系统:普通食物+10分,15%概率出现的黄色水果+20分
  • 进阶机制:每吃10个食物进入新关卡,随机生成保证可达的迷宫布局
  1. 技术实现
  • 三重实现:
    • Windows版:i686架构,WinAPI,3-5KB
    • Linux版:x86_64架构,X11,3-5KB
    • 浏览器版:HTML5 Canvas,3-5KB
  • 巧妙的多格式拼接:
    • Windows PE头部嵌入可跳过执行的shell脚本
    • Linux部分使用LZMA压缩的ELF64二进制
    • HTML内容通过CSS隐藏文件头部的二进制数据
  • 最终文件大小:13,312字节(约13KB)
  1. 技术细节亮点
  • 通过精心设计的文件结构,使不同平台自动识别对应代码段
  • Windows版本依赖兼容性模式解决特殊PE头问题
  • Linux版本采用自解压shell脚本
  • 浏览器版本利用HTML容错性处理头部二进制数据

(注:原文中的代码片段、具体偏移量等过细技术细节已简化,保留了关键实现思路)

评论总结

以下是评论内容的总结:

  1. 跨平台运行问题

    • 作者zamadatix分享了在不同平台(浏览器、Linux、Windows)运行程序的经验和解决方案。
      引用
    • "Browser: works after renaming to .html"
    • "Windows: ... turning [DEP] back off allowed it to launch."
  2. 技术实现的创新性

    • trollbridge认为Polyglot技术早该实现,而nvllsvm提到类似的小体积高表现程序(如kkrieger游戏)。
      引用
    • "One of the interesting things about Polyglot is that nobody did it any sooner."
    • "kkrieger game for Windows which was a 96k FPS game..."
  3. 对简洁高效程序的赞赏

    • TuringNYC和hyperbrainer分别提到经典游戏(如《塞尔达传说》)和Cosmopolitan项目,强调小体积程序的魅力。
      引用
    • "how little text/code/information could produce how much wonder..."
    • "Reminds me of the Cosmopolitan project..."
  4. 改进建议

    • gaigalas建议通过HTML和JS实现更灵活的安装方式,socketcluster推崇单文件应用的便捷性。
      引用
    • "You could distribute it as .html only, and use JS to offer a local download link..."
    • "I love the idea of applications which exist in one file..."
  5. 质疑与批评

    • journal认为用语言模型可以更简单实现,netsharc则对EXE文件在DOS下的兼容性提出疑问。
      引用
    • "Can’t you do that with a language model in less than one paragraph?"
    • "Windows EXE files are runnable in DOS... but most of the time just prints 'This program requires Microsoft Windows.'"
  6. 技术细节探讨

    • wasmperson分析了Linux可执行文件的特殊结构,指出其节省空间的技巧。
      引用
    • "I extracted the linux executable and was surprised to find that both readelf and objdump choke on it..."
    • "the name of the dynamic linker was shoved into the 'unused' fields..."

总结:评论主要围绕跨平台程序的实现、技术创新的历史意义、小体积程序的价值、改进建议及技术细节展开,观点多样且深入。