title: Trouble with AI in AS3
body: <p>I'm making a battleship simulator, in which you navigate a battleship to complete a certain objective whilst fending off enemy ships. Said enemy ships should have a form of primitive AI that would allow it to track the location of your ship and attempt to shoot at it.</p>
  
  <p>The issue I am having is that I'm not entirely sure how I can code for a group of enemy ships to hone in on the player's ship based on location. I have made multiple attempts to get the enemy ship to move, but to no avail.</p>
  
  <p>Attached is my most recent coding attempt for enemy ship movement (mvi_PBattleship is for the player ship and mvi_EBattleship is for the enemy ship):</p>
  
  <pre><code>    var EMoveTimer:Timer = new Timer(10);
      EMoveTimer.addEventListener("timer", EMove);
  
      function EMove(eventArgs:TimerEvent):void{
  
          EMoveTimer.start();
  
          if(((mvi_EBattleship.x + 31.7) &lt; mvi_PBattleship.x) &amp;&amp; (mvi_EBattleship.x &lt; mvi_PBattleship.x) &amp;&amp; ((mvi_EBattleship.y + 195.8) &lt; mvi_PBattleship.y) &amp;&amp; (mvi_EBattleship.y &lt; mvi_PBattleship.y)){
              mvi_EBattleship.x += 1;
              mvi_EBattleship.y += 1;
          }
  
          else if(((mvi_EBattleship.x + 31.7) &lt; mvi_PBattleship.x) &amp;&amp; (mvi_EBattleship.x &lt; mvi_PBattleship.x) &amp;&amp; (mvi_EBattleship.y &gt; (mvi_PBattleship.y + 195.8)) &amp;&amp; ((mvi_EBattleship + 195.8) &gt; (mvi_PBattleship.y + 195.8))){
              mvi_EBattleship.x += 1;
              mvi_EBattleship.y -= 1;
          }
  
          else if((mvi_EBattleship.x &gt; (mvi_PBattleship.x + 31.7)) &amp;&amp; ((mvi_EBattleship.x + 31.7) &gt; (mvi_PBattleship.x + 31.7)) &amp;&amp; ((mvi_EBattleship.y + 195.8) &lt; mvi_PBattleship.y) &amp;&amp; (mvi_EBattleship.y &lt; mvi_PBattleship.y)){
              mvi_EBattleship.x -= 1;
              mvi_EBattleship.y += 1;
          }
  
          else if((mvi_EBattleship.x &gt; (mvi_PBattleship.x + 31.7)) &amp;&amp; ((mvi_EBattleship.x + 31.7) &gt; (mvi_PBattleship.x + 31.7)) &amp;&amp; (mvi_EBattleship.y &gt; (mvi_PBattleship.y + 195.8)) &amp;&amp; ((mvi_EBattleship + 195.8) &gt; (mvi_PBattleship.y + 195.8))){
              mvi_EBattleship.x -= 1;
              mvi_EBattleship.y -= 1;
          }
  
          else if((mvi_EBattleship.x &gt; mvi_PBattleship.x) &amp;&amp; ((mvi_EBattleship.x + 31.7) &lt; (mvi_PBattleship.x + 31.7)) &amp;&amp; ((mvi_EBattleship.y + 195.8) &lt; mvi_PBattleship.y) &amp;&amp; (mvi_EBattleship.y &lt; mvi_PBattleship.y)){
              mvi_EBattleship.y += 1;
          }
  
          else if((mvi_EBattleship.x &gt; mvi_PBattleship.x) &amp;&amp; ((mvi_EBattleship.x + 31.7) &lt; (mvi_PBattleship.x + 31.7)) &amp;&amp; (mvi_EBattleship.y &gt; (mvi_PBattleship.y + 195.8)) &amp;&amp; ((mvi_EBattleship.y + 195.8) &gt; (mvi_PBattleship.y + 195.8))){
              mvi_EBattleship.y -= 1;
          }
  
          else if((mvi_EBattleship.y &gt; mvi_PBattleship.y) &amp;&amp; ((mvi_EBattleship.y + 195.8) &lt; (mvi_PBattleship.y + 195.8)) &amp;&amp; ((mvi_EBattleship.x + 31.7) &lt; mvi_PBattleship.x) &amp;&amp; (mvi_EBattleship.x &lt; mvi_PBattleship.x)){
              mvi_EBattleship.x += 1;
          }
  
          else if((mvi_EBattleship.y &gt; mvi_PBattleship.y) &amp;&amp; ((mvi_EBattleship.y + 195.8) &lt; (mvi_PBattleship.y + 195.8)) &amp;&amp; (mvi_EBattleship.x &gt; (mvi_PBattleship.x + 31.7)) &amp;&amp; ((mvi_EBattleship.x + 31.7) &gt; (mvi_PBattleship.x + 31.7))){
              mvi_EBattleship.x += 1;
          }
      }
  </code></pre>
  
  <p>So, my main questions are:</p>
  
  <p>1) What code should I be using to ensure that the enemy will track down the player?</p>
  
  <p>2) How would I make the enemy fire bullets at the player?</p>
  
  <p>3) Is there a way to track collisions between two enemy ships?</p>
  
  <p>Actual code would be much needed and appreciated, owing to the fact this project is expected to be near completion by tomorrow. Thank you very much for your help.</p>