i dont really understand what a hash is and I would like to keep this game simple. By the way this is for a game of yahtzee not poker
In java, that'd be in java.util.Hashtable
i dont really understand what a hash is and I would like to keep this game simple. By the way this is for a game of yahtzee not poker
In java, that'd be in java.util.Hashtable
With Yahtzee you might be better having an array of size 6 and store a count of how many dice are rolled of each number. That makes checking the combinations and scoring them really easy.
Can't you still have a full house and 2 pairs in Yahtzee too?
Ten Thousand/Farkle/Dix Mille is a much better dice game though I reckon, especially with the 4 or more 2's = disaster lose all your banked points rule.
I think this is the easiest way if you have no need to sort:
int same=0;
for(int i=0;i<4;++i)
for(int j=i+1;j<5;++j)
if(a == a[j])
same++;
same = 1 is a pair
same = 3 is a three of a kind
same = 6 is a quad
same = 10 is 5 of a kind
added:
same = 2 is two pair
same = 4 is a full house
Yeah that's what I was suggesting with the array of 6 entries, use it as a histogram.
I thought a small straight was 1-2-3-4-5 and a large straight was 2-3-4-5-6?
Just for fun, a (beginner) Haskell implementation:
unique :: (Eq a) => [a] -> [a]
unique [] = []
unique (x:xs) = x : unique (filter (\y -> not (x==y)) xs)
nOcurrences :: (Eq a) => a -> [a] -> Int
nOcurrences elem list = length (filter (==elem) list)
isThreeKind :: (Eq a) => [a] -> Bool
isThreeKind list = elem 3 [nOcurrences i list | i <- (unique list)]
You could parametrize the 3 number in "isThreeKind" function and have a "fourKind", a "fiveKind", or whatever...
Cheers.
Not according to wikipedia: http://en.wikipedia.org/wiki/YahtzeeYeah that's what I was suggesting with the array of 6 entries, use it as a histogram.
I thought a small straight was 1-2-3-4-5 and a large straight was 2-3-4-5-6?
Looks like I've been playing a weird Yacht/Yahtzee hybrid then ;) I also thought Yacht was the same game as Yahtzee, you learn something new every day ;)
Since I mentioned 10,000 someone should do a physics based simulation of the remarkably similar game "Pass the Pigs" http://en.wikipedia.org/wiki/Pass_the_pigs
EDIT: And I've never heard of the Kissin' Bacon (both snouts touching) rule before. It's not in my ruleset!
struct Classification {
bool is_three_of_a_kind;
bool is_four_of_a_kind;
bool is_full_house;
bool is_small_straight;
bool is_large_straight;
bool is_yahtzee;
bool is_chance;
Classification(int *dice) {
int sum = 0;
int types = 0;
for (int i=0; i<5; ++i) {
sum += 1 << ((dice-1)*3);
types |= 1 << (dice-1);
}
int n_types = __builtin_popcount(types); // This only works in gcc. You can find other ways of counting set bits for other compilers.
is_three_of_a_kind = (((sum + 0111111) & 0444444) != 0);
is_four_of_a_kind = ((sum & 0444444) != 0);
is_full_house = ((n_types == 2) && !is_four_of_a_kind);
is_small_straight = ((types & (types>>1) & (types>>2) & (types>>3)) != 0);
is_large_straight = (types == 31 || types == 62);
is_yahtzee = ((types & (types-1)) == 0);
is_chance = true;
}
};
Another alternative is to encode all the bools in a single byte and make a table that maps a 5-digit base-6 number to its classification. That table is smaller than 8KB.
*reads Alvaro's post* *checks name of forum*
OK, it's "For Beginners" ;) Probably a tad too advanced for a simple Yahtzee game...
I suggested a sort and count consecutive approach (since it is scalable for more complex problems) until I found out it was Yahtzee where I feel a histogram based approach is going to be simplest to implement and understand.