Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Pong AI...Dark Basic Pro

Author
Message
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 2nd May 2005 07:01
Well, don't I feel stupid. I decided just to fiddle around with a pong game and did everything by myself up to this point with pretty much no problems, until now. Right now I'm trying to create an AI system to control the player 2 paddle but not really sure where to begin. This is all 2D, not sure if that means much in terms of creating AI. I decided to post the code so anyone could see where I'm at.
Anyone got some ideas where I could start. I'm not really in search of someone to finish out the code, I just need some basics to get me heading in the right direction based upon what I have soo far. Any help would be kindly appreciated.
thinkdigital
20
Years of Service
User Offline
Joined: 18th Oct 2003
Location:
Posted: 2nd May 2005 11:27
Pong AI isn't too hard
So let's pretend that
A = the computer paddle's Y position
B = the ball's Y position

(X movement isn't really needed)

So then, just use the curvevalue function with A as the current location, B as the destinion, and a random value (but not just any random value - you might use something like (rnd(9)+1) * 0.1, which would return a number between 0.1 and 1.0) as the speed.



P.S. - You might have to tweak the range of that random value some, as I'm not quite sure how much does what in curvevalue

[b]eGeneric Works : Dark Basic Developer Website
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 2nd May 2005 11:40
Hey there thinkdigital. I completely understood what you tried to explain and it works good, however that concept doesn't seem to give the computer much of a randomness to screw up. How could I make the computer have more random movements though, just so it doesn't keep going right to the ball? What kind of things would I need to consider when writing an AI code for something like this?
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 2nd May 2005 19:18
Alright! I got something going I think. I did some hard thinking and started trying to figure things out for myself. Not the most amazing display of AI, but it's a really good start for me and best of all, I figured it all out for myself, which isn't saying much. But here's the new code for anyone who may care to look. It's all ready to copy and paste in DBPro with no media required. Soo far now I've got the compute rmoving around on the x and y axis and it tries to go into defensive mode when the ball makes it to a certain coordinate. May not be th ebest way to do it, but hey it works for me. Not bad for a not too smart noob eh?
dlefik 2008
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Spencerville, OH
Posted: 2nd May 2005 19:34
But I must also give credit to you thinkdigital for the curvevalue idea. It just took me a little time to put it into use.

Login to post a reply

Server time is: 2024-09-23 19:22:16
Your offset time is: 2024-09-23 19:22:16