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 / Hi Guys more problems

Author
Message
Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 19th Oct 2004 03:05
Hi guys i have more problems, how would i implement an a.i function into my piong game wehen currently it can only do 2 real players - Thanks again for your time and aid

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 19th Oct 2004 07:40
Simple. AI is supposed mimic human behaviour. So you just need to work out what steps you perform to play Pong, then write code to do the same. So, for example, in pseudo code:

if ball = going_down
move paddle_down
else
move paddle_up
endif

etc.

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 19th Oct 2004 07:47
Well...that won't exactly work. You have to detect if the ball is above or below the center of the paddle, then move accordingly.

Xander Moser - Bolt Software - Firewall
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Oct 2004 10:41
Except, if you move the paddle as Philip suggests, the ball won't ever be above or below the paddle......it will just follow it. That's probably the most basic pong AI to start off with.

Once you've managed that, the next step, I would suggest, is to make the paddle return to the middle each time it has hit the ball, and once it gets to the middle you would then implement a 'move up if the ball is above/move down if the ball is below' type routine. The paddle obviously has a maximum speed, so sometimes it will make it, sometimes it won't.

As the levels get harder, you just increase the AI's paddle speed (and the ball speed too probably)

You probably want to figure it out for yourself, but you can use this code for reference if you like - it is a version of pong I wrote a couple of months ago which uses exactly this type of AI.




Renegade Andy
19
Years of Service
User Offline
Joined: 16th Oct 2004
Location: Scotland
Posted: 19th Oct 2004 22:44
Thanks a lot thats a superb start i shall study that code and rewrite my own version but i do see what your getting at though and i can relate to the if statements lol - could you take a look at my other forum on collision detection as well guys??
Thanks a lot again

Andy

NO KEYBOARD DETECED - PRESS F11 TO CONTINUE - FOOKED BIOS

Login to post a reply

Server time is: 2024-09-23 03:27:57
Your offset time is: 2024-09-23 03:27:57