20/06/26 16:07:45.68 vSOmQn7C.net
# simulation of 2 alive to 1 alive
# Notice who has the right to shoot
f2 <- function(){
re3=f3() # simulation to 2 suvivors
a=re3$abc[1] # 1 1
b=re3$abc[2] # 1 0
c=re3$abc[3] # 0 1
while(a+b+c==2){ # while 2 alive
if(c==0){ # when C dead
if(re3$bshoot){ # when A killed C, B can shoot A
a=rbinom(1,1,qb)
if(a==0) return(c(a,b,c))
}
else{ # when B killed C
b=rbinom(1,1,qa) # A can shoot B
if(b==0) return(c(a,b,c))
}
}
else{ # when C alive (C killed B, C shot at superior B)
c=rbinom(1,1,qa) # A can shoot C
if(c==0) return(c(a,b,c)) # if A killed C
a=rbinom(1,1,qc) # when A missed C,C can shoot A
if(a==0) return(c(a,b,c)) # C can always kill A
}
}
}
k=1e5
re2=replicate(k,f2())
apply(re2,1,mean) # c(1/2,1/6,1/3)