Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //This function uses a bubble counter1 to arrange the number2 numbers highest to lowest
- int arrange ( int arraydim [] ){
- int counter2, counter1;
- int change = arraydim [0];
- for (counter1 = 0; counter1 < 4; ++counter1 ){
- for (counter2 =0; counter2 < (4 - counter1); ++counter2){
- if (arraydim [counter2] > arraydim [counter2 + 1] ){
- change = arraydim [counter2 + 1];
- arraydim [counter2 +1] = arraydim [counter2];
- arraydim [counter2] = change;
- }
- }
- }
- }
- int Threeofakind ( int number1, int number2 [], int * const checkthreekinds)
- {
- int counter1, counter2, duplicateCounter1 = 0;
- //Uses a nested loop to check every element of the arraydim against the others to find if there are 3 of the same number
- for ( counter2 = 0; counter2 < number1; counter2++ ){
- if ( duplicateCounter1 >= 3 )
- { break; }
- duplicateCounter1 = 0;
- for ( counter1 = 0; counter1 < number1; counter1++ ){
- if ( number2 [counter1] == number2 [counter2] )
- { duplicateCounter1++;}
- }
- }
- if ( duplicateCounter1 >= 3 ){
- duplicateCounter1 = ((((number2 [0] + number2 [1] ) + number2 [2] ) + number2 [3] ) + number2 [4] );
- //Here is the check I mentioned earlier which stops the function scoring twice.
- *checkthreekinds= 1;
- }else{
- duplicateCounter1 = 0;
- }return duplicateCounter1;
- }
- int fullHouse ( int number2 [], int * const Checkfullhouse ){
- int ret;
- //Due to the size of the number2 arraydim there are only 2 conditions where a full house can score, this checks for both of those
- if ( number2 [0] == number2 [1] && number2 [0] == number2 [2] && number2 [3] == number2 [4] ){
- ret = 40;
- *Checkfullhouse =1;
- }else if ( number2 [0] == number2 [1] && number2 [2] == number2 [3] && number2 [3] == number2 [4]){
- ret = 40;
- *Checkfullhouse =1;
- }else{
- ret = 0;
- }return ret;
- }
- int LongStraight ( int number2 [], int * const CheckLongStraight){
- int ret;
- //There is only one way to score a long staright, this checks for that, the number2s are ordered so its easy to check.
- if ( number2 [1] == ( number2 [0] + 1) && number2 [2] == ( number2 [1] +1) && number2 [3] == ( number2 [2] + 1) && number2 [4] == ( number2 [3] + 1 )){
- ret = 35;
- *CheckLongStraight= 1;
- }else{
- ret = 0;
- }return ret;
- }
- int ShortStraight ( int number2 [], int * const CheckShortStraight){
- int ret, counter1, add1 = 0;
- //Uses if statements to check all the times a short straight can be achieved.
- //It may have been easier to uses loops for this, however I couldn't figure it out.
- if ( (number2 [1] == ( number2 [0] +1 )) || ( number2 [2] == ( number2 [0] +1))){
- add1++;
- }if ( (number2 [2] == ( number2 [0] + 2 )) && (number2 [1] == ( number2 [0] +1 ))){
- add1++;
- }if ( (number2 [3] == ( number2 [0] + 3 )) && ( number2 [2] == ( number2 [0] +2))){
- add1++;
- }if (add1 == 3){
- *CheckShortStraight= 1;
- return 25;
- }else if (add1 < 3 ){
- add1 = 0;
- }if (( number2 [2] == ( number2 [1] + 1 )) && ( number2 [3] == ( number2 [2] + 1 )) && ( number2 [4] == ( number2 [3] + 1 ))){
- *CheckShortStraight= 1;
- return 25;
- }else{
- return 0;
- }
- }
- int FiveOfAKind ( int number2 [], int * const CheckFivesKind ){
- int ret;
- //There is only one time 5 of a kind can be scored, this checks for that
- if ( (number2 [0] == number2 [1]) && (number2 [0] == number2 [2]) && (number2 [0] == number2 [3]) && (number2 [0] == number2 [4]) ){
- ret = 50;
- *CheckFivesKind = 1;
- }else{
- ret = 0;
- } return ret;
- }
- int FourOfAKind ( int number2 [], int * const CheckFoursKind )
- {
- int counter1, counter2, duplicateCounter1 = 0;
- /*Uses a nested for loop exactly the same way as the 3 of a kind function,
- just with the requirement to return a non-zero interger when 4 of the same numbers
- are counted rather than 3*/
- for ( counter2 = 0; counter2 < 5; counter2++ ){
- if ( duplicateCounter1 >= 4 )
- { break; }
- duplicateCounter1 = 0;
- for ( counter1 = 0; counter1 < 5; counter1++ ){
- if ( number2 [counter1] == number2 [counter2] )
- { duplicateCounter1++;}
- }
- }
- if ( duplicateCounter1 >= 4 ){
- duplicateCounter1 = ((((number2 [0] + number2 [1] ) + number2 [2] ) + number2 [3] ) + number2 [4] );
- *CheckFoursKind = 1;
- }else{
- duplicateCounter1 = 0;
- }return duplicateCounter1;
- }
- int Chance ( int number2 [], int * const CheckChance ){
- int ret;
- *CheckChance = 1;
- ret = (((( number2 [0] + number2 [1] ) + number2 [2] ) + number2 [3] ) + number2 [4] );
- return ret;
- }
- int twos ( int number2 [], int * const Check, int num ){
- int ret, counter1,add1;
- /*This function scores all of the catagories from 1 to 6, hence the
- check in nonspecific and can be refering to any of the checks from
- those 6 catagories, the rest of this one is pretty self explanitory*/
- for ( counter1 = 0; counter1 < 5; counter1++ ){
- if ( number2 [counter1] == num ){
- add1++;
- }
- }if (add1 >= 1 ){
- *Check = 1;
- }else {
- num = 0;
- }ret = ( num *add1);
- return ret;
- }
- int main( void )
- {
- int counter1, counter2, checkthreeskinds =0, add =0, Checkfullhouse = 0, CheckLongStraight =0, CheckShortStraight = 0, CheckFives = 0, CheckFours = 0, CheckChance = 0, CheckOnes = 0,
- CheckTwos = 0, CheckThrees2 = 0, CheckFours2 =0, CheckFives2 =0, CheckSixes = 0 ;
- int inputNumbers[13][ 5 ] = { '\0' };
- for ( counter2 = 0; counter2 < 13; counter2++){
- for ( counter1 = 0; counter1 < 5; counter1++ ){
- scanf( "%d", &inputNumbers[ counter2 ][ counter1 ] );
- }
- }for ( counter1 = 0; counter1 < 13; counter1++){
- for ( counter2 = 0; counter2 < 5; counter2++ ){
- if ( inputNumbers [counter1] [counter2] < 1 || inputNumbers [counter1] [counter2] > 6 ){
- printf ( "Dice set %d, die %d is %d, which is not a six sided dice value, please change this and re-run.\n If the value of incorrect die is 0 it may be that you have not entered enough values or you have enter a letter or symbol.\n Please make sure to enter 13 sets of 5 numbers 1 to 6.\n ", ( counter1 + 1 ), ( counter2 + 1 ), inputNumbers [counter1] [counter2] );
- return 0;
- }
- }
- }for (counter2 = 0; counter2 < 13; counter2++ ){
- arrange( inputNumbers [counter2] );
- }
- for (counter2 = 0; counter2 < 13; counter2++ ){
- counter1 = 0;
- switch ( counter1 ){
- case (0):
- if ( CheckFives != 1){
- add += FiveOfAKind ( inputNumbers [counter2], &CheckFives );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckFives == 1 )
- {break;}
- else{
- counter1++;}
- }case (1):
- if ( Checkfullhouse != 1 ){
- add += fullHouse ( inputNumbers [counter2], &Checkfullhouse );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( Checkfullhouse == 1)
- {break;}
- else{
- counter1++;}
- }case (2):
- if ( CheckLongStraight !=1 )
- { add += LongStraight ( inputNumbers [counter2], &CheckLongStraight );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckLongStraight == 1 )
- {break;}
- else{
- counter1++;}
- }case (3):
- if ( CheckShortStraight != 1 ){
- add += ShortStraight ( inputNumbers [counter2], &CheckShortStraight );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckShortStraight == 1 )
- {break;}
- else{
- counter1++;}
- }case (4):
- if ( CheckFours != 1){
- add += FourOfAKind ( inputNumbers [counter2], &CheckFours );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckFours == 1 )
- {break;}
- else{
- counter1++;}
- }case (5):
- if ( checkthreeskinds != 1 ){
- add += Threeofakind( 5, inputNumbers [counter2], &checkthreeskinds );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if (checkthreeskinds == 1)
- {break;}
- else{
- counter1++;}
- }case (6):
- if ( CheckChance != 1 ){
- add += Chance ( inputNumbers [counter2], &CheckChance );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckChance == 1 )
- {break;
- counter1++;}
- }case (7):
- if ( CheckOnes != 1 ){
- add += twos ( inputNumbers [counter2], &CheckOnes, 1 );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckOnes == 1 )
- {break;}
- else{
- counter1++;}
- }case (8):
- if ( CheckTwos != 1 ){
- add += twos ( inputNumbers [counter2], &CheckTwos, 2 );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckTwos == 1 )
- {break;}
- else{
- counter1++;}
- }case (9):
- if ( CheckThrees2 != 1 ){
- add += twos ( inputNumbers [counter2], &CheckThrees2, 3 );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckThrees2 == 1 )
- {break;}
- else{
- counter1++;}
- }case (10):
- if ( CheckFours2 != 1 ){
- add += twos ( inputNumbers [counter2], &CheckFours2, 4 );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckFours2 == 1 )
- {break;}
- else{
- counter1++;}
- }case (11):
- if ( CheckFives2 != 1 ){
- add += twos ( inputNumbers [counter2], &CheckFives2, 5 );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckFives2 == 1 )
- {break;}
- else{
- counter1++;}
- }case (12):
- if ( CheckSixes != 1 ){
- add += twos ( inputNumbers [counter2], &CheckSixes, 6 );
- if ( counter1 == 5 && add >= 63 ){
- add += 35;
- }if ( CheckSixes == 1 )
- {break;}
- else{
- counter1++;}
- }
- }
- }printf ( "The score is %d\n", add );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement