Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fgmacedo/python-statemachine
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: develop
Choose a base ref
...
head repository: bcorfman/python-statemachine
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 9 files changed
  • 1 contributor

Commits on Oct 12, 2025

  1. feat: Add probabilistic transitions with weighted random selection

    Add support for weighted transitions that allow non-deterministic state
    transitions based on configurable probabilities. This is useful for game AI,
    simulations, and randomized workflows.
    
    Key features:
    - Add optional 'weight' parameter to Transition class
    - Add optional 'random_seed' parameter to StateMachine for deterministic testing
    - Implement weighted selection in both sync and async engines
    - Automatically display probability percentages in state diagrams
    - Full backward compatibility (no weights = original first-match behavior)
    - Zero/negative weights are ignored
    - Conditions (guards/validators) work seamlessly with weighted transitions
    - Complete pickling support
    
    Changes:
    - statemachine/transition.py: Add weight parameter and repr support
    - statemachine/statemachine.py: Add random_seed and Random instance
    - statemachine/engines/sync.py: Implement weighted selection logic
    - statemachine/engines/async_.py: Implement weighted selection logic
    - statemachine/contrib/diagram.py: Add probability labels to diagrams
    - README.md: Add probabilistic transitions to features list
    - docs/transitions.md: Add comprehensive documentation with examples
    - tests/test_probabilistic_transitions.py: 20 comprehensive tests
    - tests/examples/game_character_idle_machine.py: Working example
    
    All 348 existing tests pass + 20 new tests = 368 total passing tests
    bcorfman committed Oct 12, 2025
    Configuration menu
    Copy the full SHA
    7454818 View commit details
    Browse the repository at this point in the history
Loading