Sure. Same tests. Wouldn't sweat very small decimals as there are only so many ways to get this right so if they are similar to a few decimals it probably is. Before declaring victory though, try the non-uniform distribution and consecutive shots. Edit: oops. The first has the incorrect prob dist. Repost soon. E2: fixed. Complete prints below except I sabotaged the [\\i] to escape from bbcode
> damage <- 20
> hitstrength <- 40
> startingarmor <- 100
> hitstrengthcalc <- function(hitstrength, armor) return(max(0.15,hitstrength/(hitstrength+max(armor,0.05*startingarmor))))
> shipcells <- 10
> probabilities <- c(0.10,0.1,0.10,0.1,0.10,0.10,0.1,0.10,0.1,0.10)
> norounds <- 3
>
>
> weights <- matrix(c(0,0.5,0.5,0.5,0,0.5,1,1,1,0.5,0.5,1,1,1,0.5,0.5,1,1,1,0.5,0,0.5,0.5,0.5,0),5,5)
> weights
[,1] [,2] [,3] [,4] [,5]
[1,] 0.0 0.5 0.5 0.5 0.0
[2,] 0.5 1.0 1.0 1.0 0.5
[3,] 0.5 1.0 1.0 1.0 0.5
[4,] 0.5 1.0 1.0 1.0 0.5
[5,] 0.0 0.5 0.5 0.5 0.0
>
> poolarmor <- function(armormatrix, index) {
+ sum <- 0
+ for(i in 1:5)for(j in 1:5) sum <- sum + weights[i,j]*armormatrix[i,index-3+j]
+ return(sum)
+ }
> print("Starting armor matrix")
[1] "Starting armor matrix"
> print(armormatrix <- matrix(startingarmor / 15, 5, shipcells+4))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[2,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[3,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[4,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[5,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[,12] [,13] [,14]
[1,] 6.666667 6.666667 6.666667
[2,] 6.666667 6.666667 6.666667
[3,] 6.666667 6.666667 6.666667
[4,] 6.666667 6.666667 6.666667
[5,] 6.666667 6.666667 6.666667
>
> print("Equivalent armor hp:")
[1] "Equivalent armor hp:"
> fullarmorhp <- (sum(armormatrix[2:4,])+sum(armormatrix[1,2:13])+sum(armormatrix[5,2:13]))/(5*14-4)*15
> print(fullarmorhp)
[1] 100
>
> for(r in 1:norounds){
+
+ armordamagereductions <- vector(shipcells, mode="double")
+ for (x in 1:length(armordamagereductions)) {
+ armordamagereductions
- <- hitstrengthcalc(hitstrength,poolarmor(armormatrix,x+2))
+ }
+ print("Armor damage expected based on full armor hp:")
+ print(damage*hitstrength/(hitstrength+fullarmorhp))
+
+ armordamagesatmiddlecells <- armordamagereductions*damage
+ print("Armor damage at middle cells given full shot:")
+ print(armordamagesatmiddlecells)
+ print("Probability adjusted armor damage at middle cells:")
+ for(x in 1:length(armordamagesatmiddlecells)) {
+ armordamagesatmiddlecells
- <- armordamagesatmiddlecells
- *probabilities
+ }
+ print(armordamagesatmiddlecells)
+ print("Total armor damage incoming at middle cells:")
+ print(sum(armordamagesatmiddlecells))
+
+ for (i in 1:length(armordamagesatmiddlecells)){
+ for (j in 1:5){
+ for (k in 1:5){
+ armormatrix[j,i+k-1] <- armormatrix[j,i+k-1] - armordamagesatmiddlecellsi]*weights[j,k]/15
+ }
+ }
+ }
+ print("New armor matrix:")
+ print((armormatrix))
+
+ print("Equivalent armor hp:")
+ fullarmorhp <- (sum(armormatrix[2:4,])+sum(armormatrix[1,2:13])+sum(armormatrix[5,2:13]))/(5*14-4)*15
+ print(fullarmorhp)
+ }
[1] "Armor damage expected based on full armor hp:"
[1] 5.714286
[1] "Armor damage at middle cells given full shot:"
[1] 5.714286 5.714286 5.714286 5.714286 5.714286 5.714286 5.714286 5.714286 5.714286 5.714286
[1] "Probability adjusted armor damage at middle cells:"
[1] 0.5714286 0.5714286 0.5714286 0.5714286 0.5714286 0.5714286 0.5714286 0.5714286 0.5714286 0.5714286
[1] "Total armor damage incoming at middle cells:"
[1] 5.714286
[1] "New armor matrix:"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.647619 6.628571 6.609524 6.609524 6.609524 6.609524 6.609524 6.609524 6.609524 6.609524
[2,] 6.647619 6.609524 6.571429 6.533333 6.514286 6.514286 6.514286 6.514286 6.514286 6.514286 6.533333
[3,] 6.647619 6.609524 6.571429 6.533333 6.514286 6.514286 6.514286 6.514286 6.514286 6.514286 6.533333
[4,] 6.647619 6.609524 6.571429 6.533333 6.514286 6.514286 6.514286 6.514286 6.514286 6.514286 6.533333
[5,] 6.666667 6.647619 6.628571 6.609524 6.609524 6.609524 6.609524 6.609524 6.609524 6.609524 6.609524
[,12] [,13] [,14]
[1,] 6.628571 6.647619 6.666667
[2,] 6.571429 6.609524 6.647619
[3,] 6.571429 6.609524 6.647619
[4,] 6.571429 6.609524 6.647619
[5,] 6.628571 6.647619 6.666667
[1] "Equivalent armor hp:"
[1] 98.7013
[1] "Armor damage expected based on full armor hp:"
[1] 5.76779
[1] "Armor damage at middle cells given full shot:"
[1] 5.764875 5.780745 5.791107 5.795901 5.797101 5.797101 5.795901 5.791107 5.780745 5.764875
[1] "Probability adjusted armor damage at middle cells:"
[1] 0.5764875 0.5780745 0.5791107 0.5795901 0.5797101 0.5797101 0.5795901 0.5791107 0.5780745 0.5764875
[1] "Total armor damage incoming at middle cells:"
[1] 5.785946
[1] "New armor matrix:"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.628403 6.590086 6.551735 6.551631 6.551577 6.551557 6.551557 6.551577 6.551631 6.551735
[2,] 6.628403 6.551822 6.475154 6.398435 6.359961 6.359799 6.359728 6.359728 6.359799 6.359961 6.398435
[3,] 6.628403 6.551822 6.475154 6.398435 6.359961 6.359799 6.359728 6.359728 6.359799 6.359961 6.398435
[4,] 6.628403 6.551822 6.475154 6.398435 6.359961 6.359799 6.359728 6.359728 6.359799 6.359961 6.398435
[5,] 6.666667 6.628403 6.590086 6.551735 6.551631 6.551577 6.551557 6.551557 6.551577 6.551631 6.551735
[,12] [,13] [,14]
[1,] 6.590086 6.628403 6.666667
[2,] 6.475154 6.551822 6.628403
[3,] 6.475154 6.551822 6.628403
[4,] 6.475154 6.551822 6.628403
[5,] 6.590086 6.628403 6.666667
[1] "Equivalent armor hp:"
[1] 97.38631
[1] "Armor damage expected based on full armor hp:"
[1] 5.822996
[1] "Armor damage at middle cells given full shot:"
[1] 5.816955 5.849598 5.871049 5.881035 5.883560 5.883560 5.881035 5.871049 5.849598 5.816955
[1] "Probability adjusted armor damage at middle cells:"
[1] 0.5816955 0.5849598 0.5871049 0.5881035 0.5883560 0.5883560 0.5881035 0.5871049 0.5849598 0.5816955
[1] "Total armor damage incoming at middle cells:"
[1] 5.860439
[1] "New armor matrix:"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.609013 6.551198 6.493276 6.492959 6.492791 6.49273 6.49273 6.492791 6.492959 6.493276
[2,] 6.609013 6.493544 6.377807 6.261915 6.203615 6.203117 6.20290 6.20290 6.203117 6.203615 6.261915
[3,] 6.609013 6.493544 6.377807 6.261915 6.203615 6.203117 6.20290 6.20290 6.203117 6.203615 6.261915
[4,] 6.609013 6.493544 6.377807 6.261915 6.203615 6.203117 6.20290 6.20290 6.203117 6.203615 6.261915
[5,] 6.666667 6.609013 6.551198 6.493276 6.492959 6.492791 6.49273 6.49273 6.492791 6.492959 6.493276
[,12] [,13] [,14]
[1,] 6.551198 6.609013 6.666667
[2,] 6.377807 6.493544 6.609013
[3,] 6.377807 6.493544 6.609013
[4,] 6.377807 6.493544 6.609013
[5,] 6.551198 6.609013 6.666667
[1] "Equivalent armor hp:"
[1] 96.05439
>
> damage <- 100
> hitstrength <- 100
> startingarmor <- 100
> hitstrengthcalc <- function(hitstrength, armor) return(max(0.15,hitstrength/(hitstrength+max(armor,0.05*startingarmor))))
> shipcells <- 10
> probabilities <- c(0.00,0.05,0.10,0.15,0.20,0.20,0.15,0.10,0.05,0.00)
> norounds <- 3
>
>
> weights <- matrix(c(0,0.5,0.5,0.5,0,0.5,1,1,1,0.5,0.5,1,1,1,0.5,0.5,1,1,1,0.5,0,0.5,0.5,0.5,0),5,5)
> weights
[,1] [,2] [,3] [,4] [,5]
[1,] 0.0 0.5 0.5 0.5 0.0
[2,] 0.5 1.0 1.0 1.0 0.5
[3,] 0.5 1.0 1.0 1.0 0.5
[4,] 0.5 1.0 1.0 1.0 0.5
[5,] 0.0 0.5 0.5 0.5 0.0
>
> poolarmor <- function(armormatrix, index) {
+ sum <- 0
+ for(i in 1:5)for(j in 1:5) sum <- sum + weights[i,j]*armormatrix[i,index-3+j]
+ return(sum)
+ }
> print("Starting armor matrix")
[1] "Starting armor matrix"
> print(armormatrix <- matrix(startingarmor / 15, 5, shipcells+4))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[2,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[3,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[4,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[5,] 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667 6.666667
[,12] [,13] [,14]
[1,] 6.666667 6.666667 6.666667
[2,] 6.666667 6.666667 6.666667
[3,] 6.666667 6.666667 6.666667
[4,] 6.666667 6.666667 6.666667
[5,] 6.666667 6.666667 6.666667
>
> print("Equivalent armor hp:")
[1] "Equivalent armor hp:"
> fullarmorhp <- (sum(armormatrix[2:4,])+sum(armormatrix[1,2:13])+sum(armormatrix[5,2:13]))/(5*14-4)*15
> print(fullarmorhp)
[1] 100
>
> for(r in 1:norounds){
+
+ armordamagereductions <- vector(shipcells, mode="double")
+ for (x in 1:length(armordamagereductions)) {
+ armordamagereductions
- <- hitstrengthcalc(hitstrength,poolarmor(armormatrix,x+2))
+ }
+ print("Armor damage expected based on full armor hp:")
+ print(damage*hitstrength/(hitstrength+fullarmorhp))
+
+ armordamagesatmiddlecells <- armordamagereductions*damage
+ print("Armor damage at middle cells given full shot:")
+ print(armordamagesatmiddlecells)
+ print("Probability adjusted armor damage at middle cells:")
+ for(x in 1:length(armordamagesatmiddlecells)) {
+ armordamagesatmiddlecells
- <- armordamagesatmiddlecells
- *probabilities
+ }
+ print(armordamagesatmiddlecells)
+ print("Total armor damage incoming at middle cells:")
+ print(sum(armordamagesatmiddlecells))
+
+ for (i in 1:length(armordamagesatmiddlecells)){
+ for (j in 1:5){
+ for (k in 1:5){
+ armormatrix[j,i+k-1] <- armormatrix[j,i+k-1] - armordamagesatmiddlecellsi]*weights[j,k]/15
+ }
+ }
+ }
+ print("New armor matrix:")
+ print((armormatrix))
+
+ print("Equivalent armor hp:")
+ fullarmorhp <- (sum(armormatrix[2:4,])+sum(armormatrix[1,2:13])+sum(armormatrix[5,2:13]))/(5*14-4)*15
+ print(fullarmorhp)
+ }
[1] "Armor damage expected based on full armor hp:"
[1] 50
[1] "Armor damage at middle cells given full shot:"
[1] 50 50 50 50 50 50 50 50 50 50
[1] "Probability adjusted armor damage at middle cells:"
[1] 0.0 2.5 5.0 7.5 10.0 10.0 7.5 5.0 2.5 0.0
[1] "Total armor damage incoming at middle cells:"
[1] 50
[1] "New armor matrix:"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.666667 6.583333 6.416667 6.166667 5.916667 5.750000 5.750000 5.916667 6.166667 6.416667
[2,] 6.666667 6.583333 6.333333 5.916667 5.333333 4.750000 4.416667 4.416667 4.750000 5.333333 5.916667
[3,] 6.666667 6.583333 6.333333 5.916667 5.333333 4.750000 4.416667 4.416667 4.750000 5.333333 5.916667
[4,] 6.666667 6.583333 6.333333 5.916667 5.333333 4.750000 4.416667 4.416667 4.750000 5.333333 5.916667
[5,] 6.666667 6.666667 6.583333 6.416667 6.166667 5.916667 5.750000 5.750000 5.916667 6.166667 6.416667
[,12] [,13] [,14]
[1,] 6.583333 6.666667 6.666667
[2,] 6.333333 6.583333 6.666667
[3,] 6.333333 6.583333 6.666667
[4,] 6.333333 6.583333 6.666667
[5,] 6.583333 6.666667 6.666667
[1] "Equivalent armor hp:"
[1] 88.63636
[1] "Armor damage expected based on full armor hp:"
[1] 53.01205
[1] "Armor damage at middle cells given full shot:"
[1] 51.50215 52.93339 54.75702 56.55042 57.70618 57.70618 56.55042 54.75702 52.93339 51.50215
[1] "Probability adjusted armor damage at middle cells:"
[1] 0.000000 2.646670 5.475702 8.482564 11.541236 11.541236 8.482564 5.475702 2.646670 0.000000
[1] "Total armor damage incoming at middle cells:"
[1] 56.29234
[1] "New armor matrix:"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 6.666667 6.666667 6.495111 6.145921 5.613169 5.066683 4.697832 4.697832 5.066683 5.613169 6.145921
[2,] 6.666667 6.495111 5.974365 5.092423 3.841630 2.577103 1.847055 1.847055 2.577103 3.841630 5.092423
[3,] 6.666667 6.495111 5.974365 5.092423 3.841630 2.577103 1.847055 1.847055 2.577103 3.841630 5.092423
[4,] 6.666667 6.495111 5.974365 5.092423 3.841630 2.577103 1.847055 1.847055 2.577103 3.841630 5.092423
[5,] 6.666667 6.666667 6.495111 6.145921 5.613169 5.066683 4.697832 4.697832 5.066683 5.613169 6.145921
[,12] [,13] [,14]
[1,] 6.495111 6.666667 6.666667
[2,] 5.974365 6.495111 6.666667
[3,] 5.974365 6.495111 6.666667
[4,] 5.974365 6.495111 6.666667
[5,] 6.495111 6.666667 6.666667
[1] "Equivalent armor hp:"
[1] 75.84265
[1] "Armor damage expected based on full armor hp:"
[1] 56.86902
[1] "Armor damage at middle cells given full shot:"
[1] 53.26066 56.62906 61.31532 66.40800 69.97700 69.97700 66.40800 61.31532 56.62906 53.26066
[1] "Probability adjusted armor damage at middle cells:"
[1] 0.000000 2.831453 6.131532 9.961200 13.995401 13.995401 9.961200 6.131532 2.831453 0.000000
[1] "Total armor damage incoming at middle cells:"
[1] 65.83917
[1] "New armor matrix:"
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 6.666667 6.666667 6.400729 5.847155 4.982363 4.06374553 3.432765 3.432765 4.06374553 4.982363
[2,] 6.666667 6.400729 5.581217 4.162851 2.113504 0.01033242 -1.219502 -1.219502 0.01033242 2.113504
[3,] 6.666667 6.400729 5.581217 4.162851 2.113504 0.01033242 -1.219502 -1.219502 0.01033242 2.113504
[4,] 6.666667 6.400729 5.581217 4.162851 2.113504 0.01033242 -1.219502 -1.219502 0.01033242 2.113504
[5,] 6.666667 6.666667 6.400729 5.847155 4.982363 4.06374553 3.432765 3.432765 4.06374553 4.982363
[,11] [,12] [,13] [,14]
[1,] 5.847155 6.400729 6.666667 6.666667
[2,] 4.162851 5.581217 6.400729 6.666667
[3,] 4.162851 5.581217 6.400729 6.666667
[4,] 4.162851 5.581217 6.400729 6.666667
[5,] 5.847155 6.400729 6.666667 6.666667
[1] "Equivalent armor hp:"
[1] 60.8792