Question: Write a prolog program for the relation better_poker_hand(Hand1, Hand2,Hand) that succeeds if Hand is the better poker hand between Hand1 and Hand2. For those unfamiliar
Write a prolog program for the relation better_poker_hand(Hand1, Hand2,Hand) that succeeds if Hand is the better poker hand between Hand1 and Hand2. For those unfamiliar with this card game, here are some rules of poker necessary for answering this exercise: The order of cards is 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace. Each hand consists of five cards. The rank of hands in ascending order is no pairs < one pair < two pairs < three of a kind < flush < straight < full house < four of a kind < straight flush. Where two cards have the same rank, the higher denomination wins, for example, a pair of kings beats a pair of 7's. (Hints: (1) Represent a poker hand by a list of terms of the formcard(Suit,Value). For example a hand consisting of the 2 of clubs, the 5 of spades, the queen of hearts, the queen of diamonds, and the 7 of spades would be represented by the list [card (clubs,2),card(spades,5),card(hearts,queen),card(diamonds, queen),card(spades,7)1. (2)It maybe helpful to define relations such as has_f lush (Hand), which is true if all the cards in Hand are of the same suit; has_full_house (Hand), which is true if Hand has three cards with the same value but in different suits, and the other two cards have the same different value; and has_straight (Hand), which is true if Hand has cards with consecutive values. (3) The number of cases to consider is reduced if the hand is first sorted.)
Initial Code:
better_poker_hand(Hand1, Hand2, Hand) :-
write("Error: Not Implemented"), false.
Test cases:
test(better_poker_hand) :-
better_poker_hand(
[card(diamond, 10), card(club, 2), card(heart, ace), card(spade, ace), card(diamond, king)],
[card(heart, 2), card(heart, 3), card(heart, 4), card(heart, 5), card(heart, 6)],
[card(heart, 2), card(heart, 3), card(heart, 4), card(heart, 5), card(heart, 6)]
),
better_poker_hand(
[card(heart, 5), card(spade, queen), card(heart, king), card(diamond, king), card(spade, 7)],
[card(diamond, 5), card(spade, king), card(diamond, queen), card(club, queen), card(club, 7)],
[card(heart, 5), card(spade, queen), card(heart, king), card(diamond, king), card(spade, 7)]
),
better_poker_hand(
[card(heart, 5), card(spade, queen), card(heart, ace), card(diamond, 4), card(spade, 7)],
[card(diamond, 5), card(spade, king), card(diamond, queen), card(club, jack), card(club, 7)],
[card(heart, 5), card(spade, queen), card(heart, ace), card(diamond, 4), card(spade, 7)]
).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
