Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting number of points

Status
Not open for further replies.

surfbluedog

Technical User
Dec 2, 2003
4
0
0
NZ
I am writing a bridge program.
I am trying to count the number of points present in the hand according the the number of cards in each suit.
It works when i do a single query to it, but in t1 refuses to work. I really do not know what else to try.

Please please please help, I am desperate.

N is the number of cards in that suit, and X is the value asigned to N.
My code so far is as follows:

suit_count((5,_), X):-
X is 1.
suit_count((6, _), X):-
X is 2.
suit_count((7, _), X):-
X is 3.
suit_count((8, _), X):-
X is 4.
suit_count((0, _), X):-
X is 3.
suit_count((1, _), X):-
X is 2.
suit_count((2, _), X):-
X is 1.

total_suit_count((N, Hearts), (M, Diamonds), (O, Spades), (P, Clubs), Y3):-
suit_count((N, Hearts), X),
Y is X,
suit_count((M, Diamonds), X1),
Y1 is Y + X1,
suit_count((O, Spades), X2),
Y2 is Y1 + X2,
suit_count((P, Clubs), X3),
Y3 is Y2 + X3.
 
You seem to be missing rules for 3 and 4 cards in a suit. You should assign a value of 0 to those cases. Otherwise, prolog can't unify hands containing those numbers of cards, so it will say 'No'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top