Skip to content

About

Claude's Challenge — a from-scratch Chip's Challenge engine for the browser. Bring your own assets.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude's Challenge

A browser-based port of the classic puzzle game Chip's Challenge, built with React and TypeScript.

Overview

Chip's Challenge is a tile-based puzzle game where you control Chip, a nerdy hero who must collect computer chips and reach the exit while avoiding obstacles and enemies. This web port faithfully recreates the original game mechanics from the MS Windows version.

⚠️ Code Only — No Game IP Included

This repository contains no intellectual property: no levels, no sprites, no sounds, no game icons. It is a clean-room game engine. All original-game media and level data are the property of their respective rights holders and have been deliberately stripped out.

Getting the assets

All assets are git-ignored and never committed, so a fresh clone has none. A helper script attempts to pull publicly available assets into public/:

./scripts/pull-assets.sh

Or bring your own

Prefer your own media? Drop files directly into these paths instead — the script is optional:

Asset Drop it here How to obtain
Levels public/assets/levels/*.json ./scripts/pull-assets.sh, or convert your own data file: node tools/convert-levels.cjs path/to/CHIPS.DAT public/assets/levels
Sprite sheets public/assets/sprites/Sprites.png and WindowSprites.png ./scripts/pull-assets.sh, or your own tile/sprite graphics
Sound effects public/assets/audio/*.WAV, *.mp3 ./scripts/pull-assets.sh, or your own sound files (expected names are in src/audio/AudioManager.ts)
Favicon (optional) public/favicon.png ./scripts/pull-assets.sh, or any 256×256 PNG

If you supply your own, ask your AI assistant to integrate them — for example: "I dropped my WAV files in public/assets/audio and converted my .dat file into public/assets/levels; wire them up so the game loads them." Sprite layout lives in src/rendering/SpriteSheet.ts; audio mapping in src/audio/AudioManager.ts.


Controls

Key Action
Arrow Keys Move Chip
Space Start level / Dismiss messages
P Pause/Unpause game
R Restart current level
N Next level
B Previous level

Game Objectives

  1. Collect Chips: Gather all the required computer chips (IC chips) shown in the HUD
  2. Open the Socket: Once all chips are collected, the chip socket opens
  3. Reach the Exit: Navigate to the exit tile to complete the level
  4. Beat the Clock: Most levels have a time limit (shown in the HUD)

Terrain Types

Basic Terrain

Tile Description
Floor Basic walkable surface
Wall Impassable barrier
Gravel Only Chip and blocks can pass; stops sliding creatures
Dirt Turns to floor when Chip walks on it
Exit Level completion tile (requires all chips collected)
Socket Blocks passage until all chips are collected

Hazards

Tile Description
Water Drowns Chip (unless wearing Flippers); blocks can fill water
Fire Burns Chip (unless wearing Fire Boots); Fireballs are immune
Bomb Explodes on contact, destroying Chip or creatures

Special Floors

Tile Description
Ice Causes sliding; Chip can control with Ice Skates
Ice Corner Redirects sliding entities around corners
Force Floor Pushes entities in arrow direction; Suction Boots allow resistance
Random Force Floor Pushes in a random direction each time
Teleporter Transports to next teleporter in reading order
Hint Displays level hint when Chip stands on it

Interactive Elements

Tile Description
Trap Holds creatures/blocks until released by brown button
Clone Machine Creates copies of creatures/blocks when red button pressed
Toggle Wall Alternates between open/closed when green button pressed
Blue Wall (Real) Appears as blue wall, becomes solid wall when touched
Blue Wall (Fake) Appears as blue wall, becomes floor when touched
Thin Wall Blocks movement from specific directions
Recessed Wall Becomes a wall after Chip passes through
Hidden Wall Invisible wall that blocks movement
Invisible Wall Permanently invisible impassable wall

Buttons

Button Color Effect
Brown Button Brown Releases connected trap while pressed
Red Button Red Activates connected clone machine once
Green Button Green Toggles ALL toggle walls on the level
Blue Button Blue Reverses ALL tanks on the level

Items

Keys

Key Lock Notes
Blue Key Blue Lock Consumed on use
Red Key Red Lock Consumed on use
Yellow Key Yellow Lock Consumed on use
Green Key Green Lock Not consumed - infinite uses

Boots

Boot Effect
Flippers Allows swimming in water
Fire Boots Allows walking through fire
Ice Skates Allows control on ice
Suction Boots Allows resistance on force floors

Note: The Thief tile removes ALL boots from Chip's inventory.

Creatures

All creatures kill Chip on contact. Creatures move at half Chip's speed (every 2 game ticks).

Movement Patterns

Creature Behavior
Bug Follows left wall - always tries to turn left, then forward, then right, then back
Paramecium Follows right wall - always tries to turn right, then forward, then left, then back
Fireball Bounces off walls - tries forward, then right, then left, then back
Glider Bounces off walls - tries forward, then left, then right, then back
Pink Ball Bounces back and forth - reverses direction when blocked
Tank Moves in facing direction until blocked; reverses when blue button pressed
Walker Random movement - picks a random valid direction when blocked
Blob Completely random movement each tick; moves at 1/4 speed
Teeth Chases Chip - moves toward Chip's position; moves at 1/4 speed

Creature Interactions

  • Creatures die in water (except Glider, which can fly over)
  • Creatures die in fire (except Fireball, which is immune)
  • Creatures die on bombs (destroys both creature and bomb)
  • Creatures can be trapped by traps
  • Creatures can be cloned by clone machines
  • Creatures slide on ice and force floors

Physics System

Tick System

  • The game runs at 10 ticks per second
  • Chip can move every tick
  • Most creatures move every 2 ticks
  • Blob and Teeth move every 4 ticks
  • Timer decreases by 1 second every 10 ticks

Movement Priority

  1. Forced Chip movement (from ice/force floors)
  2. Chip voluntary movement
  3. Forced creature movement (from ice/force floors)
  4. Creature AI movement

Sliding Mechanics

  • Ice: Entities slide until hitting an obstacle, then bounce back
  • Force Floors: Entities are pushed in arrow direction
  • Ice Skates: Allow Chip to walk normally on ice
  • Suction Boots: Allow Chip to walk normally on force floors
  • Sliding entities cannot change direction mid-slide (except with appropriate boots)

Block Pushing

  • Chip can push blocks in any direction
  • Blocks slide on ice and force floors
  • Blocks can fill water (block is destroyed, water becomes floor)
  • Blocks explode bombs (both are destroyed)
  • Blocks cannot push other blocks

Collision Detection

  • Chip dies if touching a creature
  • Chip dies if a creature moves onto Chip's tile
  • Multiple entities can occupy the same tile during transitions

Layer System

The game uses a 4-layer rendering system:

  1. Lower Layer (0): Terrain (floor, walls, ice, water, etc.)
  2. Upper Layer (1): Items and static objects (keys, chips, buttons, traps)
  3. Visitor Low (2): Moving blocks and creatures
  4. Visitor High (3): Chip and active entities

Level Format

Levels are stored in JSON format with:

  • Dimensions (32x32 standard)
  • Time limit (0 = unlimited)
  • Chips required
  • Title and password
  • Hint text
  • Lower and upper layer tile data
  • Trap connections (brown button → trap)
  • Clone connections (red button → clone machine)
  • Creature spawn order

Level Editor

The game includes a full-featured level editor for creating and modifying levels.

Editor Controls

Key Action
P / 1 Pencil tool
E / 2 Eraser tool
I / 3 Eyedropper tool
F / 4 Fill tool
5 Select tool
6 Path Maker tool
G Toggle grid
L Set active layer to Lower
U Set active layer to Upper
Ctrl+Z Undo
Ctrl+Y Redo
Ctrl+C Copy selection
Ctrl+X Cut selection
Ctrl+V Paste
Delete Delete selection
F5 Play test level

Editor Features

Tools

  • Pencil: Draw tiles on the active layer
  • Eraser: Remove tiles from the active layer
  • Eyedropper: Pick tile type from the canvas
  • Fill: Flood fill with selected tile
  • Select: Rectangle selection for copy/cut/paste
  • Path Maker: Draw paths with auto-rotation (great for force floors)
  • Trap Connector: Two-click tool to connect brown buttons to traps
  • Clone Connector: Two-click tool to connect red buttons to clone machines

View Toggles

  • Grid: Show/hide tile grid
  • Connections: Show/hide trap and clone connection lines
  • Lower/Upper: Show/hide layer visibility
  • Hidden: Reveal hidden walls, invisible walls, and fake blue walls (purple border)
  • Order: Show creature movement order numbers

Dialogs

  • Connections: Manage trap/clone connections, reorder priority
  • Creatures: Manage creature movement order, auto-populate from map
  • Resize: Change level dimensions
  • Load Level: Browse and load existing game levels

Level Properties

  • Level number, title, and password
  • Time limit (0 = unlimited)
  • Chips required to open socket
  • Hint text displayed on hint tiles

Development

Tech Stack

  • React 18
  • TypeScript
  • Vite
  • HTML5 Canvas

Running Locally

npm install
npm run dev

Building

npm run build

Important: Always run npm run build before committing and pushing changes. The build script runs the full test suite and will catch any broken solutions or regressions.

Project Structure

src/
├── components/       # React UI components (game screens)
├── engine/
│   ├── core/        # Game engine (Game, Level, Block, BlockFactory)
│   ├── types/       # TypeScript types and enums (BlockType, Direction)
│   ├── reactions/   # Tile interaction behaviors (movement reactions)
│   └── behaviors/   # Creature AI and tick behaviors
├── editor/
│   ├── components/  # Editor UI (EditorApp, EditorCanvas, dialogs)
│   ├── state/       # Editor state management (EditorContext, EditorState)
│   ├── models/      # Editor data models (EditorLevel)
│   ├── hooks/       # Custom hooks (useKeyboardShortcuts)
│   └── utils/       # Editor utilities (testLevelStore)
├── rendering/       # Canvas rendering and sprites (SpriteSheet)
├── audio/           # Sound effects (AudioManager)
└── input/           # Keyboard input handling

Automated Solver

The project includes an A* pathfinding solver that can automatically solve some levels.

Running the Solver

npx tsx tests/scripts/solve-level.ts <level_number> --astar --max-nodes=500000

Optimizing Solutions

After finding a solution (manually or via solver), always run the solution path optimizer to compress timing:

npx tsx tests/scripts/optimize-solution-paths.ts <level_number>

This script optimizes "pure floor walking" segments where Chip walks on simple terrain with no interactions, compressing the timing to minimum spacing. It uses three strategies:

  1. Pure floor segment compression
  2. Full timing compression
  3. Binary search gap optimization (for timing-sensitive sections)

To optimize all solutions at once:

npx tsx tests/scripts/optimize-solution-paths.ts --all

Current Limitations

The solver currently works well for navigation puzzles but struggles with:

  • Block pushing - Cannot plan push sequences to fill water or reach chips
  • Creature timing - Doesn't account for creature movement patterns
  • Toggle walls - Doesn't track toggle wall state changes
  • Traps - Doesn't understand trap/button mechanics
  • Clone machines - Doesn't handle cloning mechanics

Solver Architecture & Performance Analysis

Current Implementation Issues

The solver has several performance bottlenecks:

  1. O(n²) Re-simulation - Every node re-simulates ALL moves from start

    • 200-move solution = 20,100 total game simulations
    • This is the #1 bottleneck
  2. O(n log n) Priority Queue - Uses array.sort() per extraction

    • Should be O(log n) with binary heap
  3. String-based State Hashing - Creates/compares strings

    • Should use numeric Zobrist hashing for O(1) operations
  4. Full State Copying - Copies move array for each new state

    • Should use parent pointers and reconstruct path at end
  5. No Preprocessing - Searches blind without analyzing level structure

Complexity Analysis

State space size without optimizations:

  • Positions: P = 1024 (32×32)
  • Inventory: I ≈ 256 (key counts × boot combinations)
  • Chips collected: C = 2^n (n = chips needed, up to 100+)
  • Blocks: B = P^b (b = block count)
  • Toggles: T = 2^t (t = toggle count)

Worst case: O(P × I × C × B × T) - astronomically large

Solver Improvement Roadmap

Phase 1: Performance Optimizations (10-100x speedup)

1.1 Incremental State Simulation

Instead of: simulate(levelData, [move1, move2, ..., moveN])
Do:         clone_state(parent) → apply_single_move(state, moveN)
  • Implement GameState.clone() for O(1) state copying
  • Apply single move to cloned state instead of full replay
  • Reduces O(n²) to O(n) for n-move solutions

1.2 Binary Heap Priority Queue

class MinHeap<T> {
  insert(item: T, priority: number): void  // O(log n)
  extractMin(): T                          // O(log n)
}
  • Replace array.sort() with proper heap
  • Reduces per-node cost from O(n log n) to O(log n)

1.3 Zobrist Hashing

// Precompute random 64-bit numbers for each (position, piece) pair
const zobrist: Map<string, bigint> = precomputeZobristTable();

// State hash = XOR of all piece hashes
// Incremental update: hash ^= old_piece_hash ^ new_piece_hash
  • O(1) incremental hash updates when state changes
  • O(1) hash comparison (single integer compare)

1.4 Parent Pointer Path Reconstruction

interface SolverState {
  parent: SolverState | null;
  move: Direction | null;  // Move that led here
  // ... other fields
}
// Reconstruct path only when solution found
  • Eliminates array copying for each new state
  • Reduces memory from O(nodes × depth) to O(nodes)

Phase 2: Preprocessing & Analysis (prune search space)

2.1 Static Reachability Analysis

Before search:
1. BFS from start ignoring keys/boots → reachable_without_items
2. For each item type, compute what it unlocks
3. Build dependency graph: item A required before item B
  • Identify unreachable areas early
  • Detect impossible levels (missing required items)

2.2 Landmark Detection

Critical items that MUST be collected:
- All chips (required for socket)
- Keys blocking only path to chips/exit
- Boots blocking only path to chips/exit
  • Reduces chip collection to traveling salesman variant
  • Enables subgoal decomposition

2.3 Dead State Detection

Prune states where:
- Required chip became unreachable (pushed block wrong way)
- Required key used on wrong door
- Trapped with no escape
  • Avoid exploring doomed branches

Phase 3: Hierarchical Search (divide and conquer)

3.1 Subgoal Decomposition

High-level plan:
1. Identify all items to collect (chips, keys, boots)
2. Compute optimal/near-optimal collection order (TSP heuristics)
3. Solve pathfinding between consecutive subgoals
  • Transforms one huge search into many small searches
  • Each segment is independent and cacheable

3.2 Region-Based Planning

1. Detect "rooms" separated by doors/sockets
2. Solve intra-room navigation first
3. Plan inter-room transitions (key management)
  • Natural decomposition for key/door puzzles

Phase 4: Game Mechanics Support

4.1 Block Pushing

interface BlockState {
  positions: Map<BlockId, {x, y}>;  // Current block positions
  waterFilled: Set<string>;         // "x,y" of filled water tiles
}
  • Track block positions in state hash
  • Valid moves include "push block in direction D"
  • Detect Sokoban-style deadlocks (block in corner, etc.)

4.2 Toggle Wall State

interface ToggleState {
  wallsOpen: boolean;  // Single bit - all toggles share state
}
  • Include in state hash
  • Same position with different toggle state = different node

4.3 Trap Mechanics

interface TrapState {
  trapsOpen: Set<string>;  // "x,y" of currently open traps
  buttonConnections: Map<string, string>;  // button → trap
}
  • Track which traps are held open
  • Plan paths that use buttons strategically

4.4 Creature Handling

Option A: Time-Expanded Graph (deterministic creatures)

Node = (position, tick mod creature_period)
Edge exists only if move is safe at that tick
  • Pre-compute creature positions for all relevant ticks
  • Search in expanded graph

Option B: Simulation with Creature Prediction

For each candidate move:
  1. Predict creature positions after move
  2. Check if Chip survives
  3. Include tick in state hash
  • More flexible, handles complex interactions
  • Higher per-node cost

Phase 5: Algorithm Variants

5.1 IDA (Iterative Deepening A)**

for threshold = h(start) to infinity:
  result = depth_limited_search(start, threshold)
  if result == FOUND: return solution
  threshold = min_exceeded_f_value
  • Memory: O(depth) vs O(nodes) for A*
  • Better for deep solutions with good heuristics

5.2 Weighted A (Greedy bias)*

f(n) = g(n) + w × h(n)  // w > 1 favors heuristic
  • w=1.0: Optimal but slow
  • w=2.0: Usually 2x faster, solutions within 2x optimal
  • w=5.0: Very fast, good for finding ANY solution

5.3 Beam Search (Bounded memory)

Keep only top-k nodes at each depth level
  • Fixed memory regardless of search space
  • May miss optimal solution

Phase 6: Better Heuristics

6.1 True Distance (ignoring items)

Precompute: BFS from exit to all tiles (ignoring keys/boots)
Heuristic: precomputed_distance[chip_position]
  • Accounts for walls, unlike Manhattan distance
  • Still admissible (never overestimates)

6.2 Chip Collection Estimate

For remaining chips, estimate collection cost:
- Minimum spanning tree of chip positions
- Or nearest-neighbor TSP approximation
  • Better than "chips × constant"

6.3 Required Items Distance

If chips remain behind blue door and no blue key:
  h += distance_to_nearest_blue_key + distance_key_to_door
  • Accounts for item dependencies

Implementation Priority

Recommended order for maximum impact:

Priority Task Expected Speedup Complexity
1 Incremental simulation 10-100x Medium
2 Binary heap 2-5x Easy
3 Zobrist hashing 2-3x Easy
4 Static reachability Prunes 20-50% Medium
5 Weighted A* (w=2) 2-4x Easy
6 Block pushing +20 levels Hard
7 Toggle walls +10 levels Medium
8 True distance heuristic 1.5-2x Medium
9 Creature avoidance +15 levels Hard
10 Hierarchical planning 10-100x for big levels Hard

Solved Levels

Currently 15 of 149 levels have automated solutions: 1, 2, 3, 6, 7, 10, 16, 17, 22, 39, 40, 75, 135, 142, 145

Credits

  • Original game by Chuck Sommerville (Epyx, 1989)
  • Windows port by Microsoft (1992)
  • This web port based on the UWP C# implementation

License

This is a fan-made recreation for educational purposes.

About

Claude's Challenge — a from-scratch Chip's Challenge engine for the browser. Bring your own assets.

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages