function slick(s)

if nargin == 0
   s = 4;
end

names = getNames();

% b = char(zeros(s)+' ');
b = randi([1,2], s);
b(b == 1) = 'X';
b(b == 2) = 'O';

t = 1;

showBoard(b);
while ~done(b)
   m = getMove(s, names{t});
   while ~validMove(b, m, t)
      disp('oops - try again')
      m = getMove(s, names{t})
   end
   b = makeMove(b, m, t);
   t = 3 - t;
   showBoard(b);
end
end

% --------------------------
function names = getNames()
names{1} = input('first player''s name: ','s');
names{2} = input('second player''s name: ','s');
end

% --------------------------
function showBoard(b)
fprintf('\n')
s = length(b);
for col = 1:s
   fprintf('+-')
end
fprintf('+\n')
for row = 1:s
   fprintf('|%c', b(row,:))
   fprintf('|\n')
   for col = 1:s
      fprintf('+-')
   end
   fprintf('+\n')
end
fprintf('\n')
end

% ---------------------------
function m = getMove(s, n)
fprintf('%s, your move - ', n)
m.type = input('shift (nsew) or place marker (m): ','s');
if m.type == 'm'
   m.row = input('row: ');
   m.col = input('col: ');
elseif m.type  == 'n' | m.type == 's'
   m.row = 0;
   m.col = input('col: ');
elseif m.type == 'e' | m.type  == 'w'
   m.row = input('row: ');
   m.col = 0;
end
end

% --------------------------
function v = validMove(b, m, t)
disp('valid move?')
s = length(b);
mark = 'XO';
v1 = any('nsewm' == m.type);
v2 = m.type == 'm' && m.row > 0 && m.col > 0 && m.row <= s && m.col <= s && b(m.row,m.col) == ' ';
v3 = (m.type == 'n' || m.type == 's') && m.col > 0 && m.col <= s && any(b(:,m.col) == mark(t));
v4 = (m.type == 'e' || m.type == 'w') && m.row > 0 && m.row <= s && any(b(m.row,:) == mark(t));
v = v1 && (v2 || v3 || v4);
end

% ---------------------------
function b = makeMove(b, m, t)
disp('making move')
end
 
% ---------------------------
function d = done(b)
disp('done?')
d = false;
end

