Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:19:35+00:00 2026-06-09T11:19:35+00:00

I am trying to code a poker game using Prolog. I understand how to

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:19:37+00:00Added an answer on June 9, 2026 at 11:19 am

    Your problem is that you search the whole hand all the times and T1, T2.. are free variables, so

    member(card(V, T1), R),
    ...
    

    unifies 4 times with the same card, and four_of_a_kind always returns true.

    Solution: Just lock the suits.

    Code:

    is_card(X,Y) :-
        number(X), between(1,13,X),
        member(Y, [c,d,h,s]). /* clubs, diamonds, hearts and spades */
    
    four_of_a_kind(R) :-
        member(card(V,c), R),
        member(card(V,d), R),
        member(card(V,h), R),
        member(card(V,s), R), !.
    

    Some query:

    ?- four_of_a_kind([card(7,c), card(7,d), card(7,h), card(9,s), card(7,s)]).
    true.
    
    ?- four_of_a_kind([card(7,c), card(7,d), card(9,h), card(9,s), card(7,s)]).
    false.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m trying to code a tooltip (Yes I know, I have my reasons to
I am trying to code AES using Cipher Block Chaining(CBC) mode. I am pretty
I am trying to code the following query using Zend_Db api's: select * from
I'm trying to optimize code that I have. In order to do that, I
I am trying to make a poker game of sorts. I'm trying to learn
I am just asking a quick simple question here. I'm trying to code poker
Trying to run a very simple flot.js example, I have the following code to
I have a poker game where I designed a nice pretty GUI that displays
I'm trying to rotate and then scale an image using android.graphics.Matrix. The code is
I'm trying to write a simple game/utility to calculate poker odds. I know there's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.