function stratego(varargin)
% Two player game of Stratego played on two computers

% getArgs function allows for optional arguments to specify URLs, paths,
% who goes first, how the board is selected, etc.   I really went
% overboard here with all the ways to determine arguments.  This
% is not suggested for beginning programmers!
%
% Arguments:
%    sharePath (string)     path to shared files
%                              URL - access via Web
%                              file path - access via DropBox
%                              default - .
%    board (string)        file name for starting board
%                              contains only the user's side of board
%                              .xls file - data in Excel file
%                              .dat file - text file, 4 rows, 10 columns
%                              default - use built-in sample board
%    startFirst (logical)  true for starting player
%                          false (default) for second player
%    hist (string)         name of history (.log) file
%                             exist - resume game from end
%                             ~exist - new game
%                             contains complete starting board
%                                and a log of plays
%                             default - create unique file name

args = getArgs(varargin);
args.sharePath              % displaying return values, just for testing
args.sharePathType          %   purposes
args.board
args.startFirst
args.hist

board = getBoard();

displayBoard(board);
if ~args.startFirst
   fprintf('Please wait for other player''s move')
else
   board = makeMove(board);
end

while ~Done(board)
   waitForOthersMove();
   displayBoard(board)
   if ~Done(board)
      board = makeMove(board);
   end
   pause(1)
end

displayWinner(board)
end

% -------------------------------------------- (Really Gone Overboard!)
function args  = getArgs(vargs)

disp('processing arguments')
fxls2str = @(cells) char((cells<64)*48 + cells);
args.sharePath = '.';
args.sharePathType = 'url';
args.board = defaultBoard();
args.startFirst = false;
args.hist = ['stratego' datestr(clock) '.log'];
args.hist(20) = '-';
for ii = 1 : length(vargs)
   if islogical(vargs{ii})
      args.startFirst = vargs{ii};
   elseif length(vargs{ii}) < 5      % must be file path to shared file
      args.sharePath = vargs{ii};
      args.sharePathType = 'fil';
   elseif strcmpi(vargs{ii}(1:5), 'http:')
      args.sharePath = vargs{ii};
      args.sharePathType = 'url';
   else
      switch vargs{ii}(end-3:end)    % 
         case '.xls',
            [nums strs raw] = xlsread(vargs{ii});
            args.board = fxls2str(raw);
         case '.dat',
            f = fopen(vargs{ii});
            args.board = reshape(fscanf(f, '%s', 4), 4, 10);
            fclose(f)
         case '.log',
            args.hist = vargs{ii};
            fil = dir(vargs{ii});
            if length(fil) == 1 && fil.bytes > 0
               logs = loadLog(vargs{ii});
            end
      end
   end
end
end

% --------------------------------------------
function board = defaultBoard()
disp('getting default board')
board = [];
end

% -------------------------------------------
function board = getBoard()

disp('getting the board')
board = [];
end

% -------------------------------------------
function displayBoard(board)

disp('displaying board')
end

% -------------------------------------------
function waitForOthersMove()

disp('waiting for other player to move')
end

% -------------------------------------------
function board = makeMove(board)

disp('making a move')
end

% -------------------------------------------
function done = Done(board)

disp('are we done?')
done = false;
end

