Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 11-11-2011, 03:45 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Began the equation by assuming the fact that the lot was circular was essentially an extra detail that mattered very little to the eventual outcome since the circumference can basically be regarded as a circle laid out flat. So assuming a 100 unit long straight line, and a gap of 1 unit between the cars as the highest gap (rather than say 1.99999 repeated which would lead to 25 cars instead of whatever limit you said later), came up with this code that would linearly determine how many cars would fit.

PHP Code:
function onCreated(){
  
temp.val1 findMin(1002);
  
temp.val2 findMax(1002);
  echo(
val1);
  echo(
val2);
  for(
temp.0100i++){
    
temp.val3 += findRand(1002);
  }
  echo(
val3/100);
}

function 
findRand(ni){
  
temp.space 0;
  
temp.gap random(12);
  
temp.isgap false;
  
temp.cars 0;
  while(
space n){
    
isgap = !isgap;
    if(
isgap){
      
space += gap;
    }
    else{
      
space += i;
      
cars++;
    }
  }
  return 
cars;
}

function 
findMin(ni){
  
temp.space 0;
  
temp.gap 1;
  
temp.isgap false;
  
temp.cars 0;
  while(
space n){
    
isgap = !isgap;
    if(
isgap){
      
space += gap;
    }
    else{
      
space += i;
      
cars++;
    }
  }
  return 
cars;
}

function 
findMax(ni){
  return 
int(n/i);

Output:
PHP Code:
33
50
40.87 

The results if plotted for each random iteration would wind up being a sort of diamond leading around the value of min + max / 2, causing the average to approach that value.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:28 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.