DnD_5e.tactics package

Subpackages

Module contents

class DnD_5e.tactics.Tactic(**kwargs)[source]

Bases: object

A base class for classes that choose an item based on an algorithm stored in method run_tactic

get_name() str[source]
Returns:

name

Return type:

str

get_tiebreakers() list[source]
Returns:

tiebreakers

Return type:

list of Tactic s

get_verbose() bool[source]
Returns:

verbose setting

Return type:

bool

append_tiebreaker(tiebreaker)[source]

Add the given tiebreaker to the end of the tiebreakers list

Parameters:

tiebreaker (Tactic) – the tiebreaker to add

Returns:

None

Raise:

ValueError if tiebreaker is not a Tactic or self already has tiebreaker as a tiebreaker

extend_tiebreakers(tact)[source]

Add the tiebreakers of the given Tactic to the end of the tiebreakers list

Parameters:

tiebreaker (Tactic) – the tiebreaker to add

Returns:

None

Raise:

ValueError if tiebreaker is not a Tactic or self already has tiebreaker as a tiebreaker

run_tactic(choices: list, **kwargs) list[source]

Use the class’s algorithm to select an option from a list. This is the default implementation and it chooses an option at random. This method should be overridden in subclassses.

Parameters:

choices (list) – the options to choose from

Returns:

a list of the chosen items.

List may be empty, it may be identical to choices, or it may contain some (but not all) of the options in choices.

make_choice(choices: list, **kwargs)[source]

Return exactly one option from choices. The process is this: Try run_tactic(). If only one option is returned, you are done. Else, try running tiebreakers (in order) until you arrive at one option. If you still don’t have exactly one option, choose a random option from whatever is left.

Parameters:
  • choices (list) – the options to choose from

  • **kwargs

    keyword arguments to be passed on to run_tactic()

Returns:

the chosen element

class DnD_5e.tactics.ThresholdTactic(**kwargs)[source]

Bases: Tactic

A tactic that has a threshold of some kind (e.g., ac higher than a given number)

calculate_threshold(**kwargs) int[source]

Calculate threshold using keyword arguments.

Parameters:

kwargs – passed on from constructor

Returns:

threshold

validate_threshold()[source]
Returns:

Raise:

ValueError if threshold is invalid

get_threshold() int[source]
Returns:

threshold

class DnD_5e.tactics.ConditionTactic(**kwargs)[source]

Bases: Tactic

Tactics that select items that meet a certain condition

check_condition(item, **kwargs) bool[source]

Check this tactic’s condition. To be implemented in subclasses.

Parameters:

item – the option that the condition is checked on

Returns:

indication of whether the condition is met or not

run_tactic(choices: list, **kwargs) list[source]

Select the item(s) that meet the given condition

Parameters:

choices (list) – the options to choose from

Returns:

the options that meet the condition

class DnD_5e.tactics.MinTactic(**kwargs)[source]

Bases: Tactic

Select the item(s) that have the lowest value in the given field

get_value(item, **kwargs)[source]

Get the value for whatever detail of item we are concerned about

Parameters:

item – the option we are looking at

Returns:

the numerical value of whatever detail we are concerned about

run_tactic(choices: list, **kwargs) list[source]

Select the item(s) that have the lowest value in the given field

Parameters:

choices – the options to choose from

Returns:

the options that have the lowest value in the given field

class DnD_5e.tactics.MaxTactic(**kwargs)[source]

Bases: Tactic

Select the item(s) that have the highest value in the given field

get_value(item, **kwargs)[source]

Get the value for whatever detail of item we are concerned about

Parameters:

item – the option we are looking at

Returns:

the numerical value of whatever detail we are concerned about

run_tactic(choices: list, **kwargs) list[source]

Select the item(s) that have the highest value in the given field

Parameters:

choices – the options to choose from

Returns:

the options that have the highest value in the given field