I’ve been working with the A.I logic since my first Pong is build , I failed several times, and each time I’d thought I got it, most of the time is because I left out some calculation to be done, such as 2 bounces and 3 bounces will get the ball to the different location. I played with the game after each “successful”(I thought) A.I build, and I exploit the bug myself.
Being a dumb fixing certain number of bounce into the A.I calculation give me hell lots of bugs. So I put the calculation into a loop, will keep on calculating for new location until it calculation reached the end of the screen, where the A.I paddles located. I didn’t do research or refer to any sort of source for the A.I script, so I end up with some stupid but working pretty O.K logic.
Whenever player hit the ball, the direction and position of the ball is taking into account, based on the initial direction, the A.I will calculate the first location on the top/bottom screen where the ball will making the first bounce, after that A.I will continue to calculate the second bounce on the opposite based on the calculated position and direction, and do the calculation until it get to the A.I position.
After get the final position of the ball, by taking calculating the CPU’s paddle position and length, will move accordingly to the ball calculated position.
Of course, my version of Pong doesn’t have the ball bouncing math that depends on the place where the ball is hit on the paddle, so I don’t have the super weird angle of bouncing to put into the calculation of A.I move.
First time scripting the A.I move made me rethink how’s polish is the commercial game’s A.I, even a simple chess game also featuring a great A.I. Appreciate the great A.I in those game I’ve play and enjoy, the game wouldn’t be fun if there aren’t any A.I there, not to say stupid A.I or smart A.I