Pong Help

This is a discussion on Pong Help within the General AI Programming forums, part of the Cprogramming.com and AIHorizon.com's Artificial Intelligence Boards category; 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; } ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    51

    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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    51
    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;
    		}
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

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

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