FYI, one of the most well-known books about writing game entity behavior is literally called "Programming Game AI by Example." (published in 2004)
https://www.amazon.com/Programming-Example-Wordware-Develope...
https://www.amazon.com/Programming-Example-Wordware-Develope...