title: How to structure enemy AI in JS?
body: <p>So I am working on adding entities in a game I am working on, I am wondering what the best way to structure enemy AI would be.</p>
  <p>I have an entity Object with all of the usual functions built, and currently I am controlling what the entity does with two functions</p>
  <pre><code>entity.prototype.runMeleeAI = function(){
  //makes the enemy make melee attacks
  }
  
  entity.prototype.runRangedAI = function(){
  //makes the enemy make ranged attacks
  }
  </code></pre>
  <p>I switch between which one of the functions runs with a property from whatever type of entity it is, so for example</p>
  <pre><code>const entityTypes = {
  &quot;slime&quot;:{ 
  &quot;AiType&quot;: &quot;ranged&quot;
  }}
  </code></pre>
  <p>However, I am wondering how I should manage it if I want an entity to have an AI that is different from those two types, should I just create a new function, eg</p>
  <pre><code>entity.prototype.runDashAi = function(){
  //do stuff
  }
  
  entity.prototype.runBossAI = function(){
  //do stuff
  }
  </code></pre>
  <p>Then if I wanted a special AI for an entity I could set it to be one of those</p>
  <p>Or is there a better way to structure this? I want to have lots of different AI types that will only be used for one type of entity</p>
  <p>Should I write the AI functions in separate files and then pass them on the entity object? or is there an entire way to do this i am not thinking of</p>