
How to Build a Chess Roguelike in Phaser.js
Introduction: Chess Is the Perfect First Turn-Based Engine
To build a chess roguelike in Phaser.js, make an 8×8 grid from plain JavaScript arrays, render its tiles, and alternate player and enemy turns. Add pieces and capture rules, then connect battles with a run loop, relic rewards, and a shop stub. Phaser handles the display; your board rules can stay in ordinary JavaScript.
E-E-A-T / About This Build
This walkthrough was drafted with an AI writing pipeline and checked against official Phaser release notes and The Ouroboros King’s public Steam page. The build pins Phaser 3.90.0; when this build was made, its CDN URL returned HTTP 200. The playable build was loaded in a headless Chromium check (page load, one king move, one enemy response). That is a scripted check, not hands-on playtesting.
Why Chess Roguelikes Work (And Why Phaser Fits)
Chess-like rules give a game clear, readable choices: select a piece, choose a destination, and see what changes. Roguelike systems can then make each run feel different. A relic might alter a capture rule, while a shop offers a choice about how to spend a reward. These additions create variety without requiring a complicated real-time control scheme.
A useful genre reference is The Ouroboros King on Steam. It combines chess strategy with roguelike build variety and replayability, including armies, relics, and gadgets. Its Steam release date was February 27, 2023.
Phaser suits this kind of project because it can draw the board and respond to clicks, while JavaScript handles the rules. A turn-based board does not need Arcade Physics: pieces occupy cells, and moves update their coordinates. You can add physics later if your game introduces moving objects or real-time action.
Project Setup: Phaser 3.90.0 via CDN
Create an HTML file and load the pinned Phaser build:
<script src="https://cdn.jsdelivr.net/npm/phaser@3.90.0/dist/phaser.min.js"></script>
Phaser 4 has been released (the GitHub releases list v4.0.0 through v4.2.1), but this tutorial uses the 3.x line so its API matches the code below. Phaser’s release history is available on GitHub.
Create a scene class and pass it to a game configuration. The FIT scale mode keeps the game within its available space; CENTER_BOTH centers it.
class ChessRunScene extends Phaser.Scene {
constructor() {
super("ChessRunScene");
}
create() {
// Set up the board, pieces, and pointer input here.
}
}
const config = {
type: Phaser.AUTO,
width: 720,
height: 560,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH
},
scene: [ChessRunScene]
};
new Phaser.Game(config);
Step 1: The Grid Board
Keep the game state separate from its appearance. Use this.board as an 8×8 array, with each cell holding either null or a piece object. The first index is the row (y); the second is the column (x). This makes checking a destination straightforward: this.board[y][x].
For a square board with 64-pixel cells, convert a board position to its pixel center with x * 64 + 32 and y * 64 + 32. Reverse the mapping on a click by dividing the pointer position by the cell size and rounding down.
Draw alternating tile colors with Phaser graphics or rectangles. Use a highlight for the selected piece and another for its possible destinations. Keeping drawing separate from board data makes it easier to refresh the display after a move.
Step 2: The Turn Loop
Store the active side in this.turn, using "player" or "enemy". When the player finishes a move, call endTurn(). That method hands control to the enemy, runs its move logic, and returns control to the player.
Before processing a click, check that it is the player’s turn. In the reference build the enemy response runs synchronously, so this guard is a safety habit that becomes essential once you animate enemy moves. In the reference build, each enemy captures a player piece when it can and otherwise steps toward the nearest one. Replace that greedy rule with a smarter evaluation when you want harder fights.
Step 3: Pieces and Movement
Keep pieces in this.pieces, an array of objects shaped like { type, side, x, y, hp }. For example, a piece might have type: "rook" and side: "player". The board cells can refer to the same objects, so a move updates one piece’s position and the board’s occupancy.
Start with a small set of movement rules. A rook slides along a row or column, a bishop along diagonals, a knight jumps in an L-shape, a king moves one cell in any direction, and a pawn advances one cell and captures diagonally. For each selected piece, generate candidate destinations, then reject any that leave the board or pass through an occupied square when the piece cannot jump.
On the interface, use click-to-select and click-to-move. If the clicked cell contains a friendly piece, select it. If it is a valid destination, move the selected piece there. Keeping movement rules in helper functions makes it easier to add piece types without growing the input handler into a tangle.
Step 4: Captures
A capture happens when a piece moves onto a cell occupied by an opponent. Remove the target from this.pieces, clear its cell in this.board, and then place the moving piece at the destination. If pieces have hit points, reduce them first and remove them only when their health reaches zero.
Keep capture behavior in captureAt(x, y). That gives relic effects a clear place to hook into later: for example, a passive effect could grant gold after a successful player capture. Start with the basic rule, then add modifiers one at a time.
Step 5: Relics and the Shop (Stub)
A shop does not need a full economy system to make the run structure visible. Add a simple between-battle screen with a few offers, a gold total, and a purchase action. Keep owned relics in a list, and check those relics at the moment they matter—for instance, in capture logic or when a battle starts.
The reference build keeps this small: three relic choices after each cleared level, and one purchase. Press S to buy an extra pawn for 5 gold. Each relic changes a number in the run state, such as the gold earned per capture.
Step 6: The Run Loop
A run connects encounters rather than treating every board as a separate game. Track the current level, gold, and owned relics in this.run. After a victory, show a reward or shop stub; after the player chooses to continue, nextLevel() prepares the next encounter.
Decide what ends a battle. A simple prototype might end when one side has no pieces left, or when a designated leader is captured. Handle defeat just as clearly: show a run-over state and offer a restart. These conditions give your run a beginning, a sequence of decisions, and an end.
Code Walkthrough: The Parts That Matter
These excerpts are simplified from the reference build below. The ... lines mark code left out for space.
Keep the board as an 8×8 array that mirrors the piece list. syncBoard() rebuilds it after every move:
syncBoard() {
this.board = Array.from({ length: 8 }, () => Array(8).fill(null));
for (const p of this.pieces) this.board[p.y][p.x] = p;
}
Movement rules live in one helper. Rooks slide until something blocks them:
legalMoves(p) {
const out = [];
const slide = (dx, dy) => {
for (let k = 1; k < 8; k++) {
if (!this.inside(p.x + dx * k, p.y + dy * k)) break;
const t = this.board[p.y + dy * k][p.x + dx * k];
if (t && t.side === p.side) break;
out.push({ x: p.x + dx * k, y: p.y + dy * k });
if (t) break; // an enemy stops the slide and can be captured
}
};
if (p.type === 'R') [[1, 0], [-1, 0], [0, 1], [0, -1]].forEach(([dx, dy]) => slide(dx, dy));
// ... bishops, knights, kings, and pawns follow the same pattern
return out;
}
A move calls captureAt() when the target square is occupied, then ends the turn:
movePiece(p, x, y) {
if (this.board[y][x]) this.captureAt(x, y);
p.x = x;
p.y = y;
this.syncBoard();
if (!this.pieces.some(q => q.side === 'e')) { this.levelClear(); return; }
this.endTurn();
}
captureAt(x, y) {
const t = this.board[y][x];
this.pieces = this.pieces.filter(q => q !== t);
this.run.gold += this.run.goldPerKill; // relics change this number
}
endTurn() gives each enemy one action, then returns control:
endTurn() {
this.turn = 'enemy';
for (const e of this.pieces.filter(q => q.side === 'e')) {
const moves = this.legalMoves(e);
// ... capture a player piece if one is reachable, otherwise step toward the nearest one
}
this.syncBoard();
this.turn = 'player';
}
Run progression sits in one object, and relics are plain functions that edit it:
this.run = { level: 1, gold: 0, relics: [], kingHp: 2, goldPerKill: 2, extraPawns: 0 };
const RELICS = [
{ name: 'Gold Vein', desc: '+3 gold per capture', apply: (run) => { run.goldPerKill += 3; } },
// ... two more relics
];
pickRelic(i) {
RELICS[i].apply(this.run);
this.run.level += 1;
this.nextLevel(); // spawns 2 + level enemies
}
Play the Game
The embedded build is the reference game for this tutorial. Click a cyan piece to select it, then click a highlighted square. The king, rooks, bishops, knights and pawns follow simplified chess rules. Each enemy takes one move after you. Clearing a level offers three relics (press 1, 2 or 3). Press S to spend 5 gold on an extra pawn, and R to restart. The code snippets above are simplified excerpts from this build, not copies of every line.
What You Learned
You used a plain array to represent a grid, piece objects to store game state, and a turn loop to keep player input and enemy actions distinct. You added captures, sketched a relic and shop pattern, and connected battles with a run state. Because the game is turn-based, those rules do not require a physics engine.
FAQ
Do I need Phaser 4 for this?
No. This build uses Phaser 3.90.0. Phaser 4 is released, but it is not required for this tutorial.
Do I need Arcade Physics for a board game?
No. The board is a grid, and a move changes a piece’s cell. Plain JavaScript arrays are enough for that logic.
Are there commercial chess roguelikes to study?
Yes. The Ouroboros King is one example of a game blending chess strategy with roguelike builds, relics, and gadgets.
Next Steps
Try replacing the prototype’s simple enemy move with legal movement rules, then let a relic modify one rule in a visible way. Once battles and rewards feel clear, add persistent unlocks or more detailed shop choices.