ダンジョンズ&デスクトップ:GitHub Copilot CLI で手動生成型ローグライクを構築する
GitHub Blog は、GitHub Copilot CLI を活用して開発者が Go で実装した「GitHub Dungeons」という新ツールを紹介し、リポジトリのコードを BSP アルゴリズムで動的に変換するローグライクゲームの実例を示した。
キーポイント
Copilot CLI を活用したプロトタイピング
開発者は Go の知識が限定的だったにもかかわらず、GitHub Copilot CLI の「/yolo」コマンド(全権限許可)を活用し、コードの記述よりも振る舞いの記述に集中することで数時間でツールを完成させた。
リポジトリをダンジョンに変換する仕組み
GitHub Dungeons は、リポジトリの最新コミット SHA をシードとして Binary Space Partitioning (BSP) アルゴリズムを実行し、コードベースの構造に基づいてユニークなダンジョンマップを生成する。
ローグライクと CLI の親和性
パーマデス(一度死んだらリセット)や手動設計ではなくアルゴリズムによる生成といったローグライクの要素が、コマンドラインインターフェースの特性と相性が良く、開発体験をゲーム化するのに適している。
動的なコードベース可視化
同じコミットからは常に同じマップが生成される一方、コードの変更(コミット)が行われるたびにダンジョンのレイアウトが変化し、リポジトリの状態を直感的に把握する新たな手段となる。
GitHub Copilot CLI の /delegate コマンドによる非同期開発
/delegate コマンドを使用すると、自然言語で機能の記述を行い、Copilot エージェントにクラウド上で処理を任せることで、プルリクエストとして結果を受け取れる。これにより、ボイラープレートやエッジケースへの時間を減らし、ゲームデザインやプレイヤー体験の構築に集中できる。
BSP(Binary Space Partitioning)によるダンジョン生成
ロウライクに必要な「構造化」「再遊性」「ナビゲーション可能性」を両立させるため、空間を再帰的に分割して部屋を作成し連結する BSP 技法が採用された。これにより、整然とした矩形の部屋と有機的なランダム性を保証できる。
BSPアルゴリズムによるダンジョン生成
空間を再帰的に分割して「葉」領域を作成し、ランダム性を加味した部屋とL字型の通路で接続することで、意図的な設計感を持つ構造化された混沌を実現します。
影響分析・編集コメントを表示
影響分析
この記事は、AI コパイロットツールが単なるコード補完を超え、開発者の思考プロセスを変容させ、複雑なアルゴリズムの実装を容易にする「プロトタイピングの民主化」を象徴する事例です。特に、開発環境そのものをゲーム化するアイデアは、コードベースの理解やデバッグに対する開発者の意識を変える可能性があり、DevOps やコード可視化の分野における新たなトレンドを示唆しています。
編集コメント
AI ツールが「コードを書く」だけでなく、開発者の発想を刺激し、既存の概念(ローグライク)と技術(BSP)を組み合わせた全く新しいツールを生み出すための触媒として機能している点が興味深いです。
GitHub Copilot CLI チャレンジに熱中してしまい、少し疑問符がつくような決断を下しました:自分のコードベースをローグライクダンジョンに変えてしまったのです。
きっかけはシンプルなプロンプトでした。「現在のリポジトリを受け取り、BSP [省略] を用いて生成されたダンジョンを持つプレイ可能なローグライクダンジョンにする Go 言語製の GitHub CLI エクステンションを作成せよ」。そして /yolo と入力しました。
その結果が「GitHub Dungeons」です。これはコードベースからダンジョンを生成するターミナルゲームです。部屋、通路、敵はすべてあなたのリポジトリから構築され、ターミナル内で直接描画されます。矢印キーで移動し、バグと戦い、出口を探します。すべてのリポジトリが異なるマップを生み出し、すべてのコミットがレイアウトを再形成します。そして HP がゼロになると、最初からやり直しです。

豆知識: /yolo(「You Only Live Once」の略)は Copilot CLI のコマンドです(/allow-all のエイリアス)。ローグライクがパーマデス(一度死んだらゲームオーバー)を中心に構築されていることを考えると、まさにふさわしい名前ですね。本当に人生は一度きりなのです。
ローグライクは 1980 年代の『Rogue』などのゲームにそのルーツがあります。ターミナルベースのアドベンチャーで、各プレイごとに新しいダンジョンが生成され、死んだら最初からやり直すというものです。
この「手動生成(プロシージャラルジェネレーション)」、「パーマデス」、そしてテキストベースインターフェース(後に「ベルリン解釈」といった概念で形式化されました)の組み合わせにより、このジャンルは驚くほど現代的に感じられ、コマンドラインとの相性が抜群です。
GitHub Dungeons はその伝統に倣っています。これは Go で書かれていますが、私は普段は Go を使いません。しかし Copilot との連携により、構文よりも振る舞いに集中できました。
手続き型生成とは何か?
手続き型生成(あるいは「procgen」というクールな子供たちが呼ぶ名前)は、手作業でデザインするのではなく、アルゴリズムによってコンテンツを作成する方法です。ゲームにおいては、通常、一定のルールと少しのランダム性を用いて、実行時にレベル、マップ、敵、アイテムなどが生成されることを意味します。
つまり、一つのダンジョンをデザインするのではなく、多くのものを生成するシステムをデザインするのです。
それがローグライクに繰り返しプレイできる理由を与えます:
すべてのプレイが異なる
レイアウトは毎回変化する
何かが
何かが
GitHub Dungeons では、このシステムはあなたのリポジトリと結びついています。レイアウトは最新のコミットによってシードされるため、同じコードは同じダンジョンを生成し、変更を加えるたびにそれが形を変えます。
では、実際のリポジトリがどのようにしてダンジョンになるのでしょうか?
高レベルでは、GitHub Dungeon のレイアウトは、Binary Space Partitioning(BSP)を使用して生成されます。これはリポジトリの最新のコミット SHA によってシードされます(BSP については後ほど詳しく説明します)。つまり、同じコードベースは一貫したレイアウトを生成しますが、コードが変化するにつれて進化し続けます。
実際には:
同じコミットは常に同じマップを生成する
異なるリポジトリからは構造的に明確に異なるレイアウトが生まれる
コードが変化するにつれ、ダンジョンもそれとともに進化する
これは手続き型生成ですが、あなたのコードベースと直接結びついています。それがこのアイデアです。
実際に興味深かったのは、それを構築することでした。
Copilot CLI で構築する
GitHub Copilot CLI を使用することは、最初からすべてを書くのではなく、動作を記述することを意味しました。大きな違いをもたらしたコマンドの一つが /delegate です。インラインでコードを生成するだけでなく、/delegate はクラウド上で実行されている GitHub の Copoid コーディングエージェントにタスクを引き渡します。
私は望むものを平易な英語で説明し、開始すると、それが独立して作業している間に他のことをしていても大丈夫でした。完了すると、結果を含むプルリクエストが開かれます。
例えば、/delegate Make each level progressively harder e.g. on level 2 there are extra baddies, but more health potions と入力しました。
Copilot は非同期で堅牢な最初のバージョンを生成し、そこから私はそのプルリクエストを確認・調整してバランスが適切になるまで続けました。プレイヤーが無敵になるチートコードを追加するなど、他の機能にも同じアプローチを取りました(なぜしないのか)。
さらに、ダンジョンの生成方法を説明するためにドキュメントと ASCII アートの図を追加する小さなヘルパーである「ダンジョン書記」エージェントを Copilot に生成させました。これはターミナル型ローグライクにとって非常にブランドに合っていると感じられました。
Copilot を使用すること(特に /delegate とともに)は、私が望むことを何でも実行してくれる NPC の軍隊を持っているようなものです。
リー・ライリー、ダンジョンマスター
このように作業を進める(機能の説明を行い、Copilot に任せて、生成されたプルリクエストをレビューする)ことで、エッジケースやボイラープレートに費やす時間を減らし、プレイヤー体験に集中できるようになりました。これには、プレイヤーが発見できるイースターエッグの追加も含まれます。Copilot と反復作業を行うことで、実装の詳細に頻繁に切り替えるのではなく、ゲームデザインの思考モードを維持できました。ビルドとスケルトン構築の大部分を Copilot が担当してくれたおかげで、メカニズムの設計やアイデアのテスト、そして実際に何がゲームをおもしろくするかを考えるというフローから離れることなく作業を進めることができました。
手動生成されたダンジョン(BSP 使用)
各ダンジョンデザインの核心には、バイナリー空間分割(Binary Space Partitioning: BSP)と呼ばれる技法があります。これは、友人や同僚を感心させたい場合に、ミドルアウト圧縮と共に casually に言及できる素晴らしいテクニックです。一見すると難しそうに聞こえますが、その考え方は驚くほどシンプルです:空間をより小さなチャンクに分割し続け、接続可能な部屋をいくつか得るまで繰り返します。
なぜ BSP がローグライクに適しているのか
ローグライクでは、以下のような感覚を持つマップが必要です:
構造化されている(完全にランダムな無意味なものではない)
再プレイ性がある(毎回異なる内容になる)
ナビゲート可能である(行き止まりや不可能なレイアウトがない)
BSP はこの点で絶妙なバランスを提供します。以下のような特徴があります:
清潔で長方形の部屋
接続性の保証
有機的な感覚を与えるのに十分なランダム性
仕組みは以下の通りです…
- 大きな空の空間から始める
すべては一つの大きな長方形として始まります:それがあなたのダンジョン全体です。

