Charis
Realms Beyond
Thanks for pointing out some other examples, as I don't
have any sets on hand for examples and 'correct' answers.
The two formulae are getting closer -- if I pull my 'cost'
over inside the truncation, the results get much closer to yours, but still not identical. If I make the 1.75*CL term a division instead of a multiplication, I think we're identical:
Modified version:
Research cost = MF/CF * [ 10*COST - 10*COST*N/[7*CL/4] ] / 10
That's now quite similar to yours
Well... due to differences in rounding, the *ONLY* answer that "always gives the correct result" is the one used by the program
The thing is, it's 99.9% certain they're just using integer math, nothing but truncation, no roundup function for sure. If you ever get something that 'looks like' a roundup it's always coded as something MINUS what you have. For example, 10 - roundup(n) is the same as [10 - n]. So it's closer to the code, easier to view as integers, and cleaner to express the terms with [ ] instead of function calls. In this specific case, I think that the trunc formula I give above is identical to yours, using the roundup to rounddown conversion. You have COST - UP(Cost*X) where I've written Down(Cost-Cost*X)
The two things I'm left wondering -
i) an alternate formula I looked at in the middle gives *very* close results --
Research cost ?= MF/CF* [ 10*COST - 10*COST*N*4*CL/7] / 10
It gives 14008 instead of 14000 beakers, for you example. Or 27 beakers for the other example. Are you sure it's 14000, not 14008?
ii) Is the correct 'scaling' term used 10? ie, Up_0.1 or Up_somethingElse?
In practical terms,
Research cost = MF/CF * [ 10*COST - 10*COST*N/[7*CL/4] ] / 10
(written like this or as you have it) is extremely close if not exactly what the program uses.
Again, nice job,
Charis
(Edit - fixed N typo as pointed out next post)
have any sets on hand for examples and 'correct' answers.
The two formulae are getting closer -- if I pull my 'cost'
over inside the truncation, the results get much closer to yours, but still not identical. If I make the 1.75*CL term a division instead of a multiplication, I think we're identical:
Modified version:
Research cost = MF/CF * [ 10*COST - 10*COST*N/[7*CL/4] ] / 10
That's now quite similar to yours
However, I do see your point, the formula written at the top of this thread will not be how it is written in the code for civ3. But I am fairly sure that it is the simplest mathematical way to express a formula which always gives the correct results for Research Cost.
Well... due to differences in rounding, the *ONLY* answer that "always gives the correct result" is the one used by the program

The thing is, it's 99.9% certain they're just using integer math, nothing but truncation, no roundup function for sure. If you ever get something that 'looks like' a roundup it's always coded as something MINUS what you have. For example, 10 - roundup(n) is the same as [10 - n]. So it's closer to the code, easier to view as integers, and cleaner to express the terms with [ ] instead of function calls. In this specific case, I think that the trunc formula I give above is identical to yours, using the roundup to rounddown conversion. You have COST - UP(Cost*X) where I've written Down(Cost-Cost*X)
The two things I'm left wondering -
i) an alternate formula I looked at in the middle gives *very* close results --
Research cost ?= MF/CF* [ 10*COST - 10*COST*N*4*CL/7] / 10
It gives 14008 instead of 14000 beakers, for you example. Or 27 beakers for the other example. Are you sure it's 14000, not 14008?
ii) Is the correct 'scaling' term used 10? ie, Up_0.1 or Up_somethingElse?
In practical terms,
Research cost = MF/CF * [ 10*COST - 10*COST*N/[7*CL/4] ] / 10
(written like this or as you have it) is extremely close if not exactly what the program uses.
Again, nice job,
Charis
(Edit - fixed N typo as pointed out next post)