function out=rooks(board)
  white_rows = sum(board == 1,2) > 0;
  black_rows = sum(board == -1,2) > 0;
  row_overlap = white_rows .* black_rows;

  white_cols = sum(board == 1,1) > 0;
  black_cols = sum(board == -1,1) > 0;
  col_overlap = white_cols .* black_cols;
  out = sum(row_overlap) + sum(col_overlap);
end


%!assert (rooks([1,0]) == 0)
%!assert (rooks([1,0,-1]) == 1)
%!assert (rooks([1,0;0,-1]) == 0)
%!assert (rooks([1,1;0,-1]) == 1)
%!assert (rooks([1,1;-1,-1]) == 2)
%!assert (rooks([1,-1;-1,1]) == 4)
%!assert (rooks([1,0; 0, -1]) == 0)
%!assert (rooks([1,1,-1]) == 1)
%!assert (rooks([1,1,-1; -1,0,1]) == 4) 

%!test
%! V=[1   1   1   1   1;
%!    0   0   0   0   1;
%!    1  -1   1  -1   1;
%!    1   1   1   1   1;
%!    1  -1   1  -1   1];
%! assert (rooks(V) == 4)
