function win = play ( )

%*****************************************************************************80
%
%% play() plays a game of clock solitaire.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 April 2022
%
%  Author:
%
%    John Burkardt
%
%  Output:
%
%    logical WIN: is true if this game was won.
%
  verbose = false;
%
%  Lay out the cards in 13 piles of 4 cards each.
%
  pile = piles_deal ( );
  k = 0;

  while ( true )
%
%  On first step, choose a pile i at random.
%
    if ( k == 0 )
      i = randi ( [ 1, 13 ], 1 );
    end
%
%  Select the top card from pile i.
%
    j = pile ( i, 1 );
%
%  If this card has already been used, we have lost.
%
    if ( 0 < j )
      win = false;
      if ( verbose )
        fprintf ( 1, '  Lost.  Pile %d is exhausted.\n', i );
      end
      return
    end
%
%  Turn the card over.
%
    pile(i,1) = - pile(i,1);
    j = - j;
%
%  Move the card to the bottom.
%
    pile(i,1:4) = circshift ( pile(i,1:4), 3 );
%
%  Report.
%
    k = k + 1;
    jrank = card_rank ( j );
    jsuit = card_suit ( j );

    if ( verbose )
      fprintf ( 1, '  %2d  %2d  %2d  %2d  %s\n', k, i, j, jrank, jsuit );
    end

    if ( k == 52 )
      break
    end
%
%  Determine the next pile.
%
    i = jrank;

  end 

  win = true;

  return
end

