Ticket #156 (new task)

Opened 1 year ago

Last modified 1 year ago

Owl code refactorization

Reported by: gunnar Assigned to: gnugo
Priority: normal Milestone: 3.8
Component: source Version:
Severity: normal Keywords:
Cc: patch: 1

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 (65.0 kB) - added by gunnar on 12/17/06 22:18:50.
Owl code restructuring.

Change History

12/17/06 22:18:50 changed by gunnar

  • attachment gunnar_7_11.4.diff added.

Owl code restructuring.

12/17/06 22:30:15 changed by gunnar

  • patch set to 1.

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