home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
lifeos2.zip
/
LIFE-1.02
/
PITCH
/
WILDLIFE.SAV
< prev
next >
Wrap
Text File
|
1996-06-19
|
52KB
|
2,767 lines
dynamic(is_out)?
is_out(dummy).
bind_deck(0,[5,
11,
12,
40,
16,
2,
15,
21,
30,
36,
45,
22,
6,
8,
19,
23,
20,
9,
24,
26,
27,
29,
10,
32,
0,
46,
38,
48,
51,
52,
17,
18,
25,
35,
43,
13,
4,
1,
7,
33,
39,
28,
44,
47,
3,
53,
42,
50,
34,
49,
14,
31,
37,
41]).
bind_deck(1,[53,
52,
49,
30,
15,
29,
44,
51,
50,
7,
19,
48,
8,
13,
16,
14,
0,
24,
40,
43,
6,
28,
45,
5,
22,
37,
47,
46,
42,
41,
3,
11,
20,
21,
25,
26,
10,
23,
18,
27,
32,
34,
12,
36,
17,
9,
38,
33,
1,
35,
39,
4,
31,
2]).
bind_deck(2,[34,
33,
31,
53,
32,
38,
43,
12,
26,
36,
21,
5,
17,
29,
35,
37,
44,
45,
41,
15,
46,
52,
51,
9,
50,
49,
48,
47,
27,
4,
16,
11,
10,
25,
42,
40,
0,
18,
2,
3,
7,
8,
19,
1,
6,
14,
22,
23,
30,
24,
20,
28,
39,
13]).
bind_deck(3,[6,
34,
21,
17,
38,
15,
1,
7,
13,
10,
24,
2,
9,
26,
28,
35,
14,
39,
43,
23,
44,
45,
30,
37,
4,
50,
51,
0,
46,
41,
20,
32,
25,
19,
11,
12,
22,
29,
40,
42,
47,
16,
5,
31,
36,
3,
52,
18,
8,
27,
53,
49,
33,
48]).
bind_deck(4,[53,
0,
14,
15,
17,
37,
51,
16,
18,
32,
52,
5,
23,
44,
10,
24,
50,
11,
28,
2,
34,
38,
41,
30,
9,
49,
48,
6,
33,
25,
47,
26,
46,
45,
43,
42,
3,
31,
7,
29,
35,
1,
20,
39,
27,
4,
8,
12,
13,
21,
22,
19,
36,
40]).
bind_deck(5,[38,
41,
52,
0,
36,
11,
19,
26,
37,
12,
44,
45,
5,
17,
31,
49,
2,
7,
21,
46,
50,
10,
13,
16,
6,
20,
3,
27,
9,
29,
1,
30,
4,
22,
24,
32,
14,
18,
23,
25,
33,
35,
39,
8,
34,
43,
28,
48,
47,
42,
15,
51,
53,
40]).
bind_deck(6,[3,
9,
29,
32,
36,
39,
40,
25,
2,
17,
27,
31,
7,
4,
24,
23,
14,
10,
13,
35,
38,
11,
21,
0,
15,
22,
26,
12,
19,
28,
41,
43,
1,
30,
18,
20,
33,
44,
46,
48,
34,
50,
47,
6,
16,
37,
49,
51,
52,
42,
53,
5,
45,
8]).
bind_deck(7,[9,
7,
53,
52,
46,
5,
4,
6,
18,
16,
14,
25,
35,
36,
42,
43,
47,
40,
31,
2,
51,
38,
44,
32,
23,
24,
26,
13,
17,
50,
49,
29,
37,
48,
45,
15,
27,
1,
28,
8,
20,
22,
12,
33,
11,
10,
34,
3,
39,
21,
30,
19,
0,
41]).
bind_deck(8,[31,
43,
53,
52,
1,
51,
50,
49,
48,
25,
39,
36,
47,
24,
46,
45,
2,
29,
20,
28,
22,
12,
26,
27,
40,
42,
5,
8,
17,
21,
38,
34,
4,
10,
33,
6,
18,
37,
3,
44,
23,
41,
13,
11,
16,
19,
15,
7,
30,
32,
35,
0,
14,
9]).
bind_deck(9,[53,
52,
15,
26,
19,
38,
2,
11,
6,
0,
8,
16,
18,
22,
28,
5,
29,
32,
1,
30,
34,
35,
37,
39,
36,
44,
9,
21,
17,
27,
42,
45,
7,
10,
46,
23,
43,
47,
12,
4,
13,
20,
25,
31,
41,
24,
48,
3,
49,
14,
33,
40,
50,
51]).
bind_deck(10,[9,
11,
26,
53,
52,
13,
28,
2,
10,
30,
0,
17,
22,
41,
6,
4,
18,
33,
34,
3,
5,
37,
46,
12,
15,
16,
24,
25,
32,
19,
39,
35,
47,
1,
48,
51,
36,
43,
8,
50,
40,
29,
44,
20,
49,
27,
14,
31,
7,
21,
38,
42,
45,
23]).
bind_deck(11,[9,
22,
24,
32,
39,
23,
21,
17,
40,
47,
2,
8,
53,
10,
33,
28,
4,
16,
13,
29,
44,
51,
52,
15,
26,
30,
14,
50,
48,
49,
3,
31,
37,
46,
27,
5,
1,
35,
20,
0,
6,
11,
12,
34,
36,
7,
38,
41,
45,
43,
18,
25,
19,
42]).
bind_deck(12,[53,
11,
30,
26,
32,
1,
8,
45,
52,
29,
16,
28,
15,
33,
19,
34,
35,
39,
42,
43,
48,
21,
22,
49,
12,
50,
46,
6,
24,
4,
51,
9,
18,
13,
7,
10,
31,
5,
27,
20,
25,
36,
40,
38,
23,
0,
3,
37,
41,
14,
44,
17,
47,
2]).
bind_deck(13,[53,
19,
0,
9,
25,
52,
2,
11,
17,
13,
20,
21,
37,
23,
51,
50,
10,
33,
45,
18,
35,
46,
4,
14,
27,
34,
15,
12,
26,
38,
42,
36,
32,
47,
40,
3,
6,
7,
30,
44,
43,
16,
22,
28,
29,
8,
31,
1,
5,
24,
41,
39,
48,
49]).
bind_deck(14,[53,
32,
8,
24,
26,
52,
51,
50,
2,
49,
17,
36,
39,
41,
27,
16,
48,
10,
12,
18,
19,
23,
5,
7,
14,
21,
28,
42,
44,
45,
46,
47,
9,
0,
4,
3,
6,
13,
1,
15,
11,
37,
38,
40,
20,
43,
34,
30,
29,
31,
33,
22,
25,
35]).
bind_deck(15,[4,
1,
43,
53,
18,
39,
9,
38,
13,
32,
48,
50,
19,
52,
33,
46,
40,
51,
49,
47,
11,
21,
25,
45,
44,
3,
16,
0,
17,
20,
27,
30,
42,
2,
41,
15,
6,
29,
37,
35,
5,
7,
28,
31,
24,
36,
10,
22,
26,
34,
23,
14,
8,
12]).
bind_deck(16,[53,
52,
51,
50,
5,
12,
49,
29,
13,
43,
23,
48,
6,
14,
4,
10,
32,
42,
0,
9,
22,
31,
34,
39,
27,
7,
33,
16,
36,
26,
41,
45,
3,
2,
30,
44,
1,
11,
18,
21,
46,
25,
20,
24,
35,
28,
17,
19,
38,
8,
47,
40,
37,
15]).
bind_deck(17,[53,
49,
37,
52,
51,
19,
2,
20,
32,
39,
50,
4,
9,
18,
17,
48,
47,
46,
45,
44,
30,
11,
5,
38,
43,
21,
13,
15,
3,
35,
36,
25,
41,
6,
42,
40,
34,
1,
8,
7,
0,
10,
12,
14,
16,
23,
24,
22,
27,
26,
28,
29,
31,
33]).
bind_deck(18,[15,
53,
52,
40,
17,
9,
0,
16,
43,
50,
51,
49,
11,
48,
47,
46,
27,
30,
28,
29,
38,
3,
24,
34,
32,
45,
44,
42,
20,
37,
5,
23,
2,
7,
14,
10,
8,
1,
4,
12,
18,
19,
13,
21,
6,
22,
26,
31,
25,
33,
35,
36,
39,
41]).
bind_deck(19,[28,
35,
40,
0,
29,
30,
52,
53,
51,
50,
45,
1,
8,
15,
17,
24,
10,
14,
33,
4,
36,
23,
38,
11,
22,
12,
27,
43,
18,
32,
37,
13,
26,
34,
9,
2,
5,
21,
25,
7,
31,
41,
42,
46,
6,
16,
3,
19,
20,
39,
44,
47,
48,
49]).
bind_deck(20,[53,
0,
16,
28,
8,
10,
3,
12,
15,
20,
30,
14,
31,
36,
26,
11,
23,
7,
13,
33,
39,
40,
41,
45,
9,
32,
38,
47,
6,
19,
4,
24,
27,
2,
17,
29,
46,
5,
48,
49,
50,
37,
51,
52,
42,
44,
43,
22,
35,
34,
25,
1,
21,
18]).
bind_deck(21,[11,
15,
6,
0,
30,
7,
32,
42,
22,
25,
18,
29,
26,
31,
33,
35,
39,
45,
16,
48,
37,
43,
5,
46,
50,
4,
9,
36,
3,
8,
19,
27,
10,
14,
40,
47,
24,
49,
51,
1,
52,
2,
20,
28,
23,
41,
44,
12,
21,
38,
53,
13,
34,
17]).
bind_deck(22,[1,
53,
18,
30,
52,
51,
50,
16,
0,
6,
15,
31,
7,
4,
10,
11,
38,
41,
39,
49,
3,
48,
13,
34,
47,
42,
36,
14,
37,
46,
40,
25,
23,
8,
45,
44,
43,
22,
20,
19,
26,
28,
29,
35,
33,
27,
32,
24,
2,
9,
12,
5,
17,
21]).
bind_deck(23,[23,
27,
39,
53,
52,
8,
51,
1,
5,
26,
28,
34,
35,
0,
10,
14,
16,
30,
19,
32,
37,
40,
25,
29,
2,
42,
13,
20,
17,
22,
3,
6,
11,
36,
21,
15,
7,
4,
24,
38,
43,
46,
41,
49,
9,
12,
18,
31,
44,
47,
45,
33,
48,
50]).
bind_deck(24,[44,
49,
53,
11,
25,
28,
52,
39,
50,
51,
48,
6,
27,
47,
20,
23,
34,
46,
29,
2,
3,
12,
0,
5,
7,
13,
17,
9,
22,
1,
30,
8,
31,
35,
4,
21,
36,
18,
37,
24,
15,
38,
40,
10,
41,
19,
14,
26,
42,
32,
43,
45,
33,
16]).
bind_deck(25,[3,
7,
9,
23,
16,
33,
42,
32,
35,
28,
27,
31,
34,
36,
46,
4,
1,
49,
50,
14,
19,
29,
8,
39,
43,
52,
2,
44,
53,
51,
5,
30,
22,
47,
48,
0,
45,
41,
40,
38,
10,
17,
18,
20,
21,
25,
24,
13,
26,
12,
37,
11,
6,
15]).
bind_deck(26,[2,
26,
22,
3,
43,
53,
8,
0,
34,
38,
52,
49,
11,
24,
45,
10,
51,
13,
30,
20,
44,
7,
48,
50,
47,
21,
46,
9,
42,
23,
41,
40,
25,
28,
27,
35,
14,
5,
15,
17,
4,
18,
19,
16,
29,
12,
32,
37,
1,
6,
31,
33,
36,
39]).
bind_deck(27,[53,
17,
51,
50,
52,
49,
33,
34,
31,
12,
1,
20,
28,
5,
32,
35,
10,
11,
2,
27,
29,
9,
36,
0,
25,
30,
40,
18,
41,
42,
43,
26,
19,
48,
23,
15,
13,
16,
22,
39,
3,
45,
46,
8,
24,
4,
38,
44,
47,
37,
21,
14,
6,
7]).
bind_deck(28,[15,
19,
20,
30,
27,
7,
31,
6,
13,
34,
42,
16,
5,
28,
43,
40,
44,
45,
46,
49,
11,
33,
47,
51,
26,
3,
10,
32,
38,
41,
52,
53,
50,
48,
9,
12,
17,
0,
8,
21,
23,
1,
29,
35,
2,
36,
14,
4,
39,
22,
25,
24,
18,
37]).
bind_deck(29,[16,
22,
23,
30,
33,
53,
24,
12,
28,
19,
18,
35,
44,
7,
52,
51,
50,
38,
39,
29,
40,
3,
36,
21,
15,
45,
2,
4,
25,
37,
42,
17,
49,
5,
11,
1,
8,
48,
47,
0,
6,
10,
20,
27,
31,
41,
9,
43,
14,
34,
13,
26,
32,
46]).
%/* not definition required RS6000 prolog */
%/*not(P) :- call(P), !, fail.
%not(P). */
%/* member and append predicates from the Art of Prolog. */
member_djd(X,[X|Xs]).
member_djd(X,[Y|Ys]) :- member_djd(X,Ys).
append_djd([],Ys,Ys).
append_djd([X|Xs],Ys,[X|Zs]) :- append_djd(Xs,Ys,Zs).
length_djd([],0).
length_djd([X],1).
length_djd([X|Xs],N1) :- length_djd(Xs,N), (N = N1 - 1).
%/* predicate eq defined for use with not above */
%eq(A,B) :- A :== B.
%/**********************************************************************/
%/* deck representation follows */
%/* for each suite these is a predicate which is true of cards of that */
%/* suite represented as a list of data for that card. The data is : */
%/* [card number(as represented in deck and other lists of cards , */
%/* sequence value in this suite, */
%/* suite, */ */
%/* name of card, */ */
%/* points for taking this card, */
%/* points for playing this card] */
%/*******************************************************************/
heart([0,2,hearts,c_2_of_hearts,0,1]).
heart([1,3,hearts,c_3_of_hearts,0,0]).
heart([2,4,hearts,c_4_of_hearts,0,0]).
heart([3,5,hearts,c_5_of_hearts,0,0]).
heart([4,6,hearts,c_6_of_hearts,0,0]).
heart([5,7,hearts,c_7_of_hearts,0,0]).
heart([6,8,hearts,c_8_of_hearts,0,0]).
heart([7,9,hearts,c_9_of_hearts,0,0]).
heart([8,10,hearts,c_10_of_hearts,1,0]).
heart([52,11,hearts,low_joker,1,0]).
heart([53,12,hearts,high_joker,1,0]).
heart([22,13,hearts,j_of_diamonds,1,0]).
heart([9,14,hearts,j_of_hearts,1,0]).
heart([10,15,hearts,q_of_hearts,0.0]).
heart([11,16,hearts,k_of_hearts,0,0]).
heart([12,17,hearts,a_of_hearts,0,1]).
diamond([13,2,diamonds,c_2_of_diamonds,0,1]).
diamond([14,3,diamonds,c_3_of_diamonds,0,0]).
diamond([15,4,diamonds,c_4_of_diamonds,0,0]).
diamond([16,5,diamonds,c_5_of_diamonds,0,0]).
diamond([17,6,diamonds,c_6_of_diamonds,0,0]).
diamond([18,7,diamonds,c_7_of_diamonds,0,0]).
diamond([19,8,diamonds,c_8_of_diamonds,0,0]).
diamond([20,9,diamonds,c_9_of_diamonds,0,0]).
diamond([21,10,diamonds,c_10_of_diamonds,1,0]).
diamond([52,11,diamonds,low_joker,1,0]).
diamond([53,12,diamonds,high_joker,1,0]).
diamond([9,13,diamonds,j_of_hearts,1,0]).
diamond([22,14,diamonds,j_of_diamonds,1,0]).
diamond([23,15,diamonds,q_of_diamonds,0,0]).
diamond([24,16,diamonds,k_of_diamonds,0,0]).
diamond([25,17,diamonds,a_of_diamonds,0,1]).
spade([26,2,spades,c_2_of_spades,0,1]).
spade([27,3,spades,c_3_of_spades,0,0]).
spade([28,4,spades,c_4_of_spades,0,0]).
spade([29,5,spades,c_5_of_spades,0,0]).
spade([30,6,spades,c_6_of_spades,0,0]).
spade([31,7,spades,c_7_of_spades,0,0]).
spade([32,8,spades,c_8_of_spades,0,0]).
spade([33,9,spades,c_9_of_spades,0,0]).
spade([34,10,spades,c_10_of_spades,1,0]).
spade([52,11,spades,low_joker,1,0]).
spade([53,12,spades,high_joker,1,0]).
spade([48,13,spades,j_of_clubs,1,0]).
spade([35,14,spades,j_of_spades,1,0]).
spade([36,15,spades,q_of_spades,0,0]).
spade([37,16,spades,k_of_spades,0,0]).
spade([38,17,spades,a_of_spades,0,1]).
club([39,2,clubs,c_2_of_clubs,0,1]).
club([40,3,clubs,c_3_of_clubs,0,0]).
club([41,4,clubs,c_4_of_clubs,0,0]).
club([42,5,clubs,c_5_of_clubs,0,0]).
club([43,6,clubs,c_6_of_clubs,0,0]).
club([44,7,clubs,c_7_of_clubs,0,0]).
club([45,8,clubs,c_8_of_clubs,0,0]).
club([46,9,clubs,c_9_of_clubs,0,0]).
club([47,10,clubs,c_10_of_clubs,1,0]).
club([52,11,clubs,low_joker,1,0]).
club([53,12,clubs,high_joker,1,0]).
club([35,13,clubs,j_of_spades,1,0]).
club([48,14,clubs,j_of_clubs,1,0]).
club([49,15,clubs,q_of_clubs,0,0]).
club([50,16,clubs,k_of_clubs,0,0]).
club([51,17,clubs,a_of_clubs,0,1]).
valid_bid(Val) :- 2 =< Val , Val =< 7.
valid_bid(Val) :- Val = pass.
valid_suite(hearts).
valid_suite(diamonds).
valid_suite(spades).
valid_suite(clubs).
%/* the card predicate combines infomation of all suits */
card([No,Val,Suite,Name,Pt_taken,Pt_played]) :-
heart([No,Val,Suite,Name,Pt_taken,Pt_played]).
card([No,Val,Suite,Name,Pt_taken,Pt_played]) :-
diamond([No,Val,Suite,Name,Pt_taken,Pt_played]).
card([No,Val,Suite,Name,Pt_taken,Pt_played]) :-
spade([No,Val,Suite,Name,Pt_taken,Pt_played]).
card([No,Val,Suite,Name,Pt_taken,Pt_played]) :-
club([No,Val,Suite,Name,Pt_taken,Pt_played]).
valid_card(Name,Suite,H) :-
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
member_djd(No,H).
%/* some predicates follow which are used for initialization */
bind_teams([[dennis,dick],[sussy,john]]).
bind_players([dennis,sussy,dick,john]).
succ_player(dennis,sussy).
succ_player(sussy,dick).
succ_player(dick,john).
succ_player(john,dennis).
partner(dennis,dick).
partner(dick,dennis).
partner(sussy,john).
partner(john,sussy).
bind_dealer(dennis).
bind_played([[],[],[],[]]).
bind_taken([[],[],[],[]]).
bind_score([0,0]).
%/*******************************************************************/
%/* The main predicate for invoking a game of pitch follows */
%/* to invoke a game the query - play_game(R,S). - may be used. */
%/******************************************************************/
play_game(Teams,Scores) :- bind_teams(Teams),
bind_players(Players),
bind_score(Scores),bind_dealer(Dealer),
% load("shuffle.lf"),
% open_out("pitch.log"),
play_hand(Players,Teams,Scores,Dealer,Deck,0).
play_hand(Players,Teams,Scores,Dealer,Deck,Cnt) :- done(Teams,Scores).
play_hand(Players,Teams,Scores,Dealer,Deck,Cnt) :-
bind_played(Played),
% load("is_out.lf"),
bind_taken(Taken),
%/* shell('shuffle >shuffle.p'), */
bind_deck(Cnt,Deck),
deal(Players,Deck,Newdeckx,Hands,Dealer),
bid_lf(Players,Hands,Dealer,Bidder,Bid,Suite),
write_bl(bid_is),
write_bl(Bidder),
write_bl(Bid),
write_nl(Suite),
discard(Players,Hands,Hands2,Suite),
deal2(Players,Newdeckx,Hands2,Hands3,Dealer,Bidder),
discard(Players,Hands3,Hands4,Suite),
retract(is_out(dennis)),
retract(is_out(sussy)),
retract(is_out(john)),
retract(is_out(dick)),
% load("is_out.lf"),
play_cards(Players,Hands4,Played,Taken,Bidder,Suite,
Newplayed,Newtaken,Npret,Ntret),
score(Players,Teams,Npret,Ntret,Scores,Newscores,Bidder,Bid,Suite),
succ_player(Dealer,Newdealer),
(Cnt2 -> Cnt + 1), % was is changed to = for life
play_hand(Players,Teams,Newscores,Newdealer,Newdeck,Cnt2).
%/* game is over when score reaches 21 */
done(Teams,[S1,S2]) :- S1 >= 21.
done(Teams,[S1,S2]) :- S2 >= 21.
%/* deal cards 1st round. Each player gets 9 cards */
deal(Players,Deck,Newdeckx,Hands,Dealer) :- write_nl(p_deal),
Deck = [C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C13,C14,C15,
C16,C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,
C31,C32,C33,C34,C35,C36,C37,C38,C39,C40,C41,C42,C43,C44,C45,
C46,C47,C48,C49,C50,C51,C52,C53,C54],
!,
Newdeckx = [C37,C38,C39,C40,C41,C42,C43,C44,
C45,C46,C47,C48,C49,C50,C51,C52,C53,C54],
Hands = [[C1,C2,C3,C13,C14,C15,C25,C26,C27],
[C4,C5,C6,C16,C17,C18,C28,C29,C30],
[C7,C8,C9,C19,C20,C21,C31,C32,C33],
[C10,C11,C12,C22,C23,C24,C34,C35,C36]],
write_nl(Hands).
%/* rules foer what a player can bid follow */
%/*
%can_bid(4,Hand,Suite1,Bidder) :-
% member_djd(No1,Hand),
% member_djd(No2,Hand),
% card([No1,2,Suite1,Name1,Pt_taken1,Pt_played1]),
% card([No2,17,Suite2,Name2,Pt_taken2,Pt_played2]),
% Suite1 = Suite2.
%can_bid(3,Hand,Suite,Bidder) :-
% member_djd(No1,Hand),
% card([No1,17,Suite,Name1,Pt_taken1,Pt_played1]).
%can_bid(2,Hand,Suite1,Bidder) :-
% member_djd(No1,Hand),
% member_djd(No2,Hand),
% card([No1,2,Suite1,Name1,Pt_taken1,Pt_played1]),
% card([No2,Val2,Suite2,Name2,Pt_taken2,Pt_played2]),
% Val2 >= 10,
% Suite1 = Suite2.
%can_bid(0,Hand,pass,Bidder).
%*/
%/* the bidding process is described below */
bid_lf(Players,Hands,Dealer,Bidder,Bid,Suite) :- write_nl(p_bid),
succ_player(Dealer,Bidder1),
get_hand(Players,Hands,Bidder1,Hand1),
trybid(Bidder1,Hand1,0,pass,pass,Maxbidder1,Maxbid1,Maxsuite1),
succ_player(Bidder1,Bidder2),
get_hand(Players,Hands,Bidder2,Hand2),
trybid(Bidder2,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2),
succ_player(Bidder2,Bidder3),
get_hand(Players,Hands,Bidder3,Hand3),
trybid(Bidder3,Hand3,Maxbid2,Maxbidder2,Maxsuite2,
Maxbidder3,Maxbid3,Maxsuite3),
succ_player(Bidder3,Bidder4),
get_hand(Players,Hands,Bidder4,Hand4),
trybid(Bidder4,Hand4,Maxbid3,Maxbidder3,Maxsuite3,
Bidder5,Bid5,Suite5),
no_bid(Dealer,Bidder5,Bid5,Suite5,Bidder,Bid,Suite).
no_bid(Dealer,Bidder5,Bid5,Suite5,Bidder,Bid,Suite) :-
Bid5 = 0,
Bidder = Dealer,
Bid = 2,
Suite = spades.
no_bid(Dealer,Bidder5,Bid5,Suite5,Bidder,Bid,Suite) :-
\+ (Bid5 = 0),
Bidder = Bidder5,
Bid = Bid5,
Suite = Suite5.
%/* get hand provodes a list of cards associated with a player */
get_hand(Players,Hands,P1,H1) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4].
get_hand(Players,Hands,P2,H2) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4].
get_hand(Players,Hands,P3,H3) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4].
get_hand(Players,Hands,P4,H4) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4].
%/* put_hand updates a list of cards associated with a player */
put_hand(Players,Hands,P1,Hand,Newhands) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4],
Newhands = [Hand,H2,H3,H4].
put_hand(Players,Hands,P2,Hand,Newhands) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4],
Newhands = [H1,Hand,H3,H4].
put_hand(Players,Hands,P3,Hand,Newhands) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4],
Newhands = [H1,H2,Hand,H4].
put_hand(Players,Hands,P4,Hand,Newhands) :-
Players = [P1,P2,P3,P4],
Hands = [H1,H2,H3,H4],
Newhands = [H1,H2,H3,Hand].
%/* current player can bid higher than high bid so far */
trybid(Bidder2,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2) :-
dennis :\==Bidder2,
max_bid(Bidval,Hand2,Suite,Bidder2),
Bidval > Maxbid1,
write_bl(Bidder2),
write_bl(bids),
write_nl(Bidval),
Maxbidder2 = Bidder2,
Maxbid2 = Bidval,
Maxsuite2 = Suite.
%/* current player can not bid higher than high bid so far */
trybid(Bidder2,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2) :-
dennis :\== Bidder2,
max_bid(Bidval,Hand2,Suite,Bidder2),
Bidval =< Maxbid1,
Maxbidder2 = Maxbidder1,
Maxbid2 = Maxbid1,
Maxsuite2 = Maxsuite1.
%/* rule repeated 3 times for 3 chances for valid answer */
trybid(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2) :-
display_hand(Hand2),
write_bl(enter),
write_bl(bid),
write_nl(value),
read(Bidval),
valid_bid(Bidval),
write_bl(enter),
write_bl(bid),
write_nl(suite),
read(Suite),
valid_suite(Suite),!,
trybid_b(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2,Bidval,Suite).
trybid(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2) :-
display_hand(Hand2),
write_bl(enter),
write_bl(bid),
write_nl(value),
read(Bidval),
valid_bid(Bidval),
write_bl(enter),
write_bl(bid),
write_nl(suite),
read(Suite),
valid_suite(Suite),!,
trybid_b(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2,Bidval,Suite).
trybid(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2) :-
display_hand(Hand2),
write_bl(enter),
write_bl(bid),
write_nl(value),
read(Bidval),
valid_bid(Bidval),
write_bl(enter),
write_bl(bid),
write_nl(suite),
read(Suite),
valid_suite(Suite),!,
trybid_b(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2,Bidval,Suite).
trybid_b(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2,Bidval,Suite) :-
Bidval > Maxbid1,
write_bl(Bidder2),
write_bl(bids),
write_nl(Bidval),
Maxbidder2 = dennis,
Maxbid2 = Bidval,
Maxsuite2 = Suite.
trybid_b(dennis,Hand2,Maxbid1,Maxbidder1,Maxsuite1,
Maxbidder2,Maxbid2,Maxsuite2,Bidval,Suite) :-
Bidval = pass,
Maxbidder2 = Maxbidder1,
Maxbid2 = Maxbid1,
Maxsuite2 = Maxsuite1.
%/* max bid appear in order lowest to highest */
max_bid(7,Hand,Suite,Bidder) :- can_bid(7,Hand,Suite,Bidder),!.
max_bid(6,Hand,Suite,Bidder) :- can_bid(6,Hand,Suite,Bidder),!.
max_bid(5,Hand,Suite,Bidder) :- can_bid(5,Hand,Suite,Bidder),!.
max_bid(4,Hand,Suite,Bidder) :- can_bid(4,Hand,Suite,Bidder),!.
max_bid(3,Hand,Suite,Bidder) :- can_bid(3,Hand,Suite,Bidder),!.
max_bid(2,Hand,Suite,Bidder) :- can_bid(2,Hand,Suite,Bidder),!.
max_bid(0,Hand,Suite,Bidder) :- can_bid(0,Hand,Suite,Bidder),!.
%/* delete item (card) from list of items (cards) */
delete(Item,List,Newlist) :-
discard_item(Item,List,Nl,[],Newlist).
discard_item(Item,List,Nl,Partl,Newlist) :-
List = [Item | Nl],
Partl2 = Partl,
discard_item(Item,Nl,Nl2,Partl2,Newlist).
discard_item(Item,List,Nl,Partl,Newlist) :-
List = [Item],
Partl2 = Partl,
discard_item(Item,[],Nl2,Partl2,Newlist).
discard_item(Item,List,Nl,Partl,Newlist) :-
List = [I | Nl],
I :\== Item,
Partl2 = [I | Partl],
discard_item(Item,Nl,Nl2,Partl2,Newlist).
discard_item(Item,List,Nl,Partl,Newlist) :-
List = [I],
I :\== Item,
Partl2 = [I,Part],
discard_item(Item,[],Nl2,Partl2,Newlist).
discard_item(Item,List,Nl,Partl,Newlist) :-
List = [],!,
Newlist = Partl.
%/* once suite is determined by high bidder players must discard cards
%not of that suite (except left jack & jokers) & also not retain more
%than 6 cards*/
discard(Players,Hands,Hands2,Suite) :- write_nl(p_discard),
Hands = [H1,H2,H3,H4],
discard_non_suite(H1,Nh1,[],Hand1,Suite),
discard_non_suite(H2,Nh2,[],Hand2,Suite),
discard_non_suite(H3,Nh3,[],Hand3,Suite),
discard_non_suite(H4,Nh4,[],Hand4,Suite),
discard_excess(Hand1,Newhand1,Suite),
discard_excess(Hand2,Newhand2,Suite),
discard_excess(Hand3,Newhand3,Suite),
discard_excess(Hand4,Newhand4,Suite),
Hands2 = [Newhand1,Newhand2,Newhand3,Newhand4],
write_nl(Hands2).
discard_non_suite(H,Nh,Parthand,Hand,Suite) :-
H = [No | Nh],
card([No,Val,Suite2,Name,Pt_taken,Pt_played]),
Suite = Suite2,
append_djd(Parthand , [No] ,Parthand2),
discard_non_suite(Nh,Nh2,Parthand2,Hand,Suite).
discard_non_suite(H,Nh,Parthand,Hand,Suite) :-
H = [No | Nh],
\+(card([No,Val,Suite,Name,Pt_taken,Pt_played])),
%/* write_nl(discarded),
% write_nl(Name), */
discard_non_suite(Nh,Nh2,Parthand,Hand,Suite).
discard_non_suite(H,Nh,Parthand,Hand,Suite) :-
Hand = Parthand, !.
discard_excess(Hand,Newhand,Suite) :-
length_djd(Hand,Len),
Len =< 6,
Newhand = Hand.
discard_excess(Hand,Newhand,Suite) :-
length_djd(Hand,Len),
Len > 6,
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
member_djd(No,Hand),
2 < Val,
10 > Val,
%/* write_nl(excess),
% write_nl(Name), */
delete(No,Hand,Newhand2),
discard_excess(Newhand2,Newhand,Suite).
discard_excess(Hand,Newhand,Suite) :-
length_djd(Hand,Len),
Len > 6,
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
member_djd(No,Hand),
15 = Val,
%/* write_nl(excess2),
% write_nl(Name), */
delete(No,Hand,Newhand2),
discard_excess(Newhand2,Newhand,Suite).
discard_excess(Hand,Newhand,Suite) :-
length_djd(Hand,Len),
Len > 6,
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
member_djd(No,Hand),
16 = Val,
delete(No,Hand,Newhand2),
discard_excess(Newhand2,Newhand,Suite).
discard_excess(Hand,Newhand,Suite) :-
length_djd(Hand,Len),
Len > 6,
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
member_djd(No,Hand),
2 = Val,
delete(No,Hand,Newhand2),
discard_excess(Newhand2,Newhand,Suite).
%/* after discarding players (other than the bidder) receive enough
%cards th raise their total cards to 6. The bidder gets to look through
%whatever is then left */
deal2(Players,Newdeck,Hands2,Hands3,Dealer,Bidder) :-
write_nl(p_deal2),
succ_player(Dealer,P1),
extras(Players,Newdeck,Newdeck2,Hands2,Hands2a,P1,Bidder),
succ_player(P1,P2),
extras(Players,Newdeck2,Newdeck3,Hands2a,Hands2b,P2,Bidder),
succ_player(P2,P3),
extras(Players,Newdeck3,Newdeck4,Hands2b,Hands2c,P3,Bidder),
succ_player(P3,P4),
extras(Players,Newdeck4,Newdeck5,Hands2c,Hands2d,P4,Bidder),
remaining(Players,Newdeck5,Hands2d,Hands3,Bidder),
write_nl(final_hands),
write_nl(Hands3).
extras(Players,Newdeck,Newdeck2,Hands2,Hands2a,P1,Bidder) :-
P1 = Bidder, ! ,
Newdeck2 = Newdeck,
Hands2a = Hands2.
extras(Players,Newdeck,Newdeck2,Hands2,Hands2a,P1,Bidder) :-
Newdeck = [], ! ,
Newdeck2 = Newdeck,
Hands2a = Hands2.
extras(Players,Newdeck,Newdeck2,Hands2,Hands2a,P1,Bidder) :-
get_hand(Players,Hands2,P1,H1),
length_djd(H1,Len),
Len = 6, ! ,
Newdeck2 = Newdeck,
Hands2a = Hands2.
extras(Players,Newdeck,Newdeck2,Hands2,Hands2a,P1,Bidder) :-
get_hand(Players,Hands2,P1,H1),
length_djd(H1,Len),
Len < 6,
Newdeck = [No | Newdeck3],
H1a = [No | H1],
put_hand(Players,Hands2,P1,H1a,Hands3),
extras(Players,Newdeck3,Newdeck2,Hands3,Hands2a,P1,Bidder).
remaining(Players,Newdeck5,Hands2d,Hands3,Bidder) :-
get_hand(Players,Hands2d,Bidder,H1),
append_djd(H1,Newdeck5,H1a),
put_hand(Players,Hands2d,Bidder,H1a,Hands3).
%/* each player plays a card the highest card wins */
play_cards(Players,Hands,Played,Taken,Leader,Suite,Newplayed,Newtaken,
Npret,Ntret) :-
Hands = [H1,H2,H3,H4],
sort_by_val(H1,H1s,Suite),
sort_by_val(H2,H2s,Suite),
sort_by_val(H3,H3s,Suite),
sort_by_val(H4,H4s,Suite),
Hands2 = [H1s,H2s,H3s,H4s], %/* sorted hands */
write_bl(dennis),
write_nl(hand),
display_hand(H1s),
%/* write_nl('sussy hand2'),
% display_hand(H2s),
% write_nl('dick hand3'),
% display_hand(H3s),
% write_nl('john hand4'),
% display_hand(H4s), */
play_card([Players,Hands2,Played,Taken,Leader,
Newhands,Newplayed,Newtaken,Newleader,Suite]),
play_cards(Players,Newhands,Newplayed,Newtaken,Newleader,Suite,
Np,Nt,Npret,Ntret).
%/* a hand ends when all players are out of cards */
play_cards(Players,Hands,Played,Taken,Leader,Suite,Newplayed,Newtaken,
Npret,Ntret) :-
out(Players,Hands), !,
Npret =Played,
Ntret = Taken.
out(Players,Hands) :-
Hands = [[],[],[],[]], !,
write_nl(p_out).
play_card([Players,Hands,Played,Taken,Leader,Newhands,Newplayed,
Newtaken,Newleader,Suite]) :-
play_1card([Players,Hands,Played,Leader,Newhands1,Newplayed1,
0,none,Newhigh1,Newwhohigh1,[],Newcards1,Suite]),
succ_player(Leader,P2),
play_1card([Players,Newhands1,Newplayed1,P2,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]),
succ_player(P2,P3),
play_1card([Players,Newhands2,Newplayed2,P3,Newhands3,Newplayed3,
Newhigh2,Newwhohigh2,Newhigh3,Newwhohigh3,
Newcards2,Newcards3,Suite]),
succ_player(P3,P4),
play_1card([Players,Newhands3,Newplayed3,P4,Newhands,Newplayed,
Newhigh3,Newwhohigh3,Newhigh4,Newwhohigh4,
Newcards3,Newcards4,Suite]),
summary_cards_taken([Players,Taken,Newtaken,Newhigh4,Newwhohigh4,
Newcards4,Newleader]).
play_1card([Players,Newhands1,Newplayed1,P2,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]) :-
P2 :\== dennis,
get_hand(Players,Newhands1,P2,H2),
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1),
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]),
Val > Newhigh1, ! ,
write_bl(P2),
write_bl(plays),
write_nl(Name),
delete(Card1,H2,Nh2),
Newhigh2 = Val,
Newwhohigh2 = P2,
put_hand(Players,Newhands1,P2,Nh2,Newhands2),
get_hand(Players,Newplayed1,P2,Pl1),
Pl2 = [Card1 | Pl1],
Newcards2 = [Card1 | Newcards1],
%/* write_bl(newcards2),write_nl(Newcards2), */
put_hand(Players,Newplayed1,P2,Pl2,Newplayed2). %/* was , */
%/* write_bl(newplayed2),write_nl(Newplayed2). */
play_1card([Players,Newhands1,Newplayed1,P2,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]) :-
P2 :\== dennis,
get_hand(Players,Newhands1,P2,H2),
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1),
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]),
Val < Newhigh1, ! ,
write_bl(P2),
write_bl(plays),
write_nl(Name),
delete(Card1,H2,Nh2),
Newhigh2 = Newhigh1,
Newwhohigh2 = Newwhohigh1,
put_hand(Players,Newhands1,P2,Nh2,Newhands2),
get_hand(Players,Newplayed1,P2,Pl1),
Pl2 = [Card1 | Pl1],
Newcards2 = [Card1 | Newcards1],
%/* write_bl(newcards2),write_nl(Newcards2), */
put_hand(Players,Newplayed1,P2,Pl2,Newplayed2). %/* was , */
%/* write_bl(newplayed2),write_nl(Newplayed2). */
play_1card([Players,Newhands1,Newplayed1,P2,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]) :-
get_hand(Players,Newhands1,P2,H2),
H2 = [],!,
asserta(is_out(P2)),
write_bl(P2),
write_nl(is_out),
Newhigh2 = Newhigh1,
Newhands2 = Newhands1,
Newplayed2 = Newplayed1,
Newcards2 = Newcards1,
Newwhohigh2 = Newwhohigh1.
%/* rule repeated 3 times for 3 chances */
play_1card([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]) :-
get_hand(Players,Newhands1,dennis,H2),
write_bl(play),
write_bl(what),
write_nl(card),
read(Name),
valid_card(Name,Suite,H2),!,
play_1card_b([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite],Name,H2).
play_1card([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]) :-
get_hand(Players,Newhands1,dennis,H2),
write_bl(play),
write_bl(what),
write_nl(card),
read(Name),
valid_card(Name,Suite,H2),!,
play_1card_b([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite],Name,H2).
play_1card([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite]) :-
get_hand(Players,Newhands1,dennis,H2),
write_bl(play),
write_bl(what),
write_nl(card),
read(Name),
valid_card(Name,Suite,H2),!,
play_1card_b([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite],Name,H2).
play_1card_b([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite],Name,H2) :-
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]),
Val > Newhigh1, ! ,
write_bl(dennis),
write_bl(plays),
write_nl(Name),
delete(Card1,H2,Nh2),
Newhigh2 = Val,
Newwhohigh2 = dennis,
put_hand(Players,Newhands1,dennis,Nh2,Newhands2),
get_hand(Players,Newplayed1,dennis,Pl1),
Pl2 = [Card1 | Pl1],
Newcards2 = [Card1 | Newcards1],
%/* write_bl(newcards2),write_nl(Newcards2), */
put_hand(Players,Newplayed1,dennis,Pl2,Newplayed2). %/* was , */
%/* write_bl(newplayed2),write_nl(Newplayed2). */
play_1card_b([Players,Newhands1,Newplayed1,dennis,Newhands2,Newplayed2,
Newhigh1,Newwhohigh1,Newhigh2,Newwhohigh2,
Newcards1,Newcards2,Suite],Name,H2) :-
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]),
Val < Newhigh1, ! ,
write_bl(dennis),
write_bl(plays),
write_nl(Name),
delete(Card1,H2,Nh2),
Newhigh2 = Newhigh1,
Newwhohigh2 = Newwhohigh1,
put_hand(Players,Newhands1,dennis,Nh2,Newhands2),
get_hand(Players,Newplayed1,dennis,Pl1),
Pl2 = [Card1 | Pl1],
Newcards2 = [Card1 | Newcards1],
%/* write_bl(newcards2),write_nl(Newcards2), */
put_hand(Players,Newplayed1,dennis,Pl2,Newplayed2). %/* was , */
%/* write_bl(newplayed2),write_nl(Newplayed2). */
summary_cards_taken([Players,Taken,Newtaken,Newhigh4,Newwhohigh4,
Newcards4,Newleader]):-
get_hand(Players,Taken,Newwhohigh4,H2),
append_djd(H2,Newcards4,H3),
write_bl(Newwhohigh4),
write_nl(takes_the_hand),
Newleader = Newwhohigh4,
put_hand(Players,Taken,Newwhohigh4,H3,Newtaken). %/* was , */
%/* write_bl(newtaken),write_nl(Newtaken). */
write_nl(X) :- write(X), put(46), put(10), put(13).
% write(Log,X), put(Log,46), put(Log,10), put(Log,13).
write_bl(X) :- write(X), put(32).
% write(Log,X), put(Log,32).
score(Players,Teams,Played,Taken,Scores,Newscores,Bidder,Bid,Suite) :-
Scores = [S1,S2],
Players = [P1,P2,P3,P4],
get_hand(Players,Taken,P1,Card1s_taken1),
pts_taken(Card1s_taken1,Suite,Score_addt1,0),
get_hand(Players,Played,P1,Card1s_played1),
pts_played(Card1s_played1,Suite,Score_addp1,0),
get_hand(Players,Taken,P2,Card1s_taken2),
pts_taken(Card1s_taken2,Suite,Score_addt2,0),
get_hand(Players,Played,P2,Card1s_played2),
pts_played(Card1s_played2,Suite,Score_addp2,0),
get_hand(Players,Taken,P3,Card1s_taken3),
pts_taken(Card1s_taken3,Suite,Score_addt3,0),
get_hand(Players,Played,P3,Card1s_played3),
pts_played(Card1s_played3,Suite,Score_addp3,0),
get_hand(Players,Taken,P4,Card1s_taken4),
pts_taken(Card1s_taken4,Suite,Score_addt4,0),
get_hand(Players,Played,P4,Card1s_played4),
pts_played(Card1s_played4,Suite,Score_addp4,0),
(Pts1 -> Score_addt1 + Score_addp1 + Score_addt3 +
Score_addp3),
(Pts2 -> Score_addt2 + Score_addp2 + Score_addt4 +
Score_addp4),
Teams = [T1,T2],
member_djd(Bidder,T1),
Pts1 >= Bid,
(S1a -> S1 + Pts1),
(S2a -> S2 + Pts2),
Newscores = [S1a,S2a],
write_nl(p_score),
write_nl(Teams),
write_nl(Scores),
write_nl(Newscores).
score(Players,Teams,Played,Taken,Scores,Newscores,Bidder,Bid,Suite) :-
Scores = [S1,S2],
Players = [P1,P2,P3,P4],
get_hand(Players,Taken,P1,Card1s_taken1),
pts_taken(Card1s_taken1,Suite,Score_addt1,0),
get_hand(Players,Played,P1,Card1s_played1),
pts_played(Card1s_played1,Suite,Score_addp1,0),
get_hand(Players,Taken,P2,Card1s_taken2),
pts_taken(Card1s_taken2,Suite,Score_addt2,0),
get_hand(Players,Played,P2,Card1s_played2),
pts_played(Card1s_played2,Suite,Score_addp2,0),
get_hand(Players,Taken,P3,Card1s_taken3),
pts_taken(Card1s_taken3,Suite,Score_addt3,0),
get_hand(Players,Played,P3,Card1s_played3),
pts_played(Card1s_played3,Suite,Score_addp3,0),
get_hand(Players,Taken,P4,Card1s_taken4),
pts_taken(Card1s_taken4,Suite,Score_addt4,0),
get_hand(Players,Played,P4,Card1s_played4),
pts_played(Card1s_played4,Suite,Score_addp4,0),
(Pts1 -> Score_addt1 + Score_addp1 + Score_addt3 +
Score_addp3),
(Pts2 -> Score_addt2 + Score_addp2 + Score_addt4 +
Score_addp4),
Teams = [T1,T2],
member_djd(Bidder,T2),
Pts2 >= Bid,
(S1a -> S1 + Pts1),
(S2a -> S2 + Pts2),
Newscores = [S1a,S2a],
write_nl(p_score),
write_nl(Teams),
write_nl(Scores),
write_nl(Newscores).
score(Players,Teams,Played,Taken,Scores,Newscores,Bidder,Bid,Suite) :-
Scores = [S1,S2],
Players = [P1,P2,P3,P4],
get_hand(Players,Taken,P1,Card1s_taken1),
pts_taken(Card1s_taken1,Suite,Score_addt1,0),
get_hand(Players,Played,P1,Card1s_played1),
pts_played(Card1s_played1,Suite,Score_addp1,0),
get_hand(Players,Taken,P2,Card1s_taken2),
pts_taken(Card1s_taken2,Suite,Score_addt2,0),
get_hand(Players,Played,P2,Card1s_played2),
pts_played(Card1s_played2,Suite,Score_addp2,0),
get_hand(Players,Taken,P3,Card1s_taken3),
pts_taken(Card1s_taken3,Suite,Score_addt3,0),
get_hand(Players,Played,P3,Card1s_played3),
pts_played(Card1s_played3,Suite,Score_addp3,0),
get_hand(Players,Taken,P4,Card1s_taken4),
pts_taken(Card1s_taken4,Suite,Score_addt4,0),
get_hand(Players,Played,P4,Card1s_played4),
pts_played(Card1s_played4,Suite,Score_addp4,0),
(Pts1 -> Score_addt1 + Score_addp1 + Score_addt3 +
Score_addp3),
(Pts2 -> Score_addt2 + Score_addp2 + Score_addt4 +
Score_addp4),
Teams = [T1,T2],
member_djd(Bidder,T1),
Pts1 < Bid,
(S1a -> S1 - Bid),
(S2a -> S2 + Pts2),
Newscores = [S1a,S2a],
write_nl(bidder_went_set),
write_nl(p_score),
write_nl(Teams),
write_nl(Scores),
write_nl(Newscores).
score(Players,Teams,Played,Taken,Scores,Newscores,Bidder,Bid,Suite) :-
Scores = [S1,S2],
Players = [P1,P2,P3,P4],
get_hand(Players,Taken,P1,Card1s_taken1),
pts_taken(Card1s_taken1,Suite,Score_addt1,0),
get_hand(Players,Played,P1,Card1s_played1),
pts_played(Card1s_played1,Suite,Score_addp1,0),
get_hand(Players,Taken,P2,Card1s_taken2),
pts_taken(Card1s_taken2,Suite,Score_addt2,0),
get_hand(Players,Played,P2,Card1s_played2),
pts_played(Card1s_played2,Suite,Score_addp2,0),
get_hand(Players,Taken,P3,Card1s_taken3),
pts_taken(Card1s_taken3,Suite,Score_addt3,0),
get_hand(Players,Played,P3,Card1s_played3),
pts_played(Card1s_played3,Suite,Score_addp3,0),
get_hand(Players,Taken,P4,Card1s_taken4),
pts_taken(Card1s_taken4,Suite,Score_addt4,0),
get_hand(Players,Played,P4,Card1s_played4),
pts_played(Card1s_played4,Suite,Score_addp4,0),
(Pts1 -> Score_addt1 + Score_addp1 + Score_addt3 +
Score_addp3),
(Pts2 -> Score_addt2 + Score_addp2 + Score_addt4 +
Score_addp4),
Teams = [T1,T2],
member_djd(Bidder,T2),
Pts2 < Bid,
(S1a -> S1 + Pts1),
(S2a -> S2 - Bid),
Newscores = [S1a,S2a],
write_nl(bidder_went_set),
write_nl(p_score),
write_nl(Teams),
write_nl(Scores),
write_nl(Newscores).
pts_taken(Card1s_taken1,Suite,Score_add1,Temp) :-
Card1s_taken1 = [Card1 | Card1s_left],
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]),
(Temp2 = Temp + Pt_taken),
pts_taken(Card1s_left,Suite,Score_add1,Temp2).
pts_taken(Card1s_taken1,Suite,Score_add1,Temp) :-
Card1s_taken1 = [], ! ,
Score_add1 = Temp.
pts_played(Card1s_played1,Suite,Score_add1,Temp) :-
Card1s_played1 = [Card1 | Card1s_left],
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]),
(Temp2 = Temp + Pt_played),
pts_played(Card1s_left,Suite,Score_add1,Temp2).
pts_played(Card1s_played1,Suite,Score_add1,Temp) :-
Card1s_played1 = [], ! ,
Score_add1 = Temp.
%/* lead highest card left */
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1) :-
\+(am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite)),
have_highest_card_left(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite),
Card1 = Cardx,
%/* write_nl(have_highest_card), */
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]).
%/* take point card - last (with smallest card that woll take because sorted*/
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1) :-
am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite),
pt_card_played(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardp,Suite),
have_higher_card_left(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite),
\+(partner(P2,Newwhohigh1)),
Card1 = Cardx,
%/* write_nl(take_pt_card_last), */
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]).
%/* save point cards playing last */
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1) :-
am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite),
can_save_point(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite),
Card1 = Cardx,
%/* write_nl(can_save_point), */
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]).
%/* opponent has played high card - plays small card */
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1) :-
\+(have_highest_card_left(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardw,Suite)),
\+(partner(P2,Newwhohigh1)),
have_small_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite),
Card1 = Cardx,
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]).
%/* write_nl(play_small_card). */
%/* partner has played high card - plays point card */
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1) :-
\+(have_highest_card_left(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardw,Suite)),
partner(P2,Newwhohigh1),
have_point_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite),
Card1 = Cardx,
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]).
%/* write_nl(play_point_card). */
%/* no special rule applied so play any card */
best_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,Card1,
Suite,Newhigh1,Newwhohigh1) :-
H2 = [Card1 | H3],
card([Card1,Val,Suite,Name,Pt_taken,Pt_played]).
have_highest_card_left(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite) :-
member_djd(Cardx,H2),
card([Cardx,Val,Suite,Name,Pt_taken,Pt_played]),
\+(exists_higher_card_not_in_list(Newcards1,Suite,Val,Newplayed1)).
exists_higher_card_not_in_list(Newcards1,Suite,Val,Newplayed1) :-
card([Card2,Val2,Suite,Name,Pt_taken,Pt_played]),
Val2 > Val,
\+(sub_member(Card2,Newplayed1,Newcards1)).
sub_member(Card2,Newplayed1,Newcards1) :-
member_djd(Pl,Newplayed1),
\+(member_djd(Card2,Newcards1)),
member_djd(Card2,Pl).
point_card_played(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite) :-
member_djd(Card,Newcards1),
card([Card,Val,Suite,Name,Pt_taken,Pt_played]),
Pt_taken > 0.
am_first_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite) :-
length_djd(Newcards1,Len),
Len = 0.
am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite) :-
length_djd(Newcards1,Len),
Len = 3.
am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite) :-
length_djd(Newcards1,Len),
succ_player(P2,P3),
is_out(P3),
Len = 2.
am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite) :-
length_djd(Newcards1,Len),
succ_player(P2,P3),
is_out(P3),
succ_player(P3,P4),
is_out(P4),
Len = 1.
point_card_may_be_played(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite) :-
\+(am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Card1,Suite)),
card([Card2,Val2,Suite,Name,Pt_taken,Pt_played]),
Pt_taken > 0,
\+(sub_member(Card2,Newplayed1)).
can_save_point(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite) :-
am_last_to_play(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite),
member_djd(Cardx,H2),
card([Cardx,Val,Suite,Name,Pt_taken,Pt_played]),
Pt_taken > 0,
\+(exists_higher_card_in_list(Val,Newcards1,Suite)).
exists_higher_card_in_list(Val,Newcards1,Suite) :-
member_djd(Card2,Newcards1),
card([Card2,Val2,Suite,Name,Pt_taken,Pt_played]),
Val2 > Val.
partner_played_highest_card_so_far(Players,P2,H2,Newplayed1,Newtaken1,
Newcards1,Card1,Suite,Newhigh1,Newwhohigh1) :-
partner(P2,Newwhohigh1).
have_small_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite) :-
member_djd(Cardx,H2),
card([Cardx,Val,Suite,Name,Pt_taken,Pt_played]),
Val < 10.
have_point_card(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite) :-
member_djd(Cardx,H2),
card([Cardx,Val,Suite,Name,Pt_taken,Pt_played]),
Pt_taken > 0.
display_hand(H) :-
H = [C | H2],
card([C,Val,Suite,Name,Pt_taken,Pt_played]),
write_bl(C),
write_nl(Name),
display_hand(H2).
display_hand([]).
pt_card_played(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardp,Suite) :-
member_djd(Cardp,Newcards1),
card([Cardp,Val,Suite,Name,Pt_taken,Pt_played]),
Pt_taken > 0.
have_higher_card_left(Players,P2,H2,Newplayed1,Newtaken1,Newcards1,
Cardx,Suite) :-
member_djd(Cardx,H2),
card([Cardx,Val,Suite,Name,Pt_taken,Pt_played]),
\+(exists_higher_card_in_list(Newcards1,Suite,Val)).
exists_higher_card_in_list(Newcards1,Suite,Val) :-
card([Card2,Val2,Suite,Name,Pt_taken,Pt_played]),
Val2 > Val,
member_djd(Card2,Newcards1).
sort_by_val(H,Hs,Suite) :-
get_vals(H,V,Suite),
sort(V,Vs),
get_nos(Vs,Hs,Suite).
get_vals([],[],Suite).
get_vals(H,V,Suite) :-
H = [No | Nos],
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
get_vals(Nos,Vals,Suite),
V = [Val | Vals].
get_nos([],[],Suite).
get_nos(V,H,Suite) :-
V = [Val | Vals],
card([No,Val,Suite,Name,Pt_taken,Pt_played]),
get_nos(Vals,Nos,Suite),
H = [No | Nos].
minimimd(N1,N2,N1) :- N1 =< N2.
minimimd(N1,N2,N2) :- N2 =< N1.
can_bid(Guess,Hand,Suite1,Bidder) :-
member_djd(S,[diamonds,clubs,spades,hearts]),
can_bid_suite(Guess2,Hand,S,Bidder),
Suite1 = S,
minimimd(7,Guess2,Guess).
can_bid(0,Hand,pass,Bidder).
bind_cs(0.6,0.04,0.04,1.0,0.2,dennis).
bind_cs(0.6,0.04,0.04,1.0,0.2,dick).
bind_cs(0.5,0.05,0.05,1.0,0.2,sussy).
bind_cs(0.5,0.05,0.05,1.0,0.2,john).
can_bid_suite(Guess,Hand,Suite1,Bidder) :-
discard_non_suite(Hand,Nh1,[],Handsuite,Suite1),
get_vals(Handsuite,Vals,Suite1),
no_high_cards(Vals,No_high),
%/* write_bl(no_high),write_nl(No_high), */
tot_face(Vals,Tot_face),
%/* write_bl(no_face),write_nl(Tot_face), */
tot_pts(Vals,Tot_pts),
%/* write_bl(no_pts),write_nl(Tot_pts), */
no_sure(Vals,No_sure),
%/* write_bl(no_sure),write_nl(No_sure), */
length_djd(Vals,No_cds),
%/* write_bl(no_cds),write_nl(No_cds), */
bind_cs(C1,C2,C3,C4,C5,Bidder),
(Guessf1 = C1 * No_high) ,
(Guessf2 = Guessf1 + C2 * Tot_face),
(Guessf3 = Guessf2 + C3 * Tot_pts),
(Guessf4 = Guessf3 + C4 * No_sure),
(Guessf5 = Guessf4 + C5 * No_cds),
(Guess = floor(Guessf5)).
no_high_cards(Vals,6) :-
member_djd(17,Vals),
member_djd(16,Vals),
member_djd(15,Vals),
member_djd(14,Vals),
member_djd(13,Vals),
member_djd(12,Vals),!.
no_high_cards(Vals,5) :-
member_djd(17,Vals),
member_djd(16,Vals),
member_djd(15,Vals),
member_djd(14,Vals),
member_djd(13,Vals),!.
no_high_cards(Vals,4) :-
member_djd(17,Vals),
member_djd(16,Vals),
member_djd(15,Vals),
member_djd(14,Vals),!.
no_high_cards(Vals,3) :-
member_djd(17,Vals),
member_djd(16,Vals),
member_djd(15,Vals),!.
no_high_cards(Vals,2) :-
member_djd(17,Vals),
member_djd(16,Vals),!.
no_high_cards(Vals,1) :-
member_djd(17,Vals),!.
no_high_cards(Vals,0) :-
\+(member_djd(17,Vals)),!.
tot_face([],0).
tot_face(Vals,Tot_face) :-
Vals = [V1 | Vs],
V1 > 10,!,
tot_face(Vs,Tot2),
(Tot_face = V1 + Tot2).
tot_face(Vals,Tot_face) :-
Vals = [V1 | Vs],
V1 =< 10,!,
tot_face(Vs,Tot2),
Tot_face = Tot2.
tot_pts([],0).
tot_pts(Vals,Tot_pts) :-
Vals = [V1 | Vs],
V1 > 9,
V1 < 14,!,
tot_pts(Vs,Tot2),
(Tot_pts = V1 + Tot2).
tot_pts(Vals,Tot_pts) :-
Vals = [V1 | Vs],
V1 < 10,!,
tot_pts(Vs,Tot2),
Tot_pts = Tot2.
tot_pts(Vals,Tot_pts) :-
Vals = [V1 | Vs],
V1 < 10,!,
tot_pts(Vs,Tot2),
Tot_pts = Tot2.
no_sure(Vals,2) :-
member_djd(2,Vals),
member_djd(17,Vals),!.
no_sure(Vals,1) :-
member_djd(2,Vals),
\+(member_djd(17,Vals)),!.
no_sure(Vals,1) :-
\+(member_djd(2,Vals)),
member_djd(17,Vals),!.
no_sure(Vals,0) :-
\+(member_djd(2,Vals)),
\+(member_djd(17,Vals)),!.
%trace(true)?
play_game(R,S)?
retract_out(Players) :-