So Close

chaoticset on 2003-10-23T02:34:38

I still think I should be working on the CSG that chromatic is trying to do as an example project, so I spent a few hours today writing code to make almost all of the ice-attacking customer tests pass. Almost being the emphasis -- it feels like some sort of logic problem, honestly, because it wants a result in the test that seems impossible.

The (forgive the wrong terminology, but this will be more accessible) computer has 1 hit point. It's going to regenerate 50 this turn. The attack is going to do 10 points of damage.

Somehow, the computer's supposed to come out of that with 49 hit points left.

Now, it sounds sensible -- you can only do as much damage as there were hit points at the start of the attack -- but it seems to directly contradict some other tests. (Which is to say, every time I implement something that would allow this, something else breaks and makes the test fail before it reaches the test I'm trying to pass.) One of the tests wants to limit the amount of damage possible to zero, and in doing so, makes it impossible for the damage-limited-by-hit-points thing to be true because it's asking for 75 points of damage to a 25 hit point target. It should either expect a value of 50 ( the regen value) or else not expect limits on the amount of damage. Assuming that both the damage and the regeneration are essentially "simultaneous", there shouldn't be a limit -- 10 points of damage plus 20 points of regen plus current 5 hit points should equal 15, dammit. Not 20.

IMHO.

I don't know what to do. I don't really know how to do this stuff, I'm just guessing. I'm too tired to ask for help on the wiki coherently. I'm going to bed.

Hell, someone probably already implemented what I did anyway, and it's just waiting to be committed or whatever the term is, I don't know. I didn't claim the story, just wanted to see what tests I could pass.


A Koan

chromatic on 2003-10-23T05:23:53

One day, a novice approached the master.

"Master," he said, "there are contradictions in the Tao. To achieve enlightenment, you must clear your mind. To achieve enlightenment, you must be mindful of the Universe."

"Yes," replied the master. "Off by one error."

At this, the novice was enlightened.

Index: t/customertests/AllowPlayersToAttackICE.t
===================================================================
--- t/customertests/AllowPlayersToAttackICE.t (revision 20)
+++ t/customertests/AllowPlayersToAttackICE.t (working copy)
@@ -69,6 +69,6 @@
$computer->ice( 1 );
$deck->power( 10 );
$result = $deck->attack( $computer );
-is( $computer->ice(), 49, '... taking into account damage per attack' );
+is( $computer->ice(), 41, '... taking into account damage per attack' );
isnt( $computer->data( $result ), 'more secrets',
'... regenerating before taking damage' );

Re:A Koan

jmm on 2003-10-23T16:31:38

You still look backwards to me.

You either add regen first and then subtract damage (without going below zero) which gives the 41 result you're testing for; or subtract damage first (without going below zero) and then add regen which gives a result of 50. The second is implied by your problem statement (no more damage can be applied than the hit points at the START of the period). A conceivable third approach would be to apply the damage in the middle of te regen: add half of regen value, subtract damage (max current hit points), add remaining regen. In this case, that would again result in 41, but if the regen amount were 10 instead of 50 the three results would all differ (damage then regen: 10; half regen then damage then half regen: 5; regen then damage: 1).