function [p,q,val]=nonzerosum(A,B,nsim)
% A and B are payoff matrices to the two participants in a game. Outputs
%mixed strategies p and q determined by simulation conducted nsim times
n=size(A);
p=ones(1,n(1));   % initialize with positive weights on all strategies
q=ones(n(2),1);
for i=1:nsim
   [m,s]=max(A*q);
   [m,t]=max(p*B);
   p(s)=p(s)+1;
   q(t)=q(t)+1;
end
p=p-ones(1,n(1));    p=p/sum(p);
q=q-ones(n(2),1);    q=q/sum(q);
val=[p*A*q p*B*q];


