home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_30.arc / BRIDGE.PRO next >
Text File  |  1986-11-20  |  8KB  |  369 lines

  1.  
  2. add_to_list(X, Y, L) :-
  3.     not(member(X, Y)),
  4.     append([X], Y, L).
  5.  
  6. build_hand(Suit) :-
  7.     values(Suit, Honor, Points),
  8.     Honor = small,
  9.     add_small(Suit, Points).
  10. build_hand(Suit) :-
  11.     values(Suit, y, 1),
  12.     hand(Suit, L),
  13.     add_to_list(jack, L, Newlist),
  14.     retract(hand(Suit, L)),
  15.     asserta(hand(Suit, Newlist)).
  16. build_hand(Suit) :-
  17.     values(Suit, y, 2),
  18.     hand(Suit, L),
  19.     add_to_list(queen, L, Newlist),
  20.     retract(hand(Suit, L)),
  21.     asserta(hand(Suit, Newlist)).
  22. build_hand(Suit) :-
  23.     values(Suit, y, 3),
  24.     hand(Suit, L),
  25.     add_to_list(king, L, Newlist),
  26.     retract(hand(Suit, L)),
  27.     asserta(hand(Suit, Newlist)).
  28. build_hand(Suit) :-
  29.     values(Suit, y, 4),
  30.     hand(Suit, L),
  31.     add_to_list(ace, L, Newlist),
  32.     retract(hand(Suit, L)),
  33.     asserta(hand(Suit, Newlist)).
  34.  
  35. values(clubs, small, 1).
  36. values(clubs, y, 1).
  37. values(clubs, n, 2).
  38. values(clubs, n, 3).
  39. values(clubs, n, 4).
  40. values(diamonds, small, 1).
  41. values(diamonds, n, 1).
  42. values(diamonds, n, 2).
  43. values(diamonds, y, 3).
  44. values(diamonds, y, 4).
  45. values(hearts, small, 1).
  46. values(hearts, y, 1).
  47. values(hearts, y, 2).
  48. values(hearts, y, 3).
  49. values(hearts, y, 4).
  50. values(spades, small, 1).
  51. values(spades, y, 1).
  52. values(spades, y, 2).
  53. values(spades, y, 3).
  54. values(spades, y, 4).
  55.  
  56. major(spades).
  57. major(hearts).
  58.  
  59. hand(clubs, [jack, x]).
  60. hand(diamonds, [ace, king, x]).
  61. hand(hearts, [ace, king, queen, jack, x]).
  62. hand(spades, [ace, king, queen, jack, x]).
  63.  
  64. points(clubs, 1, 2).
  65. points(diamonds, 7, 3).
  66. points(hearts, 11, 5).
  67. points(spades, 11, 5).
  68.  
  69. clear_suits :- retractall(hand(Suit, Hand)).
  70. clear_suits :-
  71.     asserta(hand(spades, [])),
  72.     asserta(hand(hearts, [])),
  73.     asserta(hand(diamonds, [])),
  74.     asserta(hand(clubs, [])).
  75.  
  76. find_longest_suit :-
  77.     retractall(longest(Suitname, Count)),
  78.     asserta(longest(none, 0)).
  79. find_longest_suit :-
  80.     points(Suit, Points, Count),
  81.     longest(Suitname, Suitcount),
  82.     Count > Suitcount,
  83.     retract(longest(Suitname, Suitcount)),
  84.     asserta(longest(Suit, Count)).
  85.  
  86. add_small(Suit, 0) :- !.
  87. add_small(Suit, C) :-
  88.     hand(Suit, L),
  89.     append(L, [x], Newlist),
  90.     retract(hand(Suit, L)),
  91.     asserta(hand(Suit, Newlist)),
  92.     X is C - 1,
  93.     add_small(Suit, X).
  94.  
  95. eval_hand :-
  96.     retractall(points(Suit, Points, Count)),
  97.     asserta(points(spades, 0, 0)),
  98.     asserta(points(hearts, 0, 0)),
  99.     asserta(points(diamonds, 0, 0)),
  100.     asserta(points(clubs, 0, 0)).
  101. eval_hand :- get_count(spades).
  102. eval_hand :- get_count(hearts).
  103. eval_hand :- get_count(diamonds).
  104. eval_hand :- get_count(clubs).
  105. eval_hand :- count_hand.
  106.  
  107. hand_count(30).
  108.  
  109. count_hand :-
  110.     retractall(hand_count(X)),
  111.     asserta(hand_count(0)).
  112. count_hand :-
  113.     points(Suit, Points, Count),
  114.     hand_count(X),
  115.     Newpoints is X + Points,
  116.     retractall(hand_count(X)),
  117.     asserta(hand_count(Newpoints)).
  118. count_hand :-
  119.     hand_count(Points),
  120.     print('Your hand is worth ', Points, ' points').
  121.  
  122. balanced_hand :-
  123.     retractall(even_distr(X)),
  124.     asserta(even_distr(no)).
  125. balanced_hand :-
  126.     points(Suit, Points, Count),
  127.     Count < 3,
  128.     !.
  129. balanced_hand :-
  130.     points(Suit, Points, Count),
  131.     Count > 5,
  132.     !.
  133. balanced_hand :-
  134.     retractall(even_distr(X)),
  135.     asserta(even_distr(yes)).
  136.  
  137. minor(diamonds).
  138. minor(clubs).
  139.  
  140. print_hand :- print('Your hand is:').
  141. print_hand :-
  142.     hand(Suit, List),
  143.     print(Suit, ':'),
  144.     tab(5),
  145.     prin(List),
  146.     nl.
  147.  
  148. bid([1, spades]).
  149.  
  150. get_values :-
  151.     print('Enter your hand at the prompts'),
  152.     get_suits(spades),
  153.     get_suits(hearts),
  154.     get_suits(diamonds),
  155.     get_suits(clubs).
  156.  
  157. even_distr(no).
  158.  
  159. major_suit(spades).
  160. major_suit(hearts).
  161.  
  162. get_count(Suit) :-
  163.     values(Suit, Honor, Points),
  164.     Honor = small,
  165.     points(Suit, P, Count),
  166.     Newcount is Count + Points,
  167.     retract(points(Suit, P, Count)),
  168.     asserta(points(Suit, P, Newcount)).
  169. get_count(Suit) :-
  170.     values(Suit, Honor, Points),
  171.     not(Honor = small),
  172.     Honor = y,
  173.     points(Suit, P, Count),
  174.     Newcount is Count + 1,
  175.     Newpoints is Points + P,
  176.     retract(points(Suit, P, Count)),
  177.     asserta(points(Suit, Newpoints, Newcount)).
  178. get_count(Suit) :-
  179.     points(Suit, Points, Count),
  180.     Count > 4,
  181.     Newpoints is Points + Count - 4,
  182.     retract(points(Suit, Points, Count)),
  183.     asserta(points(Suit, Newpoints, Count)).
  184.  
  185. minor_suit(diamonds).
  186. minor_suit(clubs).
  187.  
  188. eval_suit(Suit) :-
  189.     retractall(points(Suit, Points, Count)),
  190.     assera(points(Suit, 0, 0)),
  191.     get_count(suit).
  192.  
  193. get_suits(Suit) :-
  194.     print(Suit),
  195.     print('Ace - y/n'),
  196.     read(Ace),
  197.     asserta(values(Suit, Ace, 4)),
  198.     print('King - y/n'),
  199.     read(King),
  200.     asserta(values(Suit, King, 3)),
  201.     print('Queen - y/n'),
  202.     read(Queen),
  203.     asserta(values(Suit, Queen, 2)),
  204.     print('Jack - y/n'),
  205.     read(Jack),
  206.     asserta(values(Suit, Jack, 1)),
  207.     print('How many small ', Suit, ' are in your hand?  '),
  208.     read(Small),
  209.     asserta(values(Suit, small, Small)).
  210.  
  211. why :- print_hand.
  212. why :-
  213.     hand_count(Points),
  214.     Points < 13,
  215.     print('You have ', Points, ' points. This is not enough
  216. to\nopen'),
  217.     !.
  218. why :-
  219.     bid([1, notrump]),
  220.     hand_count(Points),
  221.     print('Your hand is worth ', Points, ' points'),
  222.     print('You have balanced distribution and between 16
  223. and\n18 points'),
  224.     print('In this situation you bid 1 notrump'),
  225.     !.
  226. why :-
  227.     bid([1, X]),
  228.     points(X, Points, Count),
  229.     longest(Suitname1, Count),
  230.     longest(Suitname2, Count),
  231.     not(Suitname1 = Suitname2),
  232.     print('You have 13 or more points'),
  233.     print('You have 2 suits each with ', Count, ' cards.'),
  234.     print('Bid either the higher ranking of two
  235. touching\nsuits'),
  236.     print('or the lower ranking if the suits do not\ntouch'),
  237.     !.
  238. why :-
  239.     bid('1 club'),
  240.     print('You do not have a biddable major suit'),
  241.     print('Your diamond suit does not contain an honor'),
  242.     print('Your club suit is not really biddable, but
  243. you\nmust open'),
  244.     print('This is a short club situation'),
  245.     !.
  246. why :-
  247.     bid([1, X]),
  248.     points(X, Points, Count),
  249.     print('You have ', Points, ' points and ', Count, '
  250. Cards\n        in ', X),
  251.     print('Bid your longest suit').
  252.  
  253. touching(spades, hearts).
  254. touching(hearts, diamonds).
  255. touching(diamonds, clubs).
  256. touching(clubs, spades).
  257.  
  258. decide_bid :- retractall(bid(X)).
  259. decide_bid :- retractall(values(Suit, Honor, Points)).
  260. decide_bid :- get_values.
  261. decide_bid :- eval_hand.
  262. decide_bid :- clear_suits.
  263. decide_bid :- build_hand(spades).
  264. decide_bid :- build_hand(hearts).
  265. decide_bid :- build_hand(diamonds).
  266. decide_bid :- build_hand(clubs).
  267. decide_bid :- print_hand.
  268. decide_bid :-
  269.     hand_count(Count),
  270.     Count < 13,
  271.     print('Pass'),
  272.     asserta(bid(pass)),
  273.     !.
  274. decide_bid :- balanced_hand.
  275. decide_bid :-
  276.     even_distr(yes),
  277.     hand_count(Count),
  278.     Count > 15,
  279.     Count < 19,
  280.     print('1 notrump'),
  281.     asserta(bid([1, notrump])),
  282.     !.
  283. decide_bid :- find_longest_suit.
  284. decide_bid :- find_next_long_suit.
  285. decide_bid :-
  286.     longest(Suit1, Count),
  287.     Count > 4,
  288.     longest(Suit2, Count),
  289.     not(Suit1 = Suit2),
  290.     touching(Suit1, Suit2),
  291.     print('1 ', Suit1),
  292.     asserta(bid([1, Suit1])),
  293.     !.
  294. decide_bid :-
  295.     longest(Suit1, Count),
  296.     Count > 4,
  297.     longest(Suit2, Count),
  298.     not(Suit1 = Suit2),
  299.     print('1 ', Suit2),
  300.     asserta(bid([1, Suit2])),
  301.     !.
  302. decide_bid :-
  303.     longest(Suit, Count),
  304.     Count > 5,
  305.     print('1 ', Suit),
  306.     asserta(bid([1, Suit])),
  307.     !.
  308. decide_bid :-
  309.     points(Suit, Points, Count),
  310.     Count > 4,
  311.     major(Suit),
  312.     print('1 ', Suit),
  313.     asserta(bid([1, Suit])),
  314.     !.
  315. decide_bid :-
  316.     points(Suit, Points, Count),
  317.     Count > 3,
  318.     minor(Suit),
  319.     values(Suit, Honor, Pts),
  320.     Honor = y,
  321.     print('1 ', Suit),
  322.     asserta(bid([1, Suit])),
  323.     !.
  324. decide_bid :-
  325.     points(clubs, Points, Count),
  326.     Count > 2,
  327.     print('1 club'),
  328.     asserta(bid('1 club')),
  329.     !.
  330. decide_bid :-
  331.     longest(Suit1, Count),
  332.     Count > 3,
  333.     longest(Suit2, Count),
  334.     not(Suit1 = Suit2),
  335.     touching(Suit1, Suit2),
  336.     print('1 ', Suit1),
  337.     asserta(bid([1, Suit1])),
  338.     !.
  339. decide_bid :-
  340.     longest(Suit1, Count),
  341.     Count > 3,
  342.     longest(Suit2, Count),
  343.     not(Suit1 = Suit2),
  344.     print('1 ', Suit2),
  345.     asserta(bid([1, Suit2])),
  346.     !.
  347. decide_bid :-
  348.     longest(Suit, Count),
  349.     Count > 3,
  350.     print('1 ', Suit),
  351.     asserta(bid([1, Suit])),
  352.     !.
  353.  
  354. find_next_long_suit :-
  355.     longest(Suitname, Suitcount),
  356.     points(Suit, _, Count),
  357.     not(Suit = Suitname),
  358.     Count = Suitcount,
  359.     asserta(longest(Suit, Count)).
  360.  
  361. append([], X, X).
  362. append([X, ..L1], L2, [X, ..L3]) :- append(L1, L2, L3).
  363.  
  364. member(X, [X, .._]).
  365. member(X, [_, ..Y]) :- member(X, Y).
  366.  
  367. longest(spades, 5).
  368. longest(hearts, 5).
  369.