//© David Jean, 1993
game maire is 32 by 13;

// D1    Discard 
// A1
// A2

{--------------------------------------------------------------------------}

{****c1 et c2 sont du meme Rang}
predicate SameRank?(c1, c2 : Card) is
  return (c1 mod 13) = (c2 mod 13);

{--------------------------------------------------------------------------}

stack D1;
stack A1;
stack A2;

var s : stack;
    tur : integer;
    info : boolean;

procedure WaitInfo;

procedure UpDate is
  if info then 
    begin
    Clear 'Informations' At 7,2 Is 20 by 3;
    Write('Turn : ',tur,' / 3\n');
    Write('Remaining Cards : ',D1!+A1!+A2!);
    WaitInfo;
    end
  else Clear;

procedure About is
begin
  Clear 'About Maire';
  write('Rules from : ?\n');
  write('Program : © David Jean, 1993.\n');
  if Info then Wait 'Info...' UpDate;
end;

procedure Doinfo is
begin 
  info := not info;
  UpDate;
end;

procedure WaitInfo is
  if info then
    Wait 'Info Off' DoInfo
  else
    Wait 'Info On' DoInfo;

stack Discard is
  x := 28;
  y := 2;
  Direction := over;
  w := 4;
  h := 3;
  //****************************
  Start is
    UpDate;
end Discard;

stack A1 is
  X := 2;
  Y := 6;
  Direction := right;
  w := 30;
  h := 3;
  //****************************
  Start is
    begin
    Pull 1 From D1;
    Turn [1] side up;
    end;
  //****************************
  SelectFrom(Spos : Index) is
    if !>0 then Pull 1 to Cursor;
  //****************************
  SelectTo(Spos : Index) is
    if !>0 then
      if SameRank?([!],Cursor[1]) then
        begin
        Pull 1 to Discard;
	Pull 1 from Cursor to Discard;
	UpDate;
        end;
  //****************************
  Help is
    begin
    Clear 'The Tableau';
    Write('Any new card dealt from The Stock can be used to form a pair ');
    Write('with its neighbor to the left or the rightmost card ');
    Write('from the other pile.\n');
    Write('Pairs are removed.\n\n');
    Write('The goal is to empty The Tableau and The Stock.\n');
    Wait 'About...' About;
    if Info then Wait 'Info...' UpDate;
    WaitInfo;
    end;
end A1;

stack A2 from A1 is
  X := 2;
  Y := 10;
end A2;

stack D1 is
  X := 2;
  Y := 2;
  Direction := over;
  w := 4;
  h := 3;
  //****************************
  Start is
    begin
    Add Ace+Spade .. King+Diamond;
    Turn [1..52] side down;
    Shuffle;
    s := A1;
    tur := 1;
    info:=TRUE;
    end;
  //****************************
  Select(Spos : Index) is
    if !>0 then
      begin
      Pull 1 to s;
      Turn s[s!] side up;
      if s=A1 then s:=A2 else s:=A1;	
      end
    else if tur<3 then
      begin
      tur := tur + 1;
      Pull A1! from A1;
      Pull 1 to A1;
      Pull A2! from A2;
      Pull 1 to A2;
      Shuffle;
      Turn [1..!] side down;
      UpDate;
      end;
  //****************************
  Help is
    begin
    Clear 'The Stock';
    Write('Click here to deal a card to one of the pile in the Tableau Alternatly.\n\n');
    Write('You have three pass to complete the game.\n');
    Wait 'About...' About;
    if Info then Wait 'Info...' UpDate;
    WaitInfo;
    end;
end D1;

predicate Win? is 
  return (A1!=0) and (A2!=0) and (D1!=0);

order D1, A1, A2, Discard.
