1.0.2 โ€ข Published 11 months ago

@medieval/martingale v1.0.2

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Martingale: the control is in your hands

๐Ÿคจ What is a fsm

A Finite State Machine (FSM) is a computational model used to design and represent the behavior of a system. It is composed of:

  • ๐Ÿšฅ States: Distinct modes or configurations that the system can be in. For example, a character in a game might have states like "idle", "walking", "running", etc.
  • ๐ŸŽฌ Transitions: Rules or conditions that determine when and how the system changes from one state to another. Transitions are typically triggered by events or conditions being met.
  • ๐Ÿ Initial State: The state the system starts in.
  • ๐ŸŽญ Actions: Operations or behaviors that occur when entering, exiting, or updating a state.

Key Characteristics of FSMs:

  • ๐Ÿคจ Deterministic: The next state is determined by the current state and input.
  • ๐Ÿงฉ Modular: States and transitions are encapsulated, making it easier to manage complex behaviors.
  • ๐Ÿง  Predictable: Provides a clear and visual representation of the system's behavior, aiding in debugging and understanding.

Applications:

FSMs are widely used in various fields such as game development, robotics, and software engineering for tasks like:

  • ๐Ÿงฉ Controlling game character behavior
  • ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Managing user interfaces
  • ๐Ÿ•ธ Protocol design in communications
  • ๐Ÿค– Workflow automation

๐Ÿ“˜ Usage

  1. create a fsm
const machine = new FSM();
  1. add a state
machine.addState('idle', {
	onEnter: () => console.log('hi'),
	onExit: () => {},
	onUpdate: () => {}
});
  1. switch states
machine.changeState('idle');

๐ŸŽฏ Conclusion

And here it is your fully functional fsm, that happens to work really well with Swordโš”๏ธ

License

MIT

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.0.2

1 year ago

0.0.1

1 year ago