Re-wrote the AI program

Changed the if loops and whatnot.