function mancala1()

% 1: most basic idea
% 2: Mimic playing the game

% --------- Main Loop to Play the Game -------------
% pn:      Player Names (two string cell array)
% again:   Play Again? (logical)
% b:       Board (twelve integer array of pockets)
% ps:      Player Scores (two integer array)

pn = getPlayerNames();
again = true;
while again
  [b ps it] = setUpGame();
  [ps] = playGame(b, ps, pn, it);
  declareWinner(ps, pn)
  again = anotherGame();
end

% --------- Get Player Names from Input ------------
function player = getPlayerNames()
player{1} = input('Enter first player''s name: ', 's')
player{2} = input('Enter second player''s name: ', 's')
return

% --------- Set up the Initial Board etc. ----------
function [board playerScores it] = setUpGame()
disp('Set up game');
board(1:12) = 4        % four stones in each hole to start
playerScores(1:2) = 0  % zero out the opening scores
it = 1                 % start with player one
return

% --------- Play the Game to its Conclusion (stub) --
function [playerScores] = playGame(board, playerScores, playerNames, it)
disp('Play game');
while true
  displayBoard(board);
  pickedHole = pickHole(board, playerNames{it})
  finalHole = distributePebbles(board, pickedHole)
  playerScores(it) = updateScore(finalHole, playerScores(it))
  it = 3 - it
end
return

% ------- Display the Board ----------------------
function displayBoard(board)
disp('Displaying board');
return

% ------- Player Picks a Hole --------------------
function pick = pickHole(board, player)
disp('Pick a hole');
fprintf('%s, Enter hole 1-12: ', player)
pick = input(': ');
return

% -------- Distribute the Pebbles (stub) ----------
% -- and return the hole position of final pebble -

function finalHole = distributePebbles(board, pick)
disp('Distributing pebbles');
finalHole = mod(board(pick) + pick -1, 12) + 1 
return

% -------- Update Score (stub) ---------------------
function score = updateScore(hole, score)
disp('Updating score');
return

% --------- Declare the Winner (stub) ---------------
function declareWinner(scores, players)
disp('Declare winner');
return

% --------- Another Game request --------------------
function another = anotherGame()
another = input('Another game (1 if yes, 0 if no)? ');
return
 