- 再帰的に分割する
空間を 2 つの領域に分割します。

その後、さらに分割を繰り返します。

さらに繰り返します。
各分割は水平方向または垂直方向のいずれかで行われます。
- 領域が小さくなりすぎたら停止する
部屋を配置できなくなるほど領域が小さくなるまで、分割を続けます。
これにより、「リーフ(葉)」と呼ばれる最終的な建築ブロックとなる多数の領域が生成されます。

- 各領域を部屋に変換する
各リーフは部屋になりますが、完全に整列させるわけではありません。サイズと位置にわずかなランダム性を加えます。

このわずかなランダム性が、すべてがグリッド状になりすぎるのを防ぐ要因となります。
- 廊下で部屋をつなぐ
次に、ツリーを逆方向にたどりながら兄弟ノード同士をリンクすることで、部屋同士をつなぎます。


各接続は L 字型になります。
- 最終結果:構造化されたカオス
これらをすべて組み合わせると、以下のようなものが完成します:

部屋は意図的に配置されている
廊下によってすべての場所が到達可能になる
毎回異なるランダム性(ただし、シード値を使えば再現可能)
なぜこれがこれほどうまく機能するのか
BSP(Binary Space Partitioning:二分空間分割)について私が気に入っている点は、設計されたように感じられるのに、実際にはそうではないという点です。
これは手動生成の2つの大きな問題を回避します。すなわち、純粋なランダム性による混乱と、硬直したグリッドによる予測可能性(および退屈さ)です。その代わりに、その中間にある何か、そして時には美しいものが得られます。
インストール方法と遊び方
自分のコードベースがダンジョンとしてどのように見えるかを確認したい場合、すでに GitHub Copilot CLI がインストールされていれば、以下を実行できます:
gh extension install leereilly/gh-dungeons
その後、gh dungeons を実行して、征服の準備ができているカスタムダンジョンに変換します。ヒーローの操作には、WASD キー、矢印キー、または Vim キーを使用してください。
あなたの目標は、隠された扉を見つけて、5 つのレベルにわたって敵から脱出(そして攻撃!)することです。視界を制限する「霧のかかった戦争(fog of war)」や、自動攻撃機能、キル数や征服したレベル数の統計を追跡できる機能など、おもしろい機能を追加しました。これら以外にも、自分で発見しなければならない機能が多数あります。
危険区域!
無謀な気分なら、「クレイジーモード」でプレイしてみてください。ゲーム全体をクリアするまでセーブされた変更を削除する pre-commit フックを設定できます。
⚠️ 警告:リポジトリにこれがどのような影響を与えるかを完全に理解していない限り、この操作は行わないでください。保存された作業が失われ、おそらく精神的な安定も損なわれることになります。
プリコミットフックの作成
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
gh dungeons
if [ $? -ne 0 ]; then
echo "You died! Your changes have been stashed into oblivion..."
git stash && git stash drop stash@{0}
exit 1
fi
EOF
実行可能権限を付与
chmod +x .git/hooks/pre-commit
明確に言っておきますが、ダンジョン攻略に失敗した場合、この機能を有効化するとすべての未コミットの変更は失われます。冒険者よ。
(編集者の注:どうか、どうか、どうかこれは行わないでください。失われた作業について当方は一切責任を負いません。ただし、リー氏にはその責任があります。)
これを持って旅立とう
これは捨て台詞のような実験から始まりましたが、GitHub Copilot CLI に対する私の考え方を一変させました。
私は素早く MVP(Minimum Viable Product:実用最小限の製品)を構築し、重要な部分について反復改善を行うことができました。そして、BSP 生成や、少し呪われたような Yendor の YAML ファイルに定義されたモンスターや移動ロジックといった重労働は Copilot に任せることができました。
記事「Dungeons & Desktops: Building a procedurally generated roguelike with GitHub Copilot CLI」は、もともと The GitHub Blog で公開されました。
原文を表示
I got nerd-sniped into the GitHub Copilot CLI Challenge and made a questionable decision: I turned my codebase into a roguelike dungeon.
It started with a simple prompt: Build a GitHub CLI extension in Go that takes the current repository and turns it into a playable roguelike dungeon, with dungeons generated with BSP [snip]. And then /yolo .
The result is GitHub Dungeons, a terminal game that generates a dungeon from your codebase. Rooms, corridors, and enemies, all built from your repo and rendered right in your terminal. You navigate with arrow keys, fight bugs, and hunt for the exit. Every repository produces a different map. Every commit reshapes the layout. And if your HP hits zero, you start over.

