The Journey of a New Computer Programmer

A longtime computer-literate who wants to learn "real" programming language(s).

Thursday, May 10, 2007

Finally! Thank Darwin!

(an expression for the less religiously inclined among us - I would like to make it clear that I'm saying {post title} as a joke.)

Good news from NavalDuels land (er, the NavalDuels ocean):

I was working on a combat-calculation loop that did basically the following:


if Fighter's first-priority target is shiptype x:


Fleet A's fighters fire on B's shiptype x >
How many of x were lost?
amount of x left is = amount started with - amount lost



Fleet B's fighters fire on A's shiptype x >
How many of x were lost?
amount of x left is = amount started with - amount lost

----
I got this to work for shiptype x being (the other guy's) fighters. That code was easily carried over to shiptype x being one of the other ship types, and THAT whole block of code should carry over well to other shiptypes doing the firing.

All this is in a firing loop tucked within the running_calcuation loop.

The statements that trigger the end of the battle, i.e set a winner, are at the bottom of running_calcuation. Once I got the firing loop's code working, the program was displaying the proper intermediate result (the amount of ships that were lost), but not displaying the final result - that is, what the battle's winner was.

I had simply forgotten to put a
firing = False
statement at the end of that loop, exiting out of the firing loop (heading back to other statements in the main loop, running_calculation.

14 freaking characters was the solution, and I spent about 15 minutes trying to figure out why the program was only displaying the intermediate result.
I probably need some sleep...(It's 1 AM as I type this...:D)

0 Comments:

Post a Comment

<< Home