Tigars<- rbind(c(0,0,0,0,1),
c(0.6508972,0.2593801,0.05709625,0.004893964,0.027732463),
c(0.6504065,0.2926829,0.04471545,0.010162602,0.002032520),
c(0.6991304,0.2034783,0.05391304,0.010434783,0.033043478),
c(0.7039007,0.1861702,0.02659574,0.000000000,0.083333333),
c(0.7592068,0.1614731,0.03399433,0.000000000,0.045325779),
c(0.6967509,0.1985560,0.05234657,0.000000000,0.052346570),
c(0.7453416,0.1614907,0.07453416,0.000000000,0.018633540),
c(0.9000000,0.1000000,0.00000000,0.000000000,0.000000000)
)
b1<- mapply(rep,2:people,1:(people-1))
b2<- mapply(rep,2:people,(people-1):1)
b<- diag(1,people)
b[upper.tri(b)]<- unlist(b1)
b[lower.tri(b)]<- unlist(b2)
Tigars.array<- array(0,c(people,Nbase+1,2))
team.array<- array(0,c(people,Nbase+1,people))
for(t in 1:people){
team.array[,,t]<- Tigars[b[t,],]
}
library(MCMCpack)
library(gtools)
library(expm)
Nbase<- 4
Nout<- 3
Ninning<- 9
people<- 9
game<- 10
Vnum<- 100
cut<- 0.95
battle.cmb<- combinations(people,2)
wdldata<- matrix(0,nr=nrow(battle.cmb),nc=3)
dimnames(wdldata)<- list(1:nrow(wdldata),c("win","draw","lose"))
game<- 100
for(b in 1:nrow(battle.cmb)){
D1<- rep(0,game)
D2<- rep(0,game)
batter<- team.array[,,battle.cmb[b,1]]
for(i in 1:game){
D1[i]<- one.game.score(batter,Nout,Nbase,people,Ninning)
}
batter<- team.array[,,battle.cmb[b,2]]
for(i in 1:game){
D2[i]<- one.game.score(batter,Nout,Nbase,people,Ninning)
}
wdl<- c(sum(D1>D2),sum(D1==D2),sum(D1<D2))
wdldata[b,]<- wdl
}
res<- cbind(battle.cmb,wdldata)
battledata<- matrix(0,nr=people,nc=3)
dimnames(battledata)<- list(1:people,c("win","draw","lose"))
for(nr in 3:5){
for(t in 1:people){
battledata[t,nr-2]<- sum(res[which(res[,1]==t),nr])
}
}
for(nr in 5:3){
for(t in 1:people){
battledata[t,6-nr]<- battledata[t,6-nr]+sum(res[which(res[,2]==t),nr])
}
}
winprob<- function(vec){
a<- vec["win"]/(vec["win"]+vec["lose"])
return(a)
}
cbind(battledata,apply(battledata,1,winprob))
one.game.score<-
function(batter,out.count,base,people,Inning){
hitpattern<- c(1,lapply(mapply(rep,0,1:(base-1)),append,c(1),after=F))
out.count<- out.count
total.score<- rep(0,Inning)
batter.box<- 1
for(t in 1:Inning){
runner<- rep(0,people)
out<- 0
repeat{
x<- sample(1:(base+1),prob=batter[batter.box,],size=1)
if(x==1){
out<- out+1
}else{
runner<- append(runner,hitpattern[[x-1]])
}
batter.box<- batter.box+1
if(batter.box>9){
batter.box<- 1
}
if(out>(out.count - 1)){
break
}
}
total.score[t]<- sum(runner[c(1:(length(runner)-3))])
}
return(sum(total.score))
}
hist.data<- function(n,batter,out.count){
data1<- rep(0,n)
for(i in 1:n){
data1[i]<- one.game.score(batter,out.count)
}
result.count<- rep(0,(max(data1) + 1))
for(p in 0:max(data1)){
result.count[p]<- length(which(data1 == p))
}
return(data1)
}