home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Games / eog_disc2.iso / encyclop / wingames / cardws12 / pyramid.cdl < prev    next >
Text File  |  1993-11-27  |  6KB  |  315 lines

  1. //⌐ David Jean, 1993
  2. game pyramid is 29 by 17;
  3.  
  4. //A1 D1 D2 
  5. //A2 
  6. //A3 
  7. //A4 
  8. //A5 
  9. //A6 
  10. //A7
  11.  
  12. {--------------------------------------------------------------------------}
  13.  
  14. procedure About is
  15. begin
  16.   Clear 'About Pyramid';
  17.   write('Rules from : The Complete book of Solitaire & Patience Games by \n');
  18.   write('Albert H. Morehead & Geoffrey Mott-Smith, Bantam Book, 1977.\n');
  19.   write('Program : ⌐ David Jean, 1993.\n');
  20. end;
  21.  
  22. stack A1;
  23. stack A2;
  24. stack A3;
  25. stack A4;
  26. stack A5;
  27. stack A6;
  28. stack A7;
  29. stack D2;
  30.  
  31. function NextStack(fs : stack): stack is
  32. var ls : stack;
  33. begin
  34.   ls:=Cursor;
  35.   with it do
  36.     if ls=fs then
  37.       return it
  38.     else
  39.       ls:=it
  40.   for A1, A2, A3, A4, A5, A6, A7;    
  41.   return fs;
  42. end;
  43.  
  44.  
  45. {--------------------------------------------------------------------------}
  46.  
  47. stack D1 is
  48.   X := 21;
  49.   Y := 3;
  50.   Direction := over;
  51.   w := 3;
  52.   h := 3;
  53.   //****************************
  54.   Start is
  55.     begin
  56.     Add Ace+Spade .. King+Diamond;
  57.     Shuffle;
  58.     [0]:=CrossCard;
  59.     end;
  60.   //****************************
  61.   SelectLeft(Spos : Index) is
  62.     if !>0 then
  63.       if ([!] / DeckSize)=Shaded then
  64.         Turn [!] side up
  65.       else
  66.         Turn [!] Side Shaded;
  67.   //****************************
  68.   SelectRight(Spos : Index) is
  69.     if !>0 then
  70.       begin
  71.       if D2!>0 then Turn D2[D2!] side up; 
  72.       Turn [!] side up;
  73.       Pull 1 to D2;
  74.       end;
  75.   //****************************
  76.   Help is
  77.     begin
  78.     Clear 'The Stock';
  79.     Write('The topmost card of this pile is available to match on The Tableau.\n\n');
  80.     Write('You can click here with the right button to move a card to The Waste Pile.\n');
  81.     Wait 'About...' About;
  82.     end;
  83. end D1;
  84.  
  85.  
  86. stack D2 is
  87.   X := 25;
  88.   Y := 3;
  89.   Direction := over;
  90.   w := 3;
  91.   h := 3;
  92.   //****************************
  93.   SelectLeft From D1;
  94.   //****************************
  95.   Help is
  96.     begin
  97.     Clear 'The Waste Pile';
  98.     Write('The topmost card of this pile is available to match on The Tableau.\n\n');
  99.     Wait 'About...' About;
  100.     end;
  101. end D2;
  102.  
  103. {--------------------------------------------------------------------------}
  104.  
  105. stack A1 is
  106.   X := 14;
  107.   Y := 2;
  108.   Direction := horizontal;
  109.   W := 3;
  110.   H := 3;
  111.   //****************************
  112.   Start is
  113.     begin
  114.     [0]:=EmptySpace;
  115.     Pull 1 from D1;
  116.     Draw D1;
  117.     end;
  118.   //****************************
  119.   SelectLeft(Spos : Index) is
  120.   var nx : stack;
  121.     begin
  122.     if Spos>! then Spos:=!;
  123.     nx:=NextStack(self);
  124.     if (nx=self) or
  125.        ((nx[Spos]=EmptySpace) and (nx[Spos + 1]=EmptySpace)) then
  126.       if [Spos]<>EmptySpace then 
  127.         if ([Spos] / DeckSize)=Shaded then
  128.           Turn [Spos] side up
  129.         else
  130.           Turn [Spos] Side Shaded;
  131.     end;
  132.   //****************************
  133.   Help is
  134.     begin
  135.     Clear 'The Tableau';
  136.     Write('From the available cards, discard pairs of card that total 13.\n');
  137.     Write('Kings are discarded alone.\n');
  138.     Write('Suit is not important.\n\n');
  139.     Write('Available cards are those not covered by others.\n\n');
  140.     Write('The goal is to empty the Tableau, The Stock and The Waste Pile.\n'); 
  141.     Wait 'About...' About;
  142.     end;
  143. end A1;
  144.  
  145. stack A2 from A1 is
  146.   X := 12;
  147.   Y := 4;
  148.   W := 7;
  149.   //****************************
  150.   Start is
  151.     begin
  152.     [0]:=EmptySpace;
  153.     Pull 2 from D1;
  154.     Draw D1;
  155.     end;
  156. end A2;
  157.  
  158. stack A3 from A1 is
  159.   X := 10;
  160.   Y := 6;
  161.   W := 11;
  162.   //****************************
  163.   Start is
  164.     begin
  165.     [0]:=EmptySpace;
  166.     Pull 3 from D1;
  167.     Draw D1;
  168.     end;
  169. end A3;
  170.  
  171. stack A4 from A1 is
  172.   X := 8;
  173.   Y := 8;
  174.   W := 15;
  175.   //****************************
  176.   Start is
  177.     begin
  178.     [0]:=EmptySpace;
  179.     Pull 4 from D1;
  180.     Draw D1;
  181.     end;
  182. end A4;
  183.  
  184. stack A5 from A1 is
  185.   X := 6;
  186.   Y := 10;
  187.   W := 19;
  188.   //****************************
  189.   Start is
  190.     begin
  191.     [0]:=EmptySpace;
  192.     Pull 5 from D1;
  193.     Draw D1;
  194.     end;
  195. end A5;
  196.  
  197. stack A6 from A1 is
  198.   X := 4;
  199.   Y := 12;
  200.   W := 23;
  201.   //****************************
  202.   Start is
  203.     begin
  204.     [0]:=EmptySpace;
  205.     Pull 6 from D1;
  206.     Draw D1;
  207.     end;
  208. end A6;
  209.  
  210. stack A7 from A1 is
  211.   X := 2;
  212.   Y := 14;
  213.   W := 27;
  214.   //****************************
  215.   Start is
  216.     begin
  217.     [0]:=EmptySpace;
  218.     Pull 7 from D1;
  219.     Draw D1;
  220.     end;
  221. end A7;
  222.  
  223. {--------------------------------------------------------------------------}
  224.  
  225. predicate win? is
  226.   return (A1[1]=EmptySpace) and (D1!=0) and (D2!=0);
  227.  
  228. const
  229.   ctotal := 1, cremove := 2, ccancel := 3;
  230.  
  231. var
  232.   total, scard : integer;
  233.  
  234. procedure CheckStack(mode : integer) is
  235. var i : integer;
  236. begin
  237.   total:=0;
  238.   scard:=0;
  239.   with it do
  240.     begin
  241.     i:=1;
  242.     while i<=it! do
  243.       begin
  244.       if (it[i] / DeckSize)=Shaded then
  245.         begin
  246.         scard:=scard+1;
  247.         if mode=ctotal then total:=total+(it[i] mod 13)+1 
  248.         else if mode=cremove then it[i]:=EmptySpace
  249.         else Turn it[i] side up; 
  250.         end;
  251.       i:=i+1;
  252.       end;
  253.     end
  254.   for A1, A2, A3, A4, A5, A6, A7;    
  255.   with it do
  256.     if (it[it!] / DeckSize)=Shaded then
  257.       begin
  258.       scard:=scard+1;
  259.       if mode=ctotal then total:=total+(it[it!] mod 13)+1 
  260.       else if mode=cremove then remove it[it!]
  261.       else Turn it[it!] side up;
  262.       end
  263.   for D1, D2;
  264. end;
  265.  
  266. predicate Integrity? is
  267. begin
  268.   CheckStack(ctotal);
  269.   if total=13 then CheckStack(cremove)
  270.   else if scard>=2 then CheckStack(ccancel);
  271.   return TRUE;
  272. end;
  273.  
  274. function BitAvail : integer is
  275. var r, i : integer;
  276.     nx : stack;
  277. begin
  278.   r:=0;
  279.   with it do
  280.     if it!>0 then r:=r or (1 << (it[it!] mod 13))
  281.   for D1, D2;
  282.   with it do
  283.     begin
  284.     i:=1;
  285.     nx:=NextStack(it);
  286.     while i<=it! do
  287.       begin
  288.       if (it=nx) or
  289.          ((nx[i]=EmptySpace) and (nx[i + 1]=EmptySpace)) then
  290.         if it[i]<>EmptySpace then 
  291.           r:=r or (1 << (it[i] mod 13));
  292.       i:=i+1;
  293.       end;
  294.     end
  295.   for A1, A2, A3, A4, A5, A6, A7;
  296.   return r;
  297. end;
  298.  
  299. predicate Loose? is
  300. var r, i : integer;
  301. begin
  302.   if D1!>0 then return FALSE;
  303.   r:=BitAvail;
  304.   i:=0;
  305.   while i<6 do
  306.     begin
  307.     if ((r and (1 << i))>0) and ((r and (1 << (11-i)))>0) then
  308.       return FALSE;
  309.     i:=i+1;
  310.     end;
  311.   if (r and (1 << 12))>0 then return FALSE;
  312.   return TRUE;
  313. end;
  314.  
  315. order D1, D2, A1, A2, A3, A4, A5, A6, A7.