Ticket #156 (new task)

Opened 4 years ago

Last modified 18 months ago

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

gunnar_7_11.4.diff Download (65.0 KB) - added by gunnar 4 years ago.
Owl code restructuring.

Regression Results

Attachment Rev. PASS FAIL Nodes Status
gunnar_7_11.4.diff Download 2381 crashed in regressions details

Change History

Changed 4 years ago by gunnar

Owl code restructuring.

Changed 4 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()

Changed 18 months ago by gunnar

  • milestone changed from 3.8 to Future
Note: See TracTickets for help on using tickets.