Enemy AI is built from simple behaviors — patrol between two points, chase when within a detection radius, attack when close — organized by a finite state machine that keeps the enemy in exactly one clearly-defined state at a time.
1-B 2-A 3-B 4-B | 5 direction 6 attack 7 = elif dist > 300: state = "patrol" 8 = hand-placed waypoint graphs or simple wall-following heuristics, which solve most practical 2D pathing needs without full A* complexity 9 = an attack_timer/cooldown that counts down each frame, triggering the next attack once it reaches zero and then resetting | 10 = states: patrol (walks back and forth) → chase (triggered when distance < detection radius) → attack (triggered when distance < a close attack range) → back to chase if the player backs off past attack range but stays within detection range → back to patrol if distance exceeds detection radius entirely, meaning the player escaped and the enemy gives up