Fun fact: /yolo (“you only live once”) is a Copilot CLI command (an alias for /allow-all). Fitting, since roguelikes are built around permadeath. You really do only get one life.
Roguelikes trace back to games like Rogue in the 1980s – terminal-based adventures where each run generated a new dungeon, and death meant starting over.
That combination of procedural generation, permadeath, and text-based interfaces (later formalized in things like the “Berlin Interpretation”) makes the genre feel surprisingly modern, and a perfect fit for the command line.
GitHub Dungeons leans into that tradition. It’s written in Go, which I don’t normally use, but working with Copilot meant I could focus on behavior instead of syntax.
What is procedural generation?
Procedural generation (or “procgen” as the cool kids call it) is a way of creating content algorithmically instead of designing it by hand. In games, that usually means levels, maps, enemies, or items are generated at runtime using a set of rules plus a bit of randomness.
So instead of designing one dungeon, you design a system that generates many.
That’s what gives roguelikes their replayability:
Every run is different
Layouts change every time
Something
Something
In GitHub Dungeons, that system is tied to your repo. The layout is seeded by your latest commit, so the same code produces the same dungeon, and every change reshapes it.
So how does a repository actually become a dungeon?
At a high level, GitHub Dungeon layouts are generated using Binary Space Partitioning (BSP), seeded by your repository’s latest commit SHA (more on BSP in a bit). That means the same codebase produces a consistent layout, while still evolving as the code changes.
In practice:
The same commit always generates the same map
Different repositories produce layouts that feel structurally distinct
As the code changes, the dungeon evolves with it
It’s procedural generation—but tied directly to your codebase. That’s the idea.
The interesting part was actually building it.
Building it with Copilot CLI
Working with GitHub Copilot CLI meant describing behavior instead of writing everything from scratch. One command that made a big difference was /delegate. Instead of just generating code inline, /delegate hands the task off to GitHub’s Copilot coding agent running in the cloud.
I could describe what I wanted in plain English, kick it off, and then go do something else while it worked independently. When it finished, it opened a pull request with the results.
For example,/delegate Make each level progressively harder e.g. on level 2 there are extra baddies, but more health potions
Copilot generated a solid first pass asynchronously, and I reviewed and tweaked the PR from there until the balance felt right. I took the same approach to other features like adding cheat codes that make the player invincible (because why not).
I even had Copilot generate a “dungeon scribe” agent, a small helper that added documentation and ASCII art diagrams to explain how dungeons were generated, which felt very on-brand for a terminal roguelike.
I even had Copilot generate a dungeon scribe agent to create documentation and explain how dungeons were generated with ASCII art diagrams, which felt very on-brand for a terminal roguelike.
Using Copilot (especially with /delegate) is like having an army of NPCs available to do whatever I want them to do.
Lee Reilly, Dungeon Master
Working this way (describing features, delegating them to Copilot, and reviewing the resulting pull requests) meant I could spend less time on edge cases and boilerplate, and more time on the player experience, including adding easter eggs for players to discover. Iterating with Copilot let me stay in a game design mindset instead of constantly switching into implementation details. Because Copilot was handling most of the build and scaffolding, I could stay in the flow of designing mechanics, testing ideas, and figuring out what actually made the game fun.
Procedurally generated levels (with BSP)
At the heart of each dungeon design is a technique called Binary Space Partitioning (BSP), which is a great thing to casually mention alongside middle-out compression if you want to impress your friends and colleagues. It sounds intimidating, but the idea is surprisingly simple: keep splitting a space into smaller chunks until you have a bunch of rooms you can connect.
Why BSP works so well for roguelikes
Roguelikes need maps that feel:
Structured (not completely random nonsense)
Replayable (different every run)
Navigable (no dead ends or impossible layouts)
BSP hits a sweet spot. It gives you:
Clean, rectangular rooms
Guaranteed connectivity
Just enough randomness to feel organic
Here’s how it works…
- Start with a big empty space
Everything begins as one big rectangle: your entire dungeon.

