博弈论,打赌出牌问题

题目:男孩和女孩打赌进行出正反两面牌游戏: 如果都是正或都是反面,女孩给男孩3块钱,如果都是都是反面,女孩给男孩1块钱; 如果正反面不相同,男孩给女孩2块钱.女孩如何操作成绩取得最好效果?
代码:
自定义函数1
function girl=girl(x) %Custom functionm=rand(1,1); %Randomly generate 0 minus 1 Numbers
if m<x
girl=1;%1 is the head of the card
else
girl=0;% 0 is the back of the card
end
%fprintf(‘女孩正面为1,反面为0,则女孩出的是:%f\n’,girl);
自定义函数2
function boy=boy(y) %%Custom functionn=rand();%%Randomly generate 0 minus 1 Numbers
if n<y
boy=1;%1 is the head of the card
else
boy=0;% 0 is the back of the card
end
%fprintf(‘男孩正面为1,反面为0,则男孩出的是:%f\n’,boy);
自定义函数3
function game=game(t,y,x) %%Custom function
moneynan=0; % The boy’s initial money was 0
moneynv=0;%The girl’s initial money was 0
for i=1:t %the for loop
k=girl(x);%Call the function and put the result in k
t=boy(y); %Call the function and put the result in t
if k1&&kt %if both the boy and the girl play the head of the card moneynan=moneynan+3;%The boy’s money plus 3
moneynv=moneynv-3;%the girl’s money minus 3
elseif k0&&kt %if both the boy and the girl play the opposite of the card moneynan=moneynan+1;%The boy’s money plus 1
moneynv=moneynv-1;%the girl’s money minus 1
elseif k~=t
moneynv=moneynv+2; %The girl’s money plus 2
moneynan=moneynan-2;%The boy’s money minus 2
end
end
fprintf(‘男孩赢的钱为:%f\n’,moneynan);%output resultfprintf(‘女孩赢的钱为:%f\n’,moneynv); %output result 主函数
t=10000;%Determined game number x=0.37;%rand(1,1); %Determine the x y=rand(1,1); %Randomly generate 0 minus 1 Numbers
game(t,y,x);%Call the function
fprintf(‘女孩出正面的概率为%f\n’,x);%%output result
fprintf(‘男孩出正面的概率为:%f\n’,y);%output result
fprintf(‘博弈次数为:%f\n’,t);%output result

结果: 经过多次运行,可以得出:当x的范围处于(0.34,0.4)时,女孩一直赢钱,男孩一直输钱。 假设x的值为0.37,y取(0,1)内的任意数,男孩一直输钱。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值