## Rush Hour Game - Product Requirements Document
### 1. Product Overview
Rush Hour is a sliding block puzzle game where players must strategically move vehicles to free a red car from a traffic jam.
### 2. Objectives
- Create an engaging puzzle game experience
- Implement progressive difficulty levels to appeal to various skill levels
- Provide a technically sound implementation using PostGIS spatial database
### 3. Target Audience
- Puzzle game enthusiasts
- Players of all ages, from beginners to expert puzzle solvers
- Users interested in spatial reasoning challenges
### 4. Core Game Mechanics
#### 4.1 Gameplay Rules
- **Goal**: Move the red car to the exit by sliding other vehicles out of its path
- **Movement**: Vehicles can only move forward or backward in their facing direction (no lifting or rotation)
- **Constraints**: Vehicles are fixed in horizontal or vertical orientation
- **Win Condition**: Red car reaches the designated exit slot
#### 4.2 Game Setup
- Board is a 6x6 grid
- Challenge cards determine initial vehicle positions
- Vehicles occupy 2-3 grid spaces each
### 5. Technical Implementation
#### 5.1 Database Schema
```sql
CREATE TABLE vehicles (
vid SERIAL PRIMARY KEY,
name TEXT NOT NULL,
color TEXT NOT NULL,
ori CHAR(1) NOT NULL CHECK (ori IN ('H','V')), -- H=horizontal, V=vertical
length INT NOT NULL CHECK (length IN (2,3)),
x INT NOT NULL CHECK (x BETWEEN 1 AND 6),
y INT NOT NULL CHECK (y BETWEEN 1 AND 6)
);
CREATE VIEW vehicle_geom AS
SELECT
vid, name, color, ori, length, x, y,
ST_MakePolygon(
ST_MakeLine(ARRAY[
ST_Point(x-1, y-1),
CASE WHEN ori='H' THEN ST_Point(x-1+length, y-1) ELSE ST_Point(x-1, y-1+length) END,
CASE WHEN ori='H' THEN ST_Point(x-1+length, y-1+1) ELSE ST_Point(x-1+1, y-1+length) END,
ST_Point(x-1+1, y-1+1),
ST_Point(x-1, y-1)
])
) AS geom
FROM vehicles;
```
#### 5.2 Movement Logic
```sql
CREATE OR REPLACE FUNCTION move_vehicle(
_vid INT, _dx INT, _dy INT
) RETURNS VOID AS $
DECLARE
v RECORD;
new_geom GEOMETRY;
BEGIN
SELECT * INTO v FROM vehicles WHERE vid=_vid;
-- compute new geom
new_geom := ST_Translate(
(SELECT geom FROM vehicle_geom WHERE vid=_vid),
_dx, _dy
);
-- bounds-check inside 0..6
IF NOT ST_Within(new_geom, ST_MakeEnvelope(0,0,6,6,0)) THEN
RAISE EXCEPTION 'out of board';
END IF;
-- collision-check against others
IF EXISTS (
SELECT 1 FROM vehicle_geom vg
WHERE vg.vid<>_vid AND ST_Intersects(vg.geom, new_geom)
) THEN
RAISE EXCEPTION 'collision';
END IF;
-- apply move: translate x,y
UPDATE vehicles
SET x = x + _dx, y = y + _dy
WHERE vid=_vid;
END;
$ LANGUAGE plpgsql;
```
### 6. Implementation Phases
#### 6.1 Phase 1: Core Backend
1. Set up PostGIS database environment
2. Implement vehicle and game board schemas
3. Create movement validation logic
#### 6.2 Phase 2: Frontend Development
1. Develop board visualization using QGIS/pgAdmin or custom interface
2. Create HTML+Leaflet interface for web-based gameplay
3. Implement WebSocket communication for move execution
#### 6.3 Phase 3: Game Features
1. Implement challenge cards with varying difficulties
2. Add win condition detection and celebration
3. Create game state persistence
### 7. Success Metrics
- Functional gameplay with accurate collision detection
- Smooth vehicle movement within constraints
- Proper win condition detection
- Multiple solvable puzzle configurations
### 8. Future Enhancements
- User accounts and progress tracking
- Custom puzzle creator
- Time-based challenges
- Mobile application version