A Chrome extension that automatically tracks game state for Settlers of Catan games played on colonist.io. The extension monitors chat messages and maintains a real-time count of resources, development cards, dice rolls, and player statistics using advanced probabilistic variant tracking.
- Player Resources: Tracks wheat, sheep, brick, wood, and ore for all players
- Development Cards: Monitors knights, victory points, year of plenty, road builders, and monopolies
- Dice Rolls: Records frequency of all dice roll results (2-12)
- Blocked Dice Tracking: Monitors when robber blocks resource production by dice number and resource type
- Building Counts: Tracks settlements, cities, and roads remaining for each player
- Victory Points: Monitors VP progress for all players
- Modern Overlay: Clean, organized display with resource tables and dice roll charts
- Probabilistic Resource Display: Shows guaranteed resources plus probability of additional resources
- Draggable & Resizable: Move and scale the overlay to your preference
- Minimize/Maximize: Collapse to header-only for minimal screen usage
- Responsive Tables: Color-coded resource tracking with remaining bank resources
- Interactive Charts: Visual dice roll frequency with statistical bars
- "You" Player Setup: One-time dialog to identify your player for accurate tracking
- Automatic Detection: Triggers on first dice roll when all players are loaded
- Message Reprocessing: Re-analyzes all chat history once your identity is known
- Enhanced Theft Tracking: Properly handles "stole [resource] from you" messages
- Live Updates: Game state updates automatically as chat messages appear
- Page Refresh Support: Processes existing chat history when page is refreshed
- Intelligent Processing: Pauses during setup, then reprocesses for accuracy
- Comprehensive Logging: Detailed console output for debugging
- Resource collection from dice rolls
- Building placement (settlements, cities, roads)
- Development card purchases and usage
- Player-to-player trades
- Bank trades (4:1 and port trades)
- Resource stealing (robber and knight)
- "From you" theft tracking (requires player identification)
- Development card effects (Year of Plenty, Monopoly, Road Building)
- Resource discarding
- Starting resource distribution
- Variant Tree System: When uncertainty exists (like unknown resource steals), creates a tree of possible game states with calculated probabilities
- Smart Variant Resolution: Automatically eliminates impossible variants when players take actions that reveal information
- Dynamic Probability Calculations: Real-time recalculation of resource probabilities as new information becomes available
- Probabilistic Resource Display: Shows minimum guaranteed resources and probability of having additional resources (e.g., "2 +67%" means at least 2 guaranteed, 67% chance of more)
- Branch Elimination: When players make offers or spend resources, impossible variants are automatically pruned
- Automatic Deduction: Single-resource-type steals are instantly resolved without creating variants
- Node.js (v14 or higher)
- npm
- Google Chrome browser
-
Clone the repository
git clone <repository-url> cd catan-counter
-
Install dependencies
npm install
-
Build the extension
npm run build
-
Load in Chrome
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" in the top right
- Click "Load unpacked"
- Select the
catan-counterfolder
- Open Chrome and navigate to
npm run build- Bundle TypeScript modules into single JavaScript file using Rollupnpm run watch- Watch for TypeScript changes and auto-bundlenpm run format- Format all files with Prettiernpm run format:check- Check if files are properly formattednpm run dev- Development mode: auto-format and bundle on file changes
npm test- Run all tests with Jestnpm run test:watch- Run tests in watch mode (auto-rerun on changes)npm run test:coverage- Run tests and generate coverage reportnpm run test:ci- Run tests in CI mode (no watch, with coverage)npm run test:update- Update Jest snapshots
-
Start development mode
npm run dev
-
Make changes to any TypeScript files in the
src/directory -
Run tests to ensure your changes work correctly
npm test -
Reload extension in Chrome (click refresh icon on extension card)
-
Test on colonist.io by starting or joining a game
The project uses Jest 30.0.2 with TypeScript support for comprehensive testing of the variant-based probabilistic system.
# Run all tests once
npm test
# Run tests in watch mode (reruns on file changes)
npm run test:watch
# Run tests with coverage report
npm run test:coverage
# Run tests in CI mode
npm run test:ciTests are organized with comprehensive coverage of game state management, chat parsing logic, and the variant-based probabilistic tracking system. The test suite includes both unit tests and integration tests with real HTML scenarios from colonist.io.
- Tests use TypeScript with Jest globals (
@jest/globals) - DOM environment is mocked for browser extension testing
- Game state functions are thoroughly tested including the variant tree system
- Coverage targets: 80% for branches, functions, lines, and statements
- Helper functions like
expectMatchingVariantCombinationsfor order-independent variant testing
The test suite includes comprehensive testing of the probabilistic variant tracking:
- Variant creation when unknown steals occur
- Probability calculations for different resource combinations
- Variant resolution when players take actions that eliminate possibilities
- Complex multi-steal scenarios with automatic branch pruning
- Real-world game scenarios with expected probability outcomes
-
Navigate to colonist.io and start/join a Catan game
-
Extension activates automatically when it detects a game chat
-
Player identification setup - On the first dice roll, a dialog will appear asking you to identify which player you are. This enables accurate tracking of "from you" messages.
-
View game state in the enhanced overlay that appears in the top-right corner
-
Interact with the overlay:
- Drag the header to move the overlay
- Minimize using the (β) button to collapse to header only
- Resize by dragging the bottom-right corner to scale proportionally
-
Monitor real-time updates as the game progresses
The overlay features an organized, visual layout with:
- Main Resource Table: Shows current known resource counts for each player
- Probability Table: Displays minimum guaranteed resources and probability of additional resources
- Header columns with resource emojis (ππΎπ§±π²β°οΈ) and remaining bank resources
- Color-coded cells for easy resource identification
- Probabilistic Display: Format like "2 +67%" (2 guaranteed, 67% chance of more)
- Visual bar graph showing frequency of each dice roll (2-12)
- Roll counts displayed above each bar
- Color coding: Red for 7, teal for 6&8, blue for others
- Header bar for dragging and minimizing
- Resize handle in bottom-right corner for proportional scaling
- Minimize button to collapse to header-only view
- Modular TypeScript: Organized into separate modules for maintainability
- Rollup Bundling: Multiple TypeScript files compiled into single JavaScript output
- Content Script: Injected into colonist.io pages
- Chat Monitoring: Uses MutationObserver to detect new messages
- Pattern Matching: Analyzes chat messages and HTML structure
- Variant Tree Management: Maintains probabilistic game states with automatic branch pruning
The extension recognizes 25+ different game scenarios including:
- Building placement and purchases
- Resource collection and trading
- Development card usage
- Player theft scenarios (including "from you" messages)
- Unknown resource steals with variant tree creation
- Special game events (robber movement, discarding, etc.)
The extension features a sophisticated variant tree system for tracking uncertain game states:
Variant: Represents a single possible game state with probabilityVariantNode: Tree node containing variants with parent/child relationshipsVariantTree: Manages the complete tree of possible game statesVariantTransactionProcessor: Handles transaction processing across variantsPropbableGameState: Integrates variant system with game state management
- Probabilistic Resource Tracking: Calculates exact probabilities based on known information
- Smart Deduction: Automatically resolves steals when victims have only one resource type
- Branch Elimination: Removes impossible variants when players reveal information through actions
- Transaction Type Safety: Uses discriminated unions for type-safe transaction processing
- Real-time Recalculation: Maintains accurate probabilities as game state evolves
- Unknown Steal: Player steals from someone with multiple resource types β Creates variants for each possibility
- Resource Offer: Player offers resources they might not have β Eliminates impossible variants
- Building Action: Player builds something requiring specific resources β Resolves which variant was correct
- Multiple Steals: Handles complex scenarios with multiple unknown steals and their interactions
- Player Detection: Automatically identifies when player setup is needed
- Processing Pause: Stops processing new messages during player identification
- Complete Reanalysis: Re-examines all chat history with "you" player context
- Accurate Attribution: Ensures proper resource tracking for all theft events
The codebase is organized into focused modules for better maintainability:
types.ts- All TypeScript interface definitions and type declarationsgameState.ts- Game state initialization, player management, and resource trackinggameStateWithVariants.ts- Enhanced game state with probabilistic variant trackingvariants.ts- Core variant tree system classesvariantTransactions.ts- Transaction processing for the variant systemdomUtils.ts- DOM element querying, resource parsing, and utility functionsoverlay.ts- Draggable game state overlay UI with probabilistic resource displaychatParser.ts- Core chat message parsing logic handling 24+ game scenarioscontent.ts- Main entry point, initialization, and mutation observer setup
All modules are bundled into a single content.js file using Rollup for optimal browser performance.
- Chrome (primary target)
- Other Chromium-based browsers (Edge, Brave, etc.)
catan-counter/
βββ src/
β βββ content.ts # Main entry point and initialization
β βββ types.ts # TypeScript interface definitions
β βββ gameState.ts # Game state management and utilities
β βββ gameStateWithVariants.ts # Enhanced game state with variant tracking
β βββ variants.ts # Core variant tree system classes
β βββ variantTransactions.ts # Transaction processing for variants
β βββ domUtils.ts # DOM querying and utility functions
β βββ overlay.ts # Draggable overlay UI with probabilistic display
β βββ chatParser.ts # Chat message parsing logic
β βββ __tests__/ # Test files directory
β βββ gameProbabilities.test.ts # Variant system integration tests
β βββ testUtils.ts # Test helper functions
β βββ gameActions.test.ts # Game action tests
β βββ chatParser.integration.test.ts # Chat parser integration tests
β βββ scenarios/ # Test HTML scenarios
βββ manifest.json # Chrome extension manifest
βββ overlay.css # Styling for game overlay
βββ content.js # Bundled JavaScript output (generated)
βββ rollup.config.js # Rollup bundler configuration
βββ jest.config.js # Jest testing configuration
βββ jest.setup.ts # Test environment setup
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ .prettierrc # Code formatting rules
βββ .prettierignore # Files to ignore in formatting
βββ README.md # This file
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run formatting (
npm run format) - Run tests (
npm test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the ISC License - see the package.json file for details.
This extension is designed for educational and analytical purposes. It does not provide any unfair advantage in gameplay and only tracks information that is already visible in the game chat.