Ticket #156 (new task)
Owl code refactorization
| Reported by: | gunnar | Owned by: | gnugo |
|---|---|---|---|
| Priority: | normal | Milestone: | Future |
| Component: | source | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | patch: | yes |
Description
The aim of this ticket is to address two structural weaknesses of the owl code. The first one is that there is a considerable amount of code duplication in owl_attack(), owl_defend(), do_owl_attack(), do_owl_defend(), owl_threaten_attack(), owl_threaten_defense(), owl_does_attack(), owl_does_defend(), owl_connection_defends(), owl_confirm_safety(), and owl_substantial(). The second weakness is that in some of those functions the owl data is initialized from dragon and worm data when stackp>0, which is shaky to say the least.
Practically enough these weaknesses can be addressed simultaneously. The idea is that the parts of do_owl_attack() and do_owl_defend() involving playing a move and updating the owl information are split off to two new functions owl_attack_trymove() and owl_defend_trymove(). Then all the rest of the functions listed above (except possibly owl_substantial()) do owl initialization at stackp=0 and then use the owl_*_trymove() functions to play the move they need before calling either of do_owl_attack() and do_owl_defend().
Attachments
Regression Results
| Attachment | Rev. | PASS | FAIL | Nodes | Status | |
| gunnar_7_11.4.diff | 2381 | crashed in regressions | details |
Change History
Changed 5 years ago by gunnar
-
attachment
gunnar_7_11.4.diff
added
comment:1 Changed 5 years ago by gunnar
- patch set
The patch gunnar_7_11.4 breaks out owl_attack_trymove() and owl_defend_trymove() functions from do_owl_attack() and do_owl_defend() respectively. To simplify this the "str" and "escape" parameters to the latter functions have been replaced by new fields in the local_owl_data struct called origin and escape_moves.
Additionally some of the entry functions to the owl code (e.g. owl_does_defend() and so on) have been moved around to form a single block of code.
There is no change in functionality. Exactly the same owl reading takes place after this patch.
- new fields origin and escape_moves in struct local_owl_data - new static functions owl_attack_trymove(), owl_defend_trymove(), and owl_popgo()

Owl code restructuring.