Executing Logic n% of Time

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
so1odo1o
Posts: 32
Joined: Sat Apr 03, 2010 10:29 am

Executing Logic n% of Time

Post by so1odo1o »

I want to implement some sort of "random" feel into my current AI and I need some help on executing logic n% of time. For example, I want my to follow the best path 80% of the time otherwise choose a random node to follow 20% of the time.

Any advice on how to execute logic n% of time possibly using the device time in a clever way?

Code: Select all

if(){ } // enter if statement 80% using time possibly
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Well simple.

Code: Select all

srand(DeviceTime);
int percent = rand() % 100 + 1; //this generates a number between 1 and 100, without the +1 its just between 0 and 99

if (percent <= 80)
{
   //choose best pass
}
else
  //take random pass
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

what ya mean with damn close?
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I think he means he was close to answering before you did. :P
Post Reply