Fixed kart paths randomness issue (and probably many others) : don't continuously call srand, srand is made to be called ONCE only, repeatedly calling srand gives very poor randomisation
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7082 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
bff95a2035
commit
9f27068fb7
@ -44,7 +44,7 @@ AIBaseController::AIBaseController(Kart *kart,
|
||||
m_next_node_index.reserve(m_quad_graph->getNumNodes());
|
||||
m_successor_index.reserve(m_quad_graph->getNumNodes());
|
||||
std::vector<unsigned int> next;
|
||||
|
||||
|
||||
for(unsigned int i=0; i<m_quad_graph->getNumNodes(); i++)
|
||||
{
|
||||
next.clear();
|
||||
@ -52,12 +52,18 @@ AIBaseController::AIBaseController(Kart *kart,
|
||||
// For now pick one part on random, which is not adjusted during the
|
||||
// race. Long term statistics might be gathered to determine the
|
||||
// best way, potentially depending on race position etc.
|
||||
int indx = rand() % next.size();
|
||||
int r = rand();
|
||||
int indx = (int)(
|
||||
(r / (float)(RAND_MAX - 1)) * next.size()
|
||||
);
|
||||
|
||||
if (next.size() > 1)
|
||||
printf("Next road : %i mapped to %i -> %i\n", r, (int)next.size(), indx);
|
||||
m_successor_index.push_back(indx);
|
||||
m_next_node_index.push_back(next[indx]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const unsigned int look_ahead=10;
|
||||
// Now compute for each node in the graph the list of the next 'look_ahead'
|
||||
// graph nodes. This is the list of node that is tested in checkCrashes.
|
||||
|
@ -548,8 +548,6 @@ void NewAIController::handleRaceStart()
|
||||
//5% in medium and less than 1% of the karts in hard.
|
||||
if( m_time_till_start < 0.0f )
|
||||
{
|
||||
srand(( unsigned ) time( 0 ));
|
||||
|
||||
//Each kart starts at a different, random time, and the time is
|
||||
//smaller depending on the difficulty.
|
||||
m_time_till_start = ( float ) rand() / RAND_MAX * m_max_start_delay;
|
||||
|
@ -366,7 +366,6 @@ std::vector<std::string> KartPropertiesManager::getRandomKartList(int count,
|
||||
else
|
||||
i++;
|
||||
}
|
||||
std::srand((unsigned int)std::time(0));
|
||||
std::random_shuffle(karts.begin(), karts.end());
|
||||
|
||||
// Loop over all karts to fill till either all slots are filled, or
|
||||
|
@ -639,6 +639,8 @@ void cleanTuxKart()
|
||||
|
||||
int main(int argc, char *argv[] )
|
||||
{
|
||||
srand(( unsigned ) time( 0 ));
|
||||
|
||||
try {
|
||||
// Init the minimum managers so that user config exists, then
|
||||
// handle all command line options that do not need (or must
|
||||
|
@ -30,7 +30,6 @@ RandomGenerator::RandomGenerator()
|
||||
m_c = 12345;
|
||||
m_all_random_generators.push_back(this);
|
||||
m_random_value = 3141591;
|
||||
std::srand((unsigned int)std::time(0));
|
||||
} // RandomGenerator
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user