Loop Logic
Posted: Thu Jan 16, 2014 3:10 pm
So I have an array that I'm looping through. I need to check to see if the array values match another value, and if so, check for one of three conditions. 2/3 of the conditions will have the runner go into the hole (The desired result), but the third will cause the check for that value to end, and the array loop should continue. This check has to come first, however. And after this check, and if the result is the 'closed' which will terminate that check, the array should be looped through normally. First look for one value from all of them, if that isn't true, look for another, and if that's not true, default back to the first value checked.
I've commented on where I have some problems. I think recursion may be necessary, but not sure.
Code: Select all
function running(){
$c = 0;
$visionCheck = rand(1,100); //Do a vision check, look for open gap if passed, go to play gap if its open, otherwise go to another gap. If failed, go to a random gap.
if(($oPlayer[23]+ $oPlayer[7])/2 >= $visionCheck){ //If the player passes the vision check
for($i=0; $i > $gap.length; $i++){ //Loops through the gaps
if($gap[$i] == $play[1]){ //Checks if the gap being looped through matches the designed play gap
if($gap[$i] == 'open'){ //If the gap that matches the play gap is open
//Go there
}elseif($gap[$i] == 'partial'){ //If the play gap is partially open
//Go there
}elseif($gap[$i] == 'closed'){ //If the play gap is closed
$c = 1; //End check for play-gap.
}
}
}elseif($gap[$i] != $play[1]){ //If the gap doesn't match the play-gap. The check for the play gap should ALWAYS come first
if($c == 1){ //I made $c = 1 to terminat the play-gap loop through. If $C is not 1, that means the runner has an open/partially open gap on the play gap and should go there
if($gap[$i] == 'open'){ //If the first gap is open, go there
//Go there
}elseif($gap[$i] == 'partial'){
//Look for others, then go there if nothing else. Best option is to have an open gap, but 2nd best is partial. This is part where I need help, how to check all of the opens first and then check for partials.
}elseif($gap[$i] == 'closed'){
//If every gap is closed, go to the play-gap. How do I make this happen?
}
}elseif($c == 0){ //If the play-gap has not been checked, add to $i to get to the playgap.
$i++;
}
}elseif(($oPlayer[23]+ $oPlayer[7])/2 < $visionCheck){ //If the player doesn't pass the vision check
$failedCheck = rand(1,$gap.length);
//go to failedCheck gap. Random gap.
}
}