%query: bid(i,o,o,o). /* bid.pl -- compute opening bid for bridge hand This program uses rules set forth in Jacoby (1988) counting high-card points, distribution points, and a few heuristics like support in 10s and 9s and long suits. Method -- find points for each suit independently, sum them, then adjust for combinations. Within a suit, compute high- card points, then distribution, then adjust for special combinations. Feb 1991 -- so far the program only counts points; we need a bridge expert to add rules for make_bid/4. Written By: John Conery */ %% To test, try "goal" %:- entry(bid(X,Y,Z,W),[share([[Y],[Z],[W]]),free([Y,Z,W]),ground([X])]). bid(Hand,Attributes,Points,Bid) :- sort_hand(Hand,SortedHand) , evaluate(SortedHand,Attributes,Points) , make_bid(SortedHand,Attributes,Points,Bid). evaluate(Hand,[],P) :- hcp(Hand,0,HCP) , adjustments(Hand,MP) , P is HCP + MP. adjustments(_,0). make_bid(Hand,Attributes,Points,'punt...'). /* hcp(H,Si,So) -- count the high-card-points in hand H */ hcp([],N,N). hcp([_X=C|Sn],Ni,No) :- hcp_suit(C,N) , Nt is N + Ni , hcp(Sn,Nt,No). hcp_suit(S,P) :- honors(S,0,HP) , dist(S,DP) , misc(S,MP) , P is HP + DP + MP. /* Count the honors in a suit. The suit is ordered, so we can stop as soon as we hit a low card. The first clause catches void suits and cases when a suit has only honors. */ honors([],Pi,Pi). honors([C1|Cn],Pi,Po) :- honor(C1,P) , P > 0 , Pt is P+Pi , honors(Cn,Pt,Po). honors([C1|Cn],Pi,Pi) :- honor(C1,0). % honor(C) = 0 if C not an honor honor(C,N) :- face_card(C,N). honor(C,0) :- integer(C). face_card(ace,4). face_card(king,3). face_card(queen,2). face_card(jack,1). dist([],3). dist([_],2). dist([_,_],1). dist([_,_,_|_],0). % Only one of the rules for misc/2 will be applied; if more than % one can be used, use 'bagof' in the call and sum the results. % A challenge for OPAL: how to code this, w/o metacall... % This version is using the first version that succeeds. % 1. singleton ace, subtract a point (worth 5, not 6); singleton % king is worth 2, doubleton queen or jack is worthless. misc([ace],-1). misc([king],-2). misc([queen,_],-2). % take off 3 for [queen,jack] ? misc([jack,_],-1). % 2. long suits -- 6 cards headed by 3 honors, add 1 for % each extra card.
content may be truncated. 'popout' for larger text window.