Excluding value of $num from "randomiser"
Posted: Tue Jul 04, 2006 5:50 am
Hi all,
I'm using the function below to set a game environment. It works, but is predictable - I would like it to be more random in terms of the mismatch between cards if $outcome = 0.
Can anyone suggest a better way to acheive this? It would be better to not see joker.swf each time $outcome = 0 and the King card has been set... it's obvious to the player that the outcome has been predetermined!
If I were to create an array of all possible cards, how would I exclude the value of $num from that array? I'm thinking that I could use the values that are left over in a function that would then go on to choose one of them in full knowledge that the movie chosen wouldnot match the card.
Thanks!
I'm using the function below to set a game environment. It works, but is predictable - I would like it to be more random in terms of the mismatch between cards if $outcome = 0.
Can anyone suggest a better way to acheive this? It would be better to not see joker.swf each time $outcome = 0 and the King card has been set... it's obvious to the player that the outcome has been predetermined!
If I were to create an array of all possible cards, how would I exclude the value of $num from that array? I'm thinking that I could use the values that are left over in a function that would then go on to choose one of them in full knowledge that the movie chosen wouldnot match the card.
Code: Select all
function set_Cards () {
// Create the correct set of cards to use for the game
// based on the value of $_SESSION['outcome']
// CREATES THE SESSION ENVIRONMENT FOR THE FLASH...
if ( $_SESSION['outcome'] == 0 ) {
// Aaaaaaaah, they're gonna lose...
$num = rand(1,3); // Generate a number to represent a card
$movie = $num+1; // The outcome will be mismatched cards
switch ( $num ) { // Defines the card that the player will "choose"
case 1 : $_SESSION['card'] = "jack"; break;
case 2 : $_SESSION['card'] = "queen"; break;
case 3 : $_SESSION['card'] = "king"; break;
}
switch ( $movie ) { // Defines the movie that the player will see
case 1 : $_SESSION['swf'] = "queen"; break;
case 2 : $_SESSION['swf'] = "king"; break;
case 3 : $_SESSION['swf'] = "jack"; break;
case 4 : $_SESSION['swf'] = "joker"; break; // This extra card caters for the fact that the result of
// the randomiser above may be "4", which causes problems
}
} // end of first "if" statement
if ( $_SESSION['outcome'] == 1 ) {
// Oooooooooh, they're gonna win!!
$num = rand(1,3);
$movie = $num;
switch ( $num ) { // Defines the card that the player will "choose"
case 1 : $_SESSION['card'] = "jack"; break;
case 2 : $_SESSION['card'] = "queen"; break;
case 3 : $_SESSION['card'] = "king"; break;
}
switch ( $movie ) { // Defines the movie that the player will see
case 1 : $_SESSION['swf'] = "jack"; break;
case 2 : $_SESSION['swf'] = "queen"; break;
case 3 : $_SESSION['swf'] = "king"; break;
}
} // end of second "if" statement
} // End of function set_Cards ()