Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBrother Bob

Posted 02 April 2013 - 05:52 PM

It will pass the check for five of a kind, because you don't check if the three's are different from the two's. That may not be a problem if the rules allow for five of a kind to also be used for a full house, but keep that in mind.

 

You can also merge the two statements by checking if the first two are equal, the last two are equal, and finally if the middle one is equal to either the second of the other values. This allows for an easy check that the three's and the two's are different.

 

if(
    dice[0] == dice[1] && // first pair
    dice[3] == dice[4] && // last pair
    (dice[2] == dice[1] || dice[2] == dice[3]) && // middle must be equal to either pair
    dice[2] != dice[4] // exclude five of a kind where first and last pair are equal
) {
    ....
}

But I would try to code some general pattern matching method so that you don't have to hand code this at all.


#1Brother Bob

Posted 02 April 2013 - 05:52 PM

It will pass the check for five of a kind, because you don't check of the three's are different from the two's. That may not be a problem if the rules allow for five of a kind to also be used for a full house, but keep that in mind.

 

You can also merge the two statements by checking if the first two are equal, the last two are equal, and finally if the middle one is equal to either the second of the other values. This allows for an easy check that the three's and the two's are different.

if(
    dice[0] == dice[1] && // first pair
    dice[3] == dice[4] && // last pair
    (dice[2] == dice[1] || dice[2] == dice[3]) && // middle must be equal to either pair
    dice[2] != dice[4] // exclude five of a kind where first and last pair are equal
) {
    ....
}

But I would try to code some general pattern matching method so that you don't have to hand code this at all.


PARTNERS