* Calculate the price factor for building a long bridge. * Basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8, * @param length Length of the bridge. * @return Price factor for the bridge. */
| 92 | * @return Price factor for the bridge. |
| 93 | */ |
| 94 | int CalcBridgeLenCostFactor(int length) |
| 95 | { |
| 96 | if (length < 2) return length; |
| 97 | |
| 98 | length -= 2; |
| 99 | int sum = 2; |
| 100 | for (int delta = 1;; delta++) { |
| 101 | for (int count = 0; count < delta; count++) { |
| 102 | if (length == 0) return sum; |
| 103 | sum += delta; |
| 104 | length--; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get the foundation for a bridge. |
no outgoing calls
no test coverage detected