function pay=cardgame(nplays,compbet)
% for the computer to always bet, set compbet=1
card=[' 2';' 3';' 4';' 5';' 6';' 7';' 8';' 9';'10';' J';' Q';' K';' A']; pay=[];
for i=1:nplays
p=randperm(13);
disp('***********NEW GAME***************')
disp(['Your stake is $1. Your card is ' card(p(1),:)  ])
if (p(2)>=compbet)  % in this case computer bets
 button = questdlg(['Your stake is $1. Your card is ', card(p(1),:),'. Do you want raise $5?'],'Raise?','Yes');
 if(button(1)=='Y')
     payoff=6*sign(p(1)-p(2));
 else
     payoff=-1;
 end
 disp('The computer raised  by $5') 
 disp(['Your card ', card(p(1),:), ':   Computers card ' card(p(2),:), ':   Your payoff ',num2str(payoff)])
 pay=[pay payoff];
 disp('')
else    % runs this if the computer does not bet
    button = questdlg(' Do you want to raise $5?','Raise?','Yes');
 if(button(1)=='Y')   % you bet computer does not
     payoff=1;
 else    % you& computer do not bet
     payoff=0;
 end
 disp('The computer does not raise') 
 disp(['Your card ', card(p(1),:), ':   Computers card ' card(p(2),:), ':   Your payoff ',num2str(payoff)])
 pay=[pay payoff];
 disp('')
end
end
disp(['mean payoff per game ', num2str(mean(pay))])