You can submit cards in terms of a Rank-Suite form.
To check if cards fall from the same set, define a predicate:
same_suit(_-S, _-S).
You can use this predicate to check for a flush:
?- Cards = [1-d, 2-d, 3-d, 4-d, 5-d], maplist(same_suit(_-S), Cards). Cards = [1-d, 2-d, 3-d, 4-d, 5-d], S = d.
To determine if you have a pair, two pairs, three species, a full house or four, you can simply count the number of pairs in your hand and then compare the result with the name of the hand.
% Count the number of pairs in the given list of cards. count_pairs([], 0). count_pairs([R-_ | Cs], Pairs) :- count_rank(R, Cs, RankCount), count_pairs(Cs, Pairs0), Pairs is RankCount + Pairs0. % Count the number of cards with the given rank count_rank(R, Cs, RankCount) :- count_rank(R, Cs, 0, RankCount). count_rank(_, [], RankCount, RankCount) :- !. count_rank(R, [R-_ | Cs], RankCount0, RankCount) :- !, RankCount1 is RankCount0 + 1, count_rank(R, Cs, RankCount1, RankCount). count_rank(R, [_ | Cs], RankCount0, RankCount) :- count_rank(R, Cs, RankCount0, RankCount). % Map the number of pairs to the name of the hand pairs_hand(1, one_pair). pairs_hand(2, two_pair). pairs_hand(3, three_of_a_kind). pairs_hand(4, full_house). %pairs_hand(5, 'NOT POSSIBLE'). pairs_hand(6, four_of_a_kind).
Examples of using:
?- count_pairs([qc, qd, qs, js, qh], PairsCount), pairs_hand(PairsCount, Hand). PairsCount = 6, Hand = four_of_a_kind. ?- count_pairs([jc, qd, qs, js, qh], PairsCount), pairs_hand(PairsCount, Hand). PairsCount = 4, Hand = full_house. ?- count_pairs([jc, qd, qs, js, 7-h], PairsCount), pairs_hand(PairsCount, Hand). PairsCount = 2, Hand = two_pair.