I am trying to code a poker game using Prolog.
I understand how to code the royal flush but my four of a kind code won’t work.
I have the following code:
four_of_a_kind(R):-
member(card(V, T1), R),
member(card(V, T2), R),
member(card(V, T3), R),
member(card(V, T4), R).
where V is the rank which I want to be the same and T1,T2,T3,T4 are the suits. R is my list of cards.
Can anyone explain how to code the four of a kind in prolog please and explain what I am doing wrong please?
Your problem is that you search the whole hand all the times and T1, T2.. are free variables, so
unifies 4 times with the same card, and four_of_a_kind always returns true.
Solution: Just lock the suits.
Code:
Some query: