A terminal-based Reversi (Othello) game where you write your strategy in TypeScript. Code a decideMove() function in the built-in editor, and watch it play against CPU opponents of increasing difficulty.
- Code your strategy -- Write a
decideMove(board, myColor)function in TypeScript using the built-in Vim-style editor - Sandboxed execution -- Your code runs in a QuickJS WebAssembly sandbox (1s timeout, 32MB memory limit) each turn
- 4 CPU ranks to beat:
- Rank E -- Random moves
- Rank C -- Greedy (maximizes flips + corner priority)
- Rank A -- Minimax with alpha-beta pruning
- Rank S -- Bitboard-accelerated deep search
- Progress tracking -- Wins and rank unlocks are saved between sessions
- Terminal UI -- Built with @opentui/react (React for the terminal)
- Bun >= 1.0
git clone https://github.com/henteko/reversi-code.git
cd reversi-code
bun install
bun src/index.tsx- Select a CPU rank to challenge
- Write your
decideMove()function in the editor - Your function receives
board(8x8 number array) andmyColor(1 for black, -1 for white) - Return
[row, col](0-indexed) to place your piece - Watch the game unfold turn by turn
board[row][col]:
0 = empty
1 = black
-1 = white
function decideMove(board: number[][], myColor: number): [number, number] {
// Try corners first
const corners: [number, number][] = [[0,0], [0,7], [7,0], [7,7]];
for (const [r, c] of corners) {
if (board[r][c] === 0) return [r, c];
}
// Otherwise pick the first empty cell
for (let r = 0; r < 8; r++) {
for (let c = 0; c < 8; c++) {
if (board[r][c] === 0) return [r, c];
}
}
return [0, 0];
}Note: Invalid moves or runtime errors result in an immediate forfeit.
bun src/index.tsx # Run the app
bun test # Run all tests
bun run build # Compile TypeScript
bunx tsc --noEmit # Type check only- Bun -- Runtime
- @opentui/react + React -- Terminal UI
- @sebastianwessel/quickjs -- QuickJS WebAssembly-sandboxed code execution
- esbuild -- TypeScript transpilation
MIT
