This is a "Sokoban" game implemented entirely within the TypeScript type system. It contains no runtime JavaScript logic; all game logic, map rendering, and win/loss conditions are processed during the compilation phase via type checking.
| Symbol | Meaning |
|---|---|
👾 |
Player |
👽 |
Player on Target |
😃 |
Box |
😎 |
Box on Target |
🕶️ |
Target |
🎇 |
Wall |
🌑 |
Floor |
The game is played using TypeScript property access (Dot Notation). In src/index.ts, you can control the player's movement through a sequence of dots:
- Select Level: Use
.stage1through.stage100. - Controls:
.w: Move Up.s: Move Down.a: Move Left.d: Move Right
- View Map: Append
.overafter your movement commands. Your IDE's type hint (Hover) will display the rendered string of the current map. - Victory Condition: Once all boxes are pushed onto targets (i.e., the
😃symbol is no longer present in the map), the type system grants access to.GameClear.WoW.MuchFun.
TypeGame
.stage1 // Enter Level 1
.s.d.d.over // Move Down once, Right twice, then view the mapThe core logic is encapsulated in the Step type. It determines what a cell should become in the next turn based on its current type and the states of the two cells ahead and behind it in the direction of movement (prev2, prev1, next1, next2).
To simplify the logic, the system only implements the logic for "Move Left". For Up, Down, and Right movements, the system uses the MatrixRotateAndScale type to rotate/transpose the 2D array (matrix), converting the problem into a "Move Left" scenario, and then rotates it back.
Join: Concatenates a tuple of symbols into a single long string.Render: Converts the 2D array into a nested object structure, allowing the IDE's type preview to display the map as a multi-line string.
- VSCode is recommended.
- Ensure TypeScript version is 4.1 or higher (supporting Template Literal Types).
- Hover over the
.overproperty insrc/index.tsto see the real-time rendered game screen.