DEMO AS DEVELOPED LOCATED AT: http://poker.mofiki.com I am currently still a noob at php and thanks to the Digital Point Community I have learned enough to begin a poker script which I will happily post here in its entirety when completed although help will be needed to complete it. Right now I am just working on a 5 card stud script and maybe we can elaborate and add features later. Here is the first problem that I have ran into due to my lack of PHP scripting knowledge: Every card has its own number value 1-52 (1 is Ace of Spades, 2 is Ace of hearts, etc.) The code below is how I have came up with figuring out what pair you have if any. The problems with this is 3 of a kind will be insanely long code due to the amount of possibilities if its written this way and if you have 2 pair it just displays that you have a pair then it displayes that you have a pair again. //saves your 5 cards into an array $handval = array($card1, $card2, $card3, $card4, $card5); //Check for 2 of a kind echo in_array(1, $handval) && in_array(2, $handval) ? 'Congrats! You have a Pair of Aces' : ''; echo in_array(1, $handval) && in_array(3, $handval) ? 'Congrats! You have a Pair of Aces' : ''; echo in_array(1, $handval) && in_array(4, $handval) ? 'Congrats! You have a Pair of Aces' : ''; echo in_array(2, $handval) && in_array(3, $handval) ? 'Congrats! You have a Pair of Aces' : ''; echo in_array(2, $handval) && in_array(4, $handval) ? 'Congrats! You have a Pair of Aces' : ''; echo in_array(3, $handval) && in_array(4, $handval) ? 'Congrats! You have a Pair of Aces' : ''; echo in_array(5, $handval) && in_array(6, $handval) ? 'Congrats! You have a Pair of 2s' : ''; echo in_array(5, $handval) && in_array(7, $handval) ? 'Congrats! You have a Pair of 2s' : ''; echo in_array(5, $handval) && in_array(8, $handval) ? 'Congrats! You have a Pair of 2s' : ''; echo in_array(6, $handval) && in_array(7, $handval) ? 'Congrats! You have a Pair of 2s' : ''; echo in_array(6, $handval) && in_array(8, $handval) ? 'Congrats! You have a Pair of 2s' : ''; echo in_array(7, $handval) && in_array(8, $handval) ? 'Congrats! You have a Pair of 2s' : ''; echo in_array(9, $handval) && in_array(10, $handval) ? 'Congrats! You have a Pair of 3s' : ''; echo in_array(9, $handval) && in_array(11, $handval) ? 'Congrats! You have a Pair of 3s' : ''; echo in_array(9, $handval) && in_array(12, $handval) ? 'Congrats! You have a Pair of 3s' : ''; echo in_array(10, $handval) && in_array(11, $handval) ? 'Congrats! You have a Pair of 3s' : ''; echo in_array(10, $handval) && in_array(12, $handval) ? 'Congrats! You have a Pair of 3s' : ''; echo in_array(11, $handval) && in_array(12, $handval) ? 'Congrats! You have a Pair of 3s' : ''; echo in_array(13, $handval) && in_array(14, $handval) ? 'Congrats! You have a Pair of 4s' : ''; echo in_array(13, $handval) && in_array(15, $handval) ? 'Congrats! You have a Pair of 4s' : ''; echo in_array(13, $handval) && in_array(16, $handval) ? 'Congrats! You have a Pair of 4s' : ''; echo in_array(14, $handval) && in_array(15, $handval) ? 'Congrats! You have a Pair of 4s' : ''; echo in_array(14, $handval) && in_array(16, $handval) ? 'Congrats! You have a Pair of 4s' : ''; echo in_array(15, $handval) && in_array(16, $handval) ? 'Congrats! You have a Pair of 4s' : ''; echo in_array(17, $handval) && in_array(18, $handval) ? 'Congrats! You have a Pair of 5s' : ''; echo in_array(17, $handval) && in_array(19, $handval) ? 'Congrats! You have a Pair of 5s' : ''; echo in_array(17, $handval) && in_array(20, $handval) ? 'Congrats! You have a Pair of 5s' : ''; echo in_array(18, $handval) && in_array(19, $handval) ? 'Congrats! You have a Pair of 5s' : ''; echo in_array(18, $handval) && in_array(20, $handval) ? 'Congrats! You have a Pair of 5s' : ''; echo in_array(19, $handval) && in_array(20, $handval) ? 'Congrats! You have a Pair of 5s' : ''; echo in_array(21, $handval) && in_array(22, $handval) ? 'Congrats! You have a Pair of 6s' : ''; echo in_array(21, $handval) && in_array(23, $handval) ? 'Congrats! You have a Pair of 6s' : ''; echo in_array(21, $handval) && in_array(24, $handval) ? 'Congrats! You have a Pair of 6s' : ''; echo in_array(22, $handval) && in_array(23, $handval) ? 'Congrats! You have a Pair of 6s' : ''; echo in_array(22, $handval) && in_array(24, $handval) ? 'Congrats! You have a Pair of 6s' : ''; echo in_array(23, $handval) && in_array(24, $handval) ? 'Congrats! You have a Pair of 6s' : ''; echo in_array(25, $handval) && in_array(26, $handval) ? 'Congrats! You have a Pair of 7s' : ''; echo in_array(25, $handval) && in_array(27, $handval) ? 'Congrats! You have a Pair of 7s' : ''; echo in_array(25, $handval) && in_array(28, $handval) ? 'Congrats! You have a Pair of 7s' : ''; echo in_array(26, $handval) && in_array(27, $handval) ? 'Congrats! You have a Pair of 7s' : ''; echo in_array(26, $handval) && in_array(28, $handval) ? 'Congrats! You have a Pair of 7s' : ''; echo in_array(27, $handval) && in_array(28, $handval) ? 'Congrats! You have a Pair of 7s' : ''; echo in_array(29, $handval) && in_array(30, $handval) ? 'Congrats! You have a Pair of 8s' : ''; echo in_array(29, $handval) && in_array(31, $handval) ? 'Congrats! You have a Pair of 8s' : ''; echo in_array(29, $handval) && in_array(32, $handval) ? 'Congrats! You have a Pair of 8s' : ''; echo in_array(30, $handval) && in_array(31, $handval) ? 'Congrats! You have a Pair of 8s' : ''; echo in_array(30, $handval) && in_array(32, $handval) ? 'Congrats! You have a Pair of 8s' : ''; echo in_array(31, $handval) && in_array(32, $handval) ? 'Congrats! You have a Pair of 8s' : ''; echo in_array(33, $handval) && in_array(34, $handval) ? 'Congrats! You have a Pair of 9s' : ''; echo in_array(33, $handval) && in_array(35, $handval) ? 'Congrats! You have a Pair of 9s' : ''; echo in_array(33, $handval) && in_array(36, $handval) ? 'Congrats! You have a Pair of 9s' : ''; echo in_array(34, $handval) && in_array(35, $handval) ? 'Congrats! You have a Pair of 9s' : ''; echo in_array(34, $handval) && in_array(36, $handval) ? 'Congrats! You have a Pair of 9s' : ''; echo in_array(35, $handval) && in_array(36, $handval) ? 'Congrats! You have a Pair of 9s' : ''; echo in_array(37, $handval) && in_array(38, $handval) ? 'Congrats! You have a Pair of 10s' : ''; echo in_array(37, $handval) && in_array(39, $handval) ? 'Congrats! You have a Pair of 10s' : ''; echo in_array(37, $handval) && in_array(40, $handval) ? 'Congrats! You have a Pair of 10s' : ''; echo in_array(38, $handval) && in_array(39, $handval) ? 'Congrats! You have a Pair of 10s' : ''; echo in_array(38, $handval) && in_array(40, $handval) ? 'Congrats! You have a Pair of 10s' : ''; echo in_array(39, $handval) && in_array(40, $handval) ? 'Congrats! You have a Pair of 10s' : ''; echo in_array(41, $handval) && in_array(42, $handval) ? 'Congrats! You have a Pair of Jacks' : ''; echo in_array(41, $handval) && in_array(43, $handval) ? 'Congrats! You have a Pair of Jacks' : ''; echo in_array(41, $handval) && in_array(44, $handval) ? 'Congrats! You have a Pair of Jacks' : ''; echo in_array(42, $handval) && in_array(43, $handval) ? 'Congrats! You have a Pair of Jacks' : ''; echo in_array(42, $handval) && in_array(44, $handval) ? 'Congrats! You have a Pair of Jacks' : ''; echo in_array(43, $handval) && in_array(44, $handval) ? 'Congrats! You have a Pair of Jacks' : ''; echo in_array(45, $handval) && in_array(46, $handval) ? 'Congrats! You have a Pair of Queens' : ''; echo in_array(45, $handval) && in_array(47, $handval) ? 'Congrats! You have a Pair of Queens' : ''; echo in_array(45, $handval) && in_array(48, $handval) ? 'Congrats! You have a Pair of Queens' : ''; echo in_array(46, $handval) && in_array(47, $handval) ? 'Congrats! You have a Pair of Queens' : ''; echo in_array(46, $handval) && in_array(48, $handval) ? 'Congrats! You have a Pair of Queens' : ''; echo in_array(47, $handval) && in_array(48, $handval) ? 'Congrats! You have a Pair of Queens' : ''; echo in_array(49, $handval) && in_array(50, $handval) ? 'Congrats! You have a Pair of Kings' : ''; echo in_array(49, $handval) && in_array(51, $handval) ? 'Congrats! You have a Pair of Kings' : ''; echo in_array(49, $handval) && in_array(52, $handval) ? 'Congrats! You have a Pair of Kings' : ''; echo in_array(50, $handval) && in_array(51, $handval) ? 'Congrats! You have a Pair of Kings' : ''; echo in_array(50, $handval) && in_array(52, $handval) ? 'Congrats! You have a Pair of Kings' : ''; echo in_array(51, $handval) && in_array(52, $handval) ? 'Congrats! You have a Pair of Kings' : ''; Code (markup): Any ideas on shortening the code and/or when it finds something true it stops looking? Any help would be great and since I am a noob descriptions would also be nice as to why you did what you did. Thank you and I will have a demo up soon so that you can actually see how it works so far and the layout/problems/etc.
Well i'm more or less reinventing the code to learn it. I would like to understand why the poker scripts do what they do in certain areas along with learning more about arrays,functions, etc. The Demo that will include any updates as I learn how to do it is located at http://poker.mofiki.com
This is kindof what i'm doing only with arrays instead of if then's although the major issue with either of these ways is that it will take thousands of lines of code writting it that way because of the number of possibilities. There are 78 different combinations just for pairs alone, straights would take hundreds of lines alone this way. HERE IS A MORE SPECIFIC QUESTION THAT WILL HELP ALOT ALSO SINCE ARRAYS SEEM TO USE THE LEAST AMOUNT OF CODE BECAUSE IT CAN LOOK FOR MULTIPLE NUMBERS IN ANY ORDER OR COMBINATION. If I have the following code in place how do I tell it to stop looking if its true with the least amount of code? echo in_array(1, $handval) && in_array(2, $handval) ? 'True' : 'False'; echo in_array(2, $handval) && in_array(3, $handval) ? 'True' : 'False'; echo in_array(1, $handval) && in_array(3, $handval) ? 'True' : 'False'; If the numbers displayed are 1, 2, 4, 3, 5 then it will display True 3 times but it needs to stop at the first true so when it realizes that 1 and 2 are there it doesn't even look at the second 2 lines. Is there something that can be added to the one line or must if else be used for every line?
I fixed the above problem with: if (in_array(1, $handval, true)) { echo "Congrats! Your High Card is an Ace of Spades"; $pointgain = 1; $handval = array(53, 54, 55, 56, 57); } Code (markup): Next Issue is how can you do: rand(1,52) //but exclude numbers Example: $card1 = rand(1,52) $card2 = rand(1,52) excluding $card1?
Try using this function to find a random number excluding a defined number: http://www.fullposter.com/snippets.php?snippet=39 function rands($from=0, $to=0, $excluded=array()){ if(is_string($excluded)){ $excluded=preg_replace('/\s{2,}/', ' ', trim($excluded)); $excluded=explode(' ', $excluded); };/*bonus feature*/ if(!is_array($excluded)){$excluded=array();}; $excluded=array_unique($excluded);//important! $from=abs($from); $to=abs($to); if( $to-$from <= sizeof($excluded)-1 ){$excluded=array();/*or might stall*/}; $excluded=array_flip($excluded); while(true){ $r=mt_rand($from, $to); if(!isset($excluded[$r])){return $r;}; }; PHP: Also, when getting no points, it just says "You gained point(s)" You might also want to remove that (s) from the string. So if you get 1 point, it will say "You gained 1 point", and if more/less: "You gained 2 points".
How would I pull the random number from this function? do I just call the function and it will give me the number or must I do something else?
You use the function like you would use rand You just have to put the numbers you DO NOT want to be shown in an array in the last parametre. So, if you want from 0 to 15, and do NOT want the number 10 and 5 to be shown, you use it like: rands(0,15,array(10,5)); You can put it into a variable, put it in an if statement or just echo it: if(rands(0,15,array(10,5)) == 5){echo 'Wohoo the random number was 5';} $random = rands(0,15,array(10,5)); echo rands(0,15,array(10,5));
That's oddly long... <?php function rands( $min, $max, array $exceptions = array() ) { $exceptions = array_unique( $exceptions ); do $rand = rand( $min, $max ); while ( in_array($rand, $exceptions) ); return $rand; } echo rands(1, 5, array(1, 2, 3)); /* 4 or 5 */ PHP: