Skip to content

Latest commit

 

History

History
156 lines (128 loc) · 3.71 KB

IMPLEMENTATION_PLAN.md

File metadata and controls

156 lines (128 loc) · 3.71 KB

Solana Monopoly Implementation Plan using Bolt ECS

1. Components

Based on the reference implementation, we'll create the following components:

1.1 Player Component

#[component]
#[derive(Copy)]
pub struct PlayerComponent {
    pub name: String,
    pub cash: u64,
    pub position: u8,
    pub jail_turns: u8,
    pub properties: Vec<u8>,  // Indices of owned properties
}

1.2 Property Component

#[component]
#[derive(Copy)]
pub struct PropertyComponent {
    pub name: String,
    pub color: u8,  // Enum index
    pub cost: u64,
    pub rent: [u64; 6],  // Base rent + 1-4 houses + hotel
    pub house_cost: u64,
    pub hotel_cost: u64,
    pub owner: Option<u8>,
    pub houses: u8,
}

1.3 GameState Component

#[component]
#[derive(Copy)]
pub struct GameStateComponent {
    pub current_player: u8,
    pub free_parking_pool: u64,
    pub community_chest_index: u8,
    pub chance_index: u8,
}

2. Systems

2.1 Movement System

  • Handles dice rolling and player movement
  • Manages passing GO
  • Triggers property landing events
  • Handles jail entry/exit

2.2 Property System

  • Handles property purchases
  • Manages rent collection
  • Implements house/hotel building
  • Handles property trading (future enhancement)

2.3 Card System

  • Implements Chance card effects
  • Implements Community Chest card effects
  • Manages card deck state

2.4 Bank System

  • Handles all monetary transactions
  • Manages free parking pool
  • Processes tax payments

3. World Program Implementation

3.1 Initialization

// Create world instance
const worldPda = FindWorldPda(worldId);
const initWorldIx = createInitializeNewWorldInstruction({
    world: worldPda,
    registry: registryPda,
    payer: provider.wallet.publicKey,
});

// Initialize board state
const boardEntity = FindEntityPda(worldId, new anchor.BN(0));
const propertyComponents = initializeProperties(boardEntity);

// Initialize players
const playerEntities = initializePlayers(worldId, playerCount);

3.2 Game Flow

  1. Player turns managed by GameState component
  2. Movement system processes dice rolls and movement
  3. Property/Card systems handle landing outcomes
  4. Bank system processes all financial transactions

3.3 State Management

  • All game state stored in components as Solana accounts
  • PDAs used for deterministic account derivation
  • Component updates handled through system instructions

4. Implementation Phases

Phase 1: Core Setup

  1. Initialize project with bolt-cli
  2. Create basic components (Player, Property)
  3. Implement World Program structure

Phase 2: Basic Gameplay

  1. Implement Movement System
  2. Add Property System for basic buying/rent
  3. Create Bank System for transactions

Phase 3: Advanced Features

  1. Add Card System
  2. Implement house/hotel building
  3. Add jail mechanics

Phase 4: Testing & Deployment

  1. Unit tests for all systems
  2. Integration tests for game flow
  3. Deployment to Solana testnet/mainnet

5. Technical Considerations

5.1 Account Management

  • Use PDAs for all game-related accounts
  • Implement proper account validation
  • Handle account size limits appropriately

5.2 Transaction Handling

  • Batch operations where possible
  • Implement proper error handling
  • Consider transaction size limits

5.3 Security

  • Implement proper access controls
  • Validate all state transitions
  • Ensure atomic operations

6. Testing Strategy

6.1 Unit Tests

  • Test each system independently
  • Verify component state changes
  • Test edge cases and error conditions

6.2 Integration Tests

  • Test complete game flows
  • Verify cross-system interactions
  • Test concurrent operations

6.3 On-chain Testing

  • Deploy to testnet
  • Verify gas costs
  • Test with multiple players