From Randy.Justice@cnet.navy.mil  Tue Sep  5 16:23:15 2000
Received: from smtp.cnet.navy.mil (smtp.cnet.navy.Mil [160.125.64.11])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA09425
	for <prolog@swi.psy.uva.nl>; Tue, 5 Sep 2000 16:23:14 +0200 (MET DST)
Received: from penx68322m1.cnet.navy.mil (pens0394.cnet.navy.Mil [160.125.210.190])
	by smtp.cnet.navy.mil (8.8.6 (PHNE_17190)/8.8.6) with ESMTP id JAA07908;
	Tue, 5 Sep 2000 09:21:33 -0500 (CDT)
Received: by pens0394.cnet.navy.Mil with Internet Mail Service (5.5.2650.21)
	id <SFZJKFWA>; Tue, 5 Sep 2000 09:23:52 -0500
Message-ID: <B4CA1F5D8D23D411ADC7009027E791BF1DF4DC@pens0394.cnet.navy.Mil>
From: "Justice, Randy -CONT" <Randy.Justice@cnet.navy.mil>
To: "'Richard A. O'Keefe'" <ok@atlas.otago.ac.nz>, prolog@swi.psy.uva.nl
Subject: RE: List
Date: Tue, 5 Sep 2000 09:23:51 -0500 
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)
Content-Type: text/plain;
	charset="iso-8859-1"

Thanks for all help...

Randy Justice


-----Original Message-----
From: Richard A. O'Keefe [mailto:ok@atlas.otago.ac.nz]
Sent: Monday, September 04, 2000 10:53 PM
To: Randy.Justice@cnet.navy.mil; prolog@swi.psy.uva.nl
Subject: Re: List


	I have the following setup.


	%   card(?Face, ?Rank)
	%   is true when Face is in [a,2..10,j,q,k] and Rank is
	%   the corresponding element of [1,2..10,11,12,13].

It is almost always a mistake to let the input/output formats of
a program dictate the internal data structures.  This predicate
would be useful for *converting* external form to internal form
and vice versa; for internal purposes, stick with the Ranks.

	
The predicate name is not good.  It should be something like

	card_face_rank(a, 1).
	...
	card_face_rank(k, 13).



	/* Card name,
	   stack */   
	    
	topcard(2, 1).
	topcard(8, 2).
	topcard(5, 3).
	topcard(9, 4).
	topcard(2, 5).
	topcard(10, 6).
	topcard(3, 7).
	topcard(j, 8).
	topcard(5, 9).
	topcard(3, 10).
	topcard(q, 11).
	topcard(4, 12).
	
I cannot make sense of this.  Theruntogetherpredicatename (why not
the more readable "top_card"?) seems to imply that it identifies
something as the top card.  But which is it?  Does "stack" in the
comment mean that the second argument (1..12) is a stack (or names
a stack in some fashion), or that the predicate is managed as a
stack?  If these things are stack numbers, why does no stack have
more than one card?

The first thing in good programming in *any* language is good
names (not names that *remind* someone who already knows what they
mean, but names that truthfully *inform* someone who *doesn't*
know what they mean yet) and good comments, again informing rather
than reminding.


	/* Test where two cards equals 14. */
	
Er, cards is cards and numbers is numbers.  How can a card
equal a number?

	is_fourteen(ICard1, ICard2):- 
	   card(ICard1,ICard1_Value), 
	   !,    
	   card(ICard2,ICard2_Value),
	   !,
	   14 =:= ICard1_Value + ICard2_Value.
	
What on earth are the cuts there for?

Presumably this predicate should be something like

	%   ranks_sum_to_fourteen(?Face1, ?Face2)
	%   is true when Face1 and Face2 are card faces
	%   (no suits involved) and their ranks sum to 14.

	ranks_sum_to_fourteen(Face1, Face2) :-
	    card_face_rank(Face1, Rank1),	
	    card_face_rank(Face2, Rank2),
	    Rank1 + Rank2 =:= 14.
	
	/* Returns a list of cards that equals 14. */
	 
	check_fourteen(Card1,Card2,StackCard1,StackCard2):-
	    topcard(Card1,StackCard1),
	    topcard(Card2,StackCard2),
	    is_fourteen(Card1,Card2).
	
	
The comment and the code couldn't contradict each other more
strongly.  The comment talks about a list, but there is no
list in the code.  The comment says "check", but the code will
"find".  The code even contradicts itself:  how can Card1 and
Card2 both be the top card?  The names in the code contradict
what the code does:  Card1 and Card2 are not (names of) cards
at all, but of card faces, and StackCard1 and StackCard2 are
not stacks, not cards, not stacks of cards, nor anything that
could be called a StackCard, but appear to be positions in a
sequence.  And again we have cards equalling numbers, which
makes as much sense as birds equalling typefaces.

Presumably this should be something like

	%   stacked_pair_summing_to_fourteen(Face1, Face2, Pos1, Pos2)
	%   is true when there is a card with face Face1 at position
	%   Pos1 in the stack, and a card with face Face2 at position
	%   Pos2 in the stack, and the ranks of those cards sum to
	%   fourteen.

	stacked_pair_summing_to_fourteen(Face1, Face2, Pos1, Pos2) :-
	    card_face_position(Face1, Pos1), % was topcard/2
	    card_face_position(Face2, Pos2),
	    ranks_sum_to_fourtenn(Face1, Face2).


	When I run this I get dups.

No you don't.

	A = 5
	B = 9
	C = 3
	D = 4 ;
	
	A = 9
	B = 5
	C = 4
	D = 3 
	
That's not a duplicate.  The two solutions I've quoted are DIFFERENT
solutions which are both really genuine right answers to the question
you asked.  Presumably what you really mean is

	%   stacked_pair_summing_to_fourteen(Face1, Face2, Pos1, Pos2)
	%   is true when there is a card with face Face1 at position
	%   Pos1 in the stack, and a card with face Face2 at position
	%   Pos2 in the stack, Pos1 is above Pos2, and the ranks of
        %   those cards sum to fourteen.

	stacked_pair_summing_to_fourteen(Face1, Face2, Pos1, Pos2) :-
	    card_face_position(Face1, Pos1),
	    card_face_position(Face2, Pos2),
	    Pos1 < Pos2,  % Pos1 is above Pos2
	    ranks_sum_to_fourtenn(Face1, Face2).

