I have recently began to experiment with an idea of making a basic movement AI for an enemy in a game. This AI would be used to control the movement of enemies in a "game engine" I am trying to develop (I am attempting to create a class-based type game using subprograms and what not). At this moment, I don't have any access to the calculator I have been programming on (left it at home and I am writing this in my study hall class), but my code is basic enough I can explain it in words.
Essentially, I am using a crude, unreliable, and slow method of moving the enemy towards a point I set (I will eventually adapt some code from one of my programs to allow the player to move), which randomly picks and integer between -1 and 1 until it slowly moves closer and closer to the target. That is, until it just passes the point, and keeps going, only it seems like it is trying to get back to the target, but moves on the x-axis for a while. I should note that the starting point of the "enemy" is (1,1), and the target is in the middle of the graph. I have set it so each pixel represents 1 unit, the bottom left corner being (0,0).
I am asking for some basic code that includes an algorithm that I could use to allow for more intelligent, quicker, and swift movement of the enemy. If anyone could help, that would be just fantastic.