ForumsProgramming ForumCreating bad Enemy A.I

8 4199
PrideRage
offline
PrideRage
148 posts
Nomad

Hello dear Community.
I would like to know how I make bad A.I for my Ping Pong game.
What that means?
It means, that the Enemy paddle should'n hit the ball always.
I've already tried a few variants of coding that, but it totally
messed up the paddle (it still hit the ball lol)
Thanks to everyone who can help me.
Greets, PrideRage

  • 8 Replies
rjbman
offline
rjbman
215 posts
Nomad

Why not just have it go back and forth at the same speed? Then if it hits the ball it does, otherwise it misses.

PrideRage
offline
PrideRage
148 posts
Nomad

Thanks rjbman for you answer.
It's so simple

rjbman
offline
rjbman
215 posts
Nomad

It's okay...it's amazing how some things pop out at you if you have a more distant perspective.

PixelSmash
offline
PixelSmash
566 posts
Nomad

Well, you could define a certain amount of randomness... sorta like accuracy. You want it to hit, but not all the time... this way you can build it with a predefinable amount of skill. The higher the skill, the less variation (over / undershoot) the enemy's bat will have

Good luck!

Diddy645
offline
Diddy645
23 posts
Nomad

I made a pong game where the paddle moved back and forth and it was REALLY LAME. People would always ask me why it was so easy and why the cpu didn't try at all. I suggest that you just make the cpu paddle slower that the ball's speed and then make the paddle always target the ball. That way, if the paddle is on one side of the screen and you hit to the other side of the screen, the enemy will be too slow to reach it in time.

BlueTreeFactory
offline
BlueTreeFactory
5 posts
Nomad

What I would do is make the paddle move towards the ball at a constant speed, like Diddy 645 says. In AS3:

var paddleSpeed:uint = 3;
addEventListener(Event.ENTER_FRAME, loop);

function loop (e:Event):void
{
if (ball.y < paddle.y)
{
paddle.y -= paddleSpeed;
}

if (ball.y > paddle.y)
{
paddle.y += paddleSpeed;
}
}

Hopefully this code makes sense!

leo99rules
offline
leo99rules
2,765 posts
Nomad

Set a low speed. The enemy can not go faster then that speed.

If you example hit one to the left and the cpu saves it, then you hit it to the right it will be too slow for it to get it on the other side.

Showing 1-7 of 8