Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 2.43 KB

File metadata and controls

54 lines (41 loc) · 2.43 KB

TypeSokoban

中文 | 日本語 | 한국어

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 Descriptions

Symbol Meaning
👾 Player
👽 Player on Target
😃 Box
😎 Box on Target
🕶️ Target
🎇 Wall
🌑 Floor

How to Play

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:

  1. Select Level: Use .stage1 through .stage100.
  2. Controls:
    • .w: Move Up
    • .s: Move Down
    • .a: Move Left
    • .d: Move Right
  3. View Map: Append .over after your movement commands. Your IDE's type hint (Hover) will display the rendered string of the current map.
  4. 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.

Example

TypeGame
  .stage1      // Enter Level 1
  .s.d.d.over  // Move Down once, Right twice, then view the map

Core Implementation Principles

1. State Machine (src/TypeGame.ts)

The 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).

2. Coordinate Transformation (src/utils.ts)

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.

3. Recursive Rendering (src/utils.ts)

  • 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.

Development Environment

  • VSCode is recommended.
  • Ensure TypeScript version is 4.1 or higher (supporting Template Literal Types).
  • Hover over the .over property in src/index.ts to see the real-time rendered game screen.