Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Warhammer 40k
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
############################################### Set number of dice and hit and wound roll needed ######################### hitdice <- 24 ### how many dice do you roll to hit / if random use expected dice (e.g., d6 is 3.5 d3 is 2) hit <- 4 ### what do you hit on wound <- 3 ### what do you wound on / set to 0 to get back number of hits (and set save to 7) save <- 3 ### what is their armour save / set to 7 to get back number of wounds ap <- 0 ### what is the ap damage <- 1 ### how many damage per wound / if random use expected damage (e.g., d6 damage is 3.5, d3 damage is 2, 2d6 pick highest is 4.47) rerollhit1 <- F ### do you re roll hits of 1 F for no T for yes rerollwound1 <- F ### do you re roll wounds of 1 F for no T for yes rerollhit <- F ### do you re roll hits F for no T for yes rerollwound <- F ### do you re roll wounds F for no T for yes ############################################### IGNORE CODE BELOW ######################################################## rolldice <- function(hitdice,hit,wound,save,ap,rerollhit,rerollwound){ savemod <- save-ap # Roll for hits hitresult <- sample(c(1:6),hitdice,replace=T) hitresult2 <- 0 if(rerollhit1 == T) { rerolls1 <- length(which(hitresult==1)) if(rerolls1 > 0) { hitresult2 <- sample(c(1:6),rerolls1,replace=T) } } if(rerollhit == T) { rerolls <- length(which(hitresult<hit)) if(rerolls > 0) { hitresult2 <- sample(c(1:6),rerolls,replace=T) } } hits <- sum(c(hitresult >= hit, hitresult2 >= hit)) # Roll for wounds woundresult <- sample(c(1:6),hits,replace=T) woundresult2 <- 0 if(rerollwound1 == T) { rerolls1 <- length(which(woundresult==1)) if(rerolls1 > 0) { woundresult2 <- sample(c(1:6),rerolls1,replace=T) } } if(rerollwound == T) { rerolls <- length(which(woundresult<wound)) if(rerolls > 0) { woundresult2 <- sample(c(1:6),rerolls,replace=T) } } wounds <- sum(c(woundresult >= wound, woundresult2 >= wound)) saves <- sum(sample(c(1:6),wounds,replace=T) >= savemod) dead <- wounds - saves dead } tmp <- NULL for(i in 1:40000) { tmp[i] <- rolldice(hitdice,hit,wound,save,ap,rerollhit,rerollwound) } paste("NUMBER OF WOUNDS LOST:",round(mean(tmp)*damage,1), sep = " ")
[
+
]
Show input
Absolute running time: 3.96 sec, cpu time: 5.45 sec, memory peak: 38 Mb, absolute service time: 3,97 sec
fork mode
|
history
|
discussion
[1] "NUMBER OF WOUNDS LOST: 2.7"