C Board  

Go Back   C Board > Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards > General AI Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-29-2007, 01:43 AM   #1
Registered User
 
Join Date: Dec 2006
Posts: 47
Pong Help

I Can't seem to figure out how to make the computer pong AI actually beatable.
Code:
	Computer.y=Ball.y;

		if(Computer.y>2.87){
			Computer.y=2.87f;
		}
		if(Computer.y<-3.62){
			Computer.y=-3.62f;
		}
Thats pretty much my AI right there. Only problem is that it never actually loses. I tried some other variations like if its lower or higher then move it up or down .01f; with some random movement but that doesn't help.

SO how do I balance out the AI?

Also if you need my entire coding just ask

Thanks for reading, hope to hear from you soon
Shadowwoelf is offline   Reply With Quote
Old 06-29-2007, 02:48 AM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
Well you're making it track the ball all the time, so obviously the bat will always meet the ball.

Suggestions
- limit the lateral acceleration of the computer bat.
- only track the ball position when the ball is on the computer side of the net (otherwise just move randomly). For more realism, pick a random point past the net to mimic reaction times.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 06-29-2007, 01:10 PM   #3
Registered User
 
Join Date: Dec 2006
Posts: 47
Thanks I just limited the lateral acceleration and I made it only follow the ball when its on a random point near its side of the field.

Code:
	if(Ball.x<=-((rand()%100+1)/1000)){
		if(Computer.y<Ball.y){
		Computer.y+=.005f;
		}
		if(Computer.y>Ball.y){
		Computer.y-=.005f;
		}
		if(Computer.y>2.87){
			Computer.y=2.87f;
		}
		if(Computer.y<-3.62){
			Computer.y=-3.62f;
		}
	}
Shadowwoelf is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Space Pong (Debug) Release Jeremy G Game Programming 6 10-02-2005 07:14 PM
The Story Of Pong (my game cookie) Jeremy G General Discussions 0 05-16-2005 11:14 PM
pong lambs4 Game Programming 2 06-02-2003 04:00 PM
Battle Pong DOlson Game Programming 13 01-08-2003 11:32 PM
God pong -update gamegod3001 A Brief History of Cprogramming.com 3 09-03-2001 09:16 PM


All times are GMT -6. The time now is 05:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22