This site requires JavaScript, please enable it in your browser!
Greenfoot back
Samummy1
Samummy1 wrote ...

2018/12/21

Stalling an AI

Samummy1 Samummy1

2018/12/21

#
I have code for an AI that I am creating for pong. I am trying to get it so that it will have to wait based on a small probability. If anyone has code or an idea on how to program this please reply
danpost danpost

2018/12/21

#
Samummy1 wrote...
I have code for an AI that I am creating for pong. I am trying to get it so that it will have to wait based on a small probability. If anyone has code or an idea on how to program this please reply
Add a timer field (outside any method):
private int waitTimer;
Give a wait time (in act cycles) to waitTimer on small chance (in act or in a method called from act):
if (Greenfoot.getRandomNumber(1000) == 0) waitTimer = 20;
Do normal AI stuff only if waitTimer is zero; otherwise, do nothing more than chalk time:
if (waitTimer > 0 && --waitTimer != 0) return;
Normal AI code goes after this last given line.
You need to login to post a reply.