![]() When translating a diagram such as this into code, switch statements and conditionals will only get us so far-as we add more states, the code complexity will balloon to a point that it will be difficult to read and maintain.īy comparison, the finite state design pattern represents each state as a class that an entity owns states are capable of polling their associated entity to decide if and when to transition it to a different state. A finite state machine diagram for a non-playable video game character. We can represent these states and their associated decision-making logic with a diagram like the following, where rectangles denote states, arrows denote state transitions, and text denotes the condition that needs to be met: Figure 1. ![]() An entity may also choose to remain in its current state until some condition is met. If and when this entity transitions from one state to another depends on a number of factors: the character’s health, whether an enemy is nearby, and so on. For example, a character in a video game may be in one of several states at any given point in time: idle, searching for an enemy, fighting an enemy, or fleeing combat. Entities are typically stateful, meaning they change their behavior based on their current state of being or mode of operation. ![]() In code, we’re often interested in modeling entities: agents or objects that occupy a given world or context.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |