riskSim=function(att,def,samp){
attLostFreq=numeric(3);
for(i in 1:samp){
attRolls=numeric(length(att));
for(j in 1:length(att)){
attRolls[j]=sample(att[j],1)}
defRolls=numeric(length(def));
for(j in 1:length(def)){
defRolls[j]=sample(def[j],1)}
attWins=sum((sort(attRolls,decreasing=T)[1:2])>(sort(defRolls,decreasing=T)[1:2]));
attLostFreq[3-attWins]=attLostFreq[3-attWins]+1}
finalVec=c(attLostFreq/samp,(attLostFreq[1]+attLostFreq[2]/2)/samp);
return(finalVec)}
You enter the attack dice for att and the defense dice as def. Here's the syntax - c(8,6,6) means you have one eight-sided die and two six-sided dice. Samp is the number of trials.
I did 10000 trials for every combination in risk, risk factions, and risk 2210. Note that even though that seems like a large sample, there can still be some error.
Here is an example of the standard matchup:
> riskSim(c(6,6,6),c(6,6),10000)
[1] 0.3712 0.3380 0.2908 0.5402
What this means is that the attack has three six-sided dice, the defense has two six-sided dice, and there were 10000 trials. The results say that in those trials, 37.12% of the time, the defense lost 2, 29.08% of the time, each side lost 1, and 29.08% of the time, the attack lost 2. In total, the attack had a 54.02 winning percentage.
Risk 2210:
> riskSim(c(6,6,6),c(6,6),10000)
[1] 0.3716 0.3316 0.2968 0.5374
> riskSim(c(8,6,6),c(6,6),10000)
[1] 0.4745 0.3086 0.2169 0.6288
> riskSim(c(8,8,6),c(6,6),10000)
[1] 0.55440 0.27590 0.16970 0.69235
> riskSim(c(8,8,8),c(6,6),10000)
[1] 0.63380 0.24050 0.12570 0.75405
> riskSim(c(6,6,6),c(8,6),10000)
[1] 0.2707 0.3610 0.3683 0.4512
> riskSim(c(8,6,6),c(8,6),10000)
[1] 0.35520 0.34730 0.29750 0.52885
> riskSim(c(8,8,6),c(8,6),10000)
[1] 0.4525 0.3210 0.2265 0.6130
> riskSim(c(8,8,8),c(8,6),10000)
[1] 0.5112 0.2948 0.1940 0.6586
> riskSim(c(6,6,6),c(8,8),10000)
[1] 0.21300 0.34070 0.44630 0.38335
> riskSim(c(8,6,6),c(8,8),10000)
[1] 0.27880 0.33810 0.38310 0.44785
> riskSim(c(8,8,6),c(8,8),10000)
[1] 0.3481 0.3346 0.3173 0.5154
> riskSim(c(8,8,8),c(8,8),10000)
[1] 0.4066 0.3258 0.2676 0.5695
Risk Factions:
> riskSim(c(6,6,6),c(6,6),10000)
[1] 0.37650 0.33770 0.28580 0.54535
> riskSim(c(6,6,6,6),c(6,6),10000)
[1] 0.4620 0.3288 0.2092 0.6264
> riskSim(c(6,6,6),c(6,6,6),10000)
[1] 0.23220 0.29890 0.46890 0.38165
> riskSim(c(6,6,6,6),c(6,6,6),10000)
[1] 0.3136 0.3062 0.3802 0.4667
Here are some things to note. Improving dice helps defense more, especially in Factions. Also, look at how likely the 2-0 and 0-2 sweep are. Consider the standard Risk Factions battle. Attack won 54.535% of the time. For two independent battles with attack winning 54.535% of the time, the distribution of series results are:
2-0
> .54535*.54535
[1] 0.2974066
1-1
> .54535*(1-.54535)*2
[1] 0.4958868
0-2
> (1-.54535)*(1-.54535)
[1] 0.2067066
That's 49.58868% for independent battles compared to 33.77% in Risk.
No comments:
Post a Comment