Need help with %s
Posted: Mon May 14, 2012 3:01 pm
I'm working on a baseball sim, and have hit a wall right now.
What I'm trying to accomplish is getting the Contact% to real life standards. Which is 87% For a Pitch in the Strike Zone and 68% outside the strike zone.
I could easily do this, but in a way that player's attributes would have no effect, and therefore everybody is the same. The problem is though, the way I have this set up right now is normal for the best batters matched with the best pitchers. However once I start mixing up the batters and pitchers, these percentages go WAY off.
So basically what I'm asking for is some help getting these percentages back to normal, even with mismatches in the batters/pitchers. (Hope that made sense)
Here's the function, $pitch is just the type of pitch (Fastball, Curve Etc), $strike is the variable that indicates if the ball is in the strike zone (1) or not (0), $conpow and $confin are player variables for their contact attributes with around 45 being the highest and 20 being the lowest, $pitch_rating is the rating based on Speed/Movement of a pitch. the highest being around 75-80 and the lowest being around 50-55 at these player levels.
Any help is much much appreciated.
What I'm trying to accomplish is getting the Contact% to real life standards. Which is 87% For a Pitch in the Strike Zone and 68% outside the strike zone.
I could easily do this, but in a way that player's attributes would have no effect, and therefore everybody is the same. The problem is though, the way I have this set up right now is normal for the best batters matched with the best pitchers. However once I start mixing up the batters and pitchers, these percentages go WAY off.
So basically what I'm asking for is some help getting these percentages back to normal, even with mismatches in the batters/pitchers. (Hope that made sense)
Here's the function, $pitch is just the type of pitch (Fastball, Curve Etc), $strike is the variable that indicates if the ball is in the strike zone (1) or not (0), $conpow and $confin are player variables for their contact attributes with around 45 being the highest and 20 being the lowest, $pitch_rating is the rating based on Speed/Movement of a pitch. the highest being around 75-80 and the lowest being around 50-55 at these player levels.
Any help is much much appreciated.
Code: Select all
function Contact($pitch,$strike,$conpow,$confin,$pitch_rating){
switch($pitch){
case '1':
case '2':
case '3':
case '4':
$contact = $conpow;
break;
case '5':
$contact = $confin;
break;
}
$batter_roll = rand(25,40);
$contact = $contact + $batter_roll;
if ($strike == 1){ //Swung at Strike
if ( $contact >= $pitch_rating ){
$contact = 1;
}else{
$contact = 0;
}
}else{//Swung at Ball
if ( $contact >= $pitch_rating ){
$contact = 1;
}else{
$contact = 0;
}
}
return array($contact);
}