- Split it (recursively)
We split the space into two regions.

Then split those again.

And again.
Each split can be horizontal or vertical.
- Stop when it gets too small
We keep splitting until regions are too small to fit a room.
That creates a bunch of “leaf” regions, the final building blocks.

- Turn each region into a room
Each leaf becomes a room, but not perfectly aligned. We randomize size and position slightly.

That slight randomness is what stops everything feeling too grid-like.
- Connect rooms with corridors
Now we connect rooms by walking back up the tree and linking siblings.


Each connection is an L-shape:
- End result: structured chaos
Put it all together and you get something like this:

Rooms feel intentional
Corridors make everything reachable
Every run is different (but reproducible with a seed)
Why this lands so well
What I like about BSP is that it feels designed, even though it isn’t.
It avoids the two big problems of procedural generation: pure randomness (messy), and rigid grids (predictable, boring). Instead, you get something in between… and sometimes beautiful.
How to install and play it
If you want to see what your own codebase looks like as a dungeon, and you already have GitHub Copilot CLI installed, you can run:
gh extension install leereilly/gh-dungeons
After that, run gh dungeons to transform your repository into a custom dungeon, ready to be conquered. Control your hero with WASD, arrow keys, or Vim keys.
Your goal is to find the hidden door and escape from (and attack!) enemies over five levels. I’ve added fun features like fog of war that limit visibility, auto-attack, ability to track stats like kills and conquered levels, and more that you’ll have to discover yourself.
Danger zone!
If you’re feeling reckless, play it on crazy mode: you can set up a pre-commit hook that deletes your saved changes unless you beat the entire game.
⚠️ WARNING: Do not do this unless you fully understand what this will do to your repository, you’ll lose saved work and probably some sanity as well.
Create the pre-commit hook
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
gh dungeons
if [ $? -ne 0 ]; then
echo "You died! Your changes have been stashed into oblivion..."
git stash && git stash drop stash@{0}
exit 1
fi
EOF
Make it executable
chmod +x .git/hooks/pre-commit
To be clear, you’ll lose all your uncommited changes if you enable this
and fail to beat the dungeon, adventurer.
(Editor’s note: Please, please, please do not do this. We are not responsible for any lost work. But Lee definitely is.)
Take this with you
This started as a throwaway experiment, but it changed how I think about GitHub Copilot CLI.
I was able to MVP it quickly, iterate on the parts that mattered, and let Copilot handle the heavy lifting, things like BSP generation and even monsters and movement defined in a slightly cursed YAML file of Yendor.
The post Dungeons & Desktops: Building a procedurally generated roguelike with GitHub Copilot CLI appeared first on The GitHub Blog.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み