AV1611 Posted April 17, 2006 Share Posted April 17, 2006 As a leaning exercise, I have written a game of Yatzee, the Dice game with 5 dice... But I am stuck...I have to write the validation routines so if, for example, I role 5 dice, and the following is true:D1=5 D2=1 D3=1 D4=4 D5=3Now, I want to take the "Ones" catagory, so I can see that I have two "ones", for a score of 2 in the ones catagory.Now, in PHP, the way I am doing it, is every catagory is set with a session variable that equals "Available" so I now present a radio button, and have the script compute the score for each "Available" catagory, so the player only has to select the radio button and press the submit button, then they go to their next turn. I need to write the validation for each catagory, so this much is true:If ($_SESSION['ones']=='AVAILABLE'){ // show the radio button then <--- I have this part already // compute the score to enter if the person selects this catagory}I suppose I have to to a VERY long (30+?) set of clauses, but there must be an easier way... AND I have to do the clauses for each catagory...Any suggestions, or am I on the right track, and just have to write all the clauses? Quote Link to comment https://forums.phpfreaks.com/topic/7597-learning-exercise/ Share on other sites More sharing options...
AV1611 Posted April 17, 2006 Author Share Posted April 17, 2006 Well, I have figured out how to do the following:1's2's3's4's5's6'sthree of a kindfour of a kindscratchyatzeeI still need to do small straight and large straight...Here is how I did the others, but I don't know how to verify the small or large straight...I know this is part of the solution:[code]<?php$straight=array($D1,$D2,$D3,$D4,$D5);sort($straight);echo $straight[0];echo $straight[1];echo $straight[2];echo $straight[3];echo $straight[4];?>[/code]Someone Please help!How do you prove is 4 out of 5 numbers are sequential???Thanks[code]<?phpif($ttt=='AVAILABLE'){if(($D1==$D2 && $D1==$D3)||($D1==$D2 && $D1==$D4)||($D1==$D2 && $D1==$D5)||($D1==$D3 && $D1==$D4)||($D1==$D3 && $D1==$D5)||($D1==$D4 && $D1==$D5)||($D2==$D3 && $D2==$D4)||($D2==$D3 && $D2==$D5)||($D2==$D4 && $D2==$D5)||($D3==$D4 && $D3==$D5)){$ttttotal=$D1+$D2+$D3+$D4+$D5;echo $ttttotal;}else{echo 0;}}else {echo $ttt;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/7597-learning-exercise/#findComment-27842 Share on other sites More sharing options...
AV1611 Posted April 17, 2006 Author Share Posted April 17, 2006 Thanks for all the help...Mark this one solved...[code]<?phpif($ss=='AVAILABLE'){$s=array($D1,$D2,$D3,$D4,$D5);sort($s);if(($s[0]==$s[1]-1 && $s[0]==$s[2]-2 && $s[0]==$s[3]-3)||($s[1]==$s[2]-2 && $s[1]==$s[3]-3 && $s[1]==$s[4]-4)){$sstotal=35;echo $sstotal;}}else{echo $ss;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/7597-learning-exercise/#findComment-27853 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.