Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # min hit miss percentage (constant)
- mhmp = 5
- random2avg = function(value, rolls, n) {
- result=rep(0,n)
- for(i in 1:rolls) {
- result = result + sample(1:value, n, T)
- }
- result = result / rolls;
- result
- }
- testhit = function(tohit, ev, n) {
- (runif(n,0,100)<mhmp) | (sample(1:(tohit+1),n,T) >= random2avg(2*ev, 2, n))
- }
- testhit_ranged = function(tohit, ev, n) {
- (runif(n,0,100)<mhmp) | (sample(1:(tohit),n,T) >= random2avg(ev, 2, n))
- }
- mons_tohit = function(hd, fighter) {
- if(fighter) {
- 18+hd*2.5
- } else {
- 18+hd*1.5
- }
- }
- hds = c(1,5,10,15,20,25,30)
- cols = c('red', 'magenta', 'green', 'blue', 'orange', 'cyan', 'brown')
- evs = seq(0,50,5)
- d = rep(NA,length(evs))
- n = 100000
- doplot=function(hitfunc, fighter, title) {
- for(hdi in 1:length(hds)) {
- hd = hds[hdi]
- col = cols[hdi]
- for(evi in 1:length(evs)) {
- ev = evs[evi]
- d[evi] = sum(hitfunc(mons_tohit(hd, fighter), ev, n))/n
- }
- if (hdi == 1) {
- plot(evs, 1-d, xlim=range(evs), ylim=c(0,1), t='l', col=col,xlab='EV', ylab='dodge rate', main=title)
- } else {
- lines(evs, 1-d, col=col)
- }
- points(evs, 1-d, col=col, pch='o')
- }
- for(y in seq(0,1,0.1)) { abline(h=y,lty=2,col='lightgrey') }
- for(x in seq(0,50,5)) { abline(v=x,lty=2,col='lightgrey') }
- legend('topleft', legend=paste('HD=', hds), fill=cols)
- }
- png(file='crawl_ev.png', width=1280, height=1024)
- par(mfrow=c(2,2))
- doplot(testhit, F, 'melee, mons fighter=no')
- doplot(testhit, T, 'melee, mons fighter=yes')
- doplot(testhit_ranged, F, 'ranged, mons fighter=no')
- doplot(testhit_ranged, T, 'ranged, mons fighter=yes')
- dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement