Skip to content

Proposal for Arrangement Handling

Karl R. Wilcox edited this page Dec 6, 2019 · 3 revisions

Proposal for Arrangement Handling

Background

This page is a placeholder for some thoughts about some new code to manage the arrangement of charges on the field. The placement of any given charge depends on many criteria, not limited to:

  • How many other charges there are
  • The "shape" of the area available
  • Specific ordering of rows given in the blazon
  • A specific arrangement given in the blazon
  • Whether the charges are "on" or "around" an ordinary, or another charge
  • Whether the charges, once arranged, are then placed in a specific location by the blazon

At present this functionality is implemented by a 1,200+ line if/then/else statement. This is not ideal(!). It is fragile, hard to debug and not clear what combinations of the criteria above are actually handled.

The Proposal in Overview

It is proposed to implement the arrangements as a (large) single dimension, array of keys and values.

  • The key will encode a specific set of arrangement criteria
  • The value will encode instructions for the placement of a charge meeting those criteria

(The value will be very similar to that currently returned by the existing if/then/else implementation).

A function will be written that takes as input the specific criteria (no. of charges, specific arrangement, etc.). It will search the array keys for a "match" with the criteria encoded within the key. The matching process will assign each key a "penalty score", where a value of zero implies an exact match of criteria. The function will return the value corresponding to the key with the lowest penalty score.

Encoding of Keys

Encoding of Values

Values are all of the type String. There are 3 variations, distinguished by the first character of the string:

  • '!' indicates that the arrangement is not possible (e.g. arrannging 2 charges "in cross"). The remainder of the string is an appropriate error message

  • '>' indicates that a "helper" function should be called, which will calculate the actual value to return. The rest of the string is the name of the helper function, (???followed by any arguments separated by slashes....???)

  • '[0-9]' indicates a position instruction, the format of which is given below

(Any other value for the first character should be treated as an internal error)

Encoding of Position Instructions