ship.tiny = createShip(6, 2, 0, 0, 1, 0, 0)
ship.small = createShip(10, 4, 0, 0, 2, 0, 0)
ship.medium.1 = createShip(16, 6, 0, 0, 2, 0, 0)
ship.medium.2 = createShip(16, 5, 0, 0, 3, 0, 0)
fleet.composition = matrix(nrow=24, ncol=4)
fleet.composition[1,] = c(5, 0, 0, 0)
fleet.composition[2,] = c(4, 0, 1, 1)
fleet.composition[3,] = c(3, 0, 3, 0)
fleet.composition[4,] = c(3, 0, 1, 3)
fleet.composition[5,] = c(2, 0, 4, 0)
fleet.composition[6,] = c(2, 0, 3, 2)
fleet.composition[7,] = c(2, 0, 1, 5)
fleet.composition[8,] = c(1, 0, 5, 1)
fleet.composition[9,] = c(1, 0, 3, 4)
fleet.composition[10,] = c(1, 0, 1, 7)
fleet.composition[11,] = c(0, 5, 0, 0)
fleet.composition[12,] = c(0, 4, 1, 1)
fleet.composition[13,] = c(0, 3, 3, 0)
fleet.composition[14,] = c(0, 3, 1, 3)
fleet.composition[15,] = c(0, 2, 4, 0)
fleet.composition[16,] = c(0, 2, 3, 2)
fleet.composition[17,] = c(0, 2, 1, 5)
fleet.composition[18,] = c(0, 1, 5, 1)
fleet.composition[19,] = c(0, 1, 3, 4)
fleet.composition[20,] = c(0, 1, 1, 7)
fleet.composition[21,] = c(0, 0, 7, 0)
fleet.composition[22,] = c(0, 0, 5, 3)
fleet.composition[23,] = c(0, 0, 3, 6)
fleet.composition[24,] = c(0, 0, 1, 9)
median.result = matrix(nrow=24, ncol=24)
victory.probability = matrix(nrow=24, ncol=24)
for(i in 1:24) {
# this is a rather clunky way of creating the fleets, but it works...
attacker = createFleet()
attacker.ships = 0
if(fleet.composition[i, 1]) {
attacker[(attacker.ships+1) attacker.ships+fleet.composition[i, 1]),] = ship.medium.1
attacker.ships = attacker.ships + fleet.composition[i, 1]
}
if(fleet.composition[i, 2]) {
attacker[(attacker.ships+1) attacker.ships+fleet.composition[i, 2]),] = ship.medium.2
attacker.ships = attacker.ships + fleet.composition[i, 2]
}
if(fleet.composition[i, 3]) {
attacker[(attacker.ships+1) attacker.ships+fleet.composition[i, 3]),] = ship.small
attacker.ships = attacker.ships + fleet.composition[i, 3]
}
if(fleet.composition[i, 4]) {
attacker[(attacker.ships+1) attacker.ships+fleet.composition[i, 4]),] = ship.tiny
attacker.ships = attacker.ships + fleet.composition[i, 4]
}
for(j in 1:24) {
defender = createFleet()
defender.ships = 0
if(fleet.composition[j, 1]) {
defender[(defender.ships+1) defender.ships+fleet.composition[j, 1]),] = ship.medium.1
defender.ships = defender.ships + fleet.composition[j, 1]
}
if(fleet.composition[j, 2]) {
defender[(defender.ships+1) defender.ships+fleet.composition[j, 2]),] = ship.medium.2
defender.ships = defender.ships + fleet.composition[j, 2]
}
if(fleet.composition[j, 3]) {
defender[(defender.ships+1) defender.ships+fleet.composition[j, 3]),] = ship.small
defender.ships = defender.ships + fleet.composition[j, 3]
}
if(fleet.composition[j, 4]) {
defender[(defender.ships+1) defender.ships+fleet.composition[j, 4]),] = ship.tiny
defender.ships = defender.ships + fleet.composition[j, 4]
}
results = simulateCombat(100, attacker, defender)
median.result[i,j] = median(results)
victory.probability[i,j] = sum(results>0) / length(results)
}
}
|