Udebs Api

Instance

class udebs.instance.Instance(is_copy=False, init='init', **options)[source]

Main instance class that represents the state space of the entire game.

Note on naming convention:

All methods beginning with ‘get’ return information about the game’s state space and are not allowed to change the state itself.

All methods beginning with ‘control’ or ‘cast’ manage some aspect of the state space and return true if changes were (probably) made and false otherwise.

Other functions are convenience wrappers for public use.

castAction(caster, move, **kwargs)[source]

Cast an action with only a caster.

<i>caster [$caster] ACTION move</i>
castFuture(caster, target, move, **kwargs)[source]

Same as castMove except returns a copy of instance if move succeeds. Does not change original instance.

Clones do not log output or generate reserve states.

main_map.castFuture(caster, target, move)
castInit(moves, **kwargs)[source]

Cast an action without variables.

<i>INIT move</i>
castLambda(string)[source]

Call a function directly from a user input effect String.

main_map.castLambda("caster CAST target move")
castMove(caster, target, move, force=False, time=None)[source]

Cast an action including both a caster and a target.

<i>caster [$caster] CAST target move</i>
castSingle(string)[source]

DEPRECATED - Please use castLambda

Call a function directly from a user input effect String.

main_map.castSingle("caster CAST target move")
controlAnd(*args, storage=None)[source]

A basic and statement. Executes arguments until one of them is false.

Returns True if all statements are true. False otherwise.

<i>AND `(condition1) `(condition2)</i>
controlClear(targets, lst)[source]

Removes all from a targets list attribute.

<i>target [$caster] CLEAR lst</i>
controlDelay(callback, time, storage)[source]

Delays an effect a number of ticks.

Note: A delay of 0 will delay an action until the end of the current action window. Note: Notice the back tick.

<i>DELAY `(caster CAST target move) 0</i>
controlDelete(target)[source]

Permanently remove an object from the game.

<i>target DELETE</i>
controlIncrement(targets, stat, increment, multi=1)[source]

Increment a statistic by a static value.

Note: Final value will be modified as follows (Stat = Stat + (increment * multi))

<i>target stat += increment</i>
<i>target stat -= increment</i>
<i>target [$caster] stat CHANGE increment</i>
controlListAdd(targets, lst, entries)[source]

Adds an element to a list.

<i>caster [$caster] lst GETS entries</i>
controlListRemove(targets, lst, entries)[source]

Removes an element from a list.

<i>caster [$caster] lst LOSES entries</i>
controlOr(*args, storage=None)[source]

A basic or statement. Executes arguments in order until one of them is true.

Returns True if any argument is ture, False otherwise.

<i>OR `(condition1) `(condition2)</i>
controlRecruit(target, positions)[source]

Create a new entity by copying another then move it to a position.

Note: If position is not set copy will be made but not moved into a location. Note: One new entity will be created for each position given.

<i>caster [$caster] RECRUIT position ["#empty"]</i>
controlRepeat(callback, amount, storage, force=False, timeout=100)[source]

Executes a callback n times. The final argument is to force retries. If set to True system will retry failures until exactly n attempts succeed. Over 100 consecutive failures will trigger an exception. Value defaults to False.

<i>REPEAT `(callback) 5 False</i>
controlShuffle(targets, lst)[source]

Randomize order of a list.

<i>target SHUFFLE lst</i>
controlString(targets, stat, value)[source]

Replace a value with another value.

Note: This function also works on all attributes.

<i>caster [$caster] stat REPLACE value</i>
controlTime(time=None, script='tick')[source]

Increments internal time by ‘time’ ticks, runs tick script, and activates any delayed effects.

<i>TIME time</i>
controlTravel(caster, targets=None)[source]

Move one object to a new location.

<i>caster [$caster] MOVE target</i>
copy() → a shallow copy of D[source]
exit(value=1)[source]

Requests the end of the game by setting Instance.cont to False, and exiting out of the game_loop.

<i>EXIT</i>
gameLoop(time=1, script='tick')[source]

Iterate over in game time.

for state in main_map.gameLoop():
    state.castMove(caster, target, move)
getDistance(caster, target, method)[source]

Returns distance between caster and target using method as a metric.

<i>PATH method caster [$caster] target [$target]</i>
getEntity(target)[source]

Fetches the udebs entity object given a selector.

Udebs selectors can take all the following forms.

  • string - The name of the object we are looking for.
  • tuple - A tuple of the form (x, y, name) representing a location on a map.
  • list - A list containing other selectors.
  • None - Returns the default empty selector.
<i># identifier</i>
getFill(center, callback=None, include_center=True, distance=None)[source]

Gets all squares in a pattern starting at center, using callback as filter for valid space.

<i>FILL center callback include_center [true] distance [null]</i>
getGroup(*args)[source]

Return all objects belonging to group. Can take multiple arguments and returns all objects belonging to any group.

<i>ALL group</i>
getListGroup(target, lst, group)[source]

Returns first element in list that is a member of group.

<i>target [$caster] lst LISTGROUP group</i>
<i>target [$caster] CLASS group</i>
getListStat(target, lst, stat)[source]

Returns sum of all object stats in a list.

<i>target [$caster] lst LISTSTAT stat</i>
getLocData(target, value=0)[source]

Gets the x, y, or map name coordinate of target, False if target not on a map.

<i>target [$caster] XLOC</i>
<i>target [$caster] YLOC</i>
<i>target [$caster] MAPNAME</i>
static getLocObject(target)[source]

Gets the location tuple of a target, False if target not on a map.

<i>target [$caster] LOC</i>
getMap(target='map')[source]

Fetches the map object caster currently resides on.

<i>caster [$caster] MAP</i>
static getName(target)[source]

Gets the name of a target.

<i>target [$caster] NAME</i>
getPath(caster, target, callback)[source]

Finds a path between caster and target using callback as filter for valid space.

<i>PATH callback caster [$caster] target [$target]</i>
getQuote(target, skip_interpret=True)[source]

Returns a literal script as a new anonymous entity.

<i>`($caster.NAME not-in $card)</i>
getRevert(time=0)[source]

Returns a previous game state.

Note: time represents how many ticks to revert.

main_map.getRevert(5)
getSearch(*args)[source]

Return objects contained in all given groups.

<i>SEARCH arg1 arg2 ...</i>
getShift(target, x, y, name=None)[source]

Returns a new loc shifted x and y units from an old one

<i>target [$caster] SHIFT x y</i>
getStat(target, stat)[source]

General getter for all attributes.

Note: Attributes will include values inherited from their group.

<i>target [$caster] STAT stat</i>
getVar(target)[source]

Gets variables attached to the instance itself.

..code-block:: xml

<i>VAR time</i>
printMap(board='map')[source]

Print a map.

resetState(script='reset')[source]

Resets the game metadata to default.

main_map.resetState()
testBlock(caster, target, callback, max_dist=None)[source]

Test to see if path exists between caster and target using callback as filter for valid space.

<i>BLOCK callback caster [$caster] target [$target]</i>
testMove(caster, target, move)[source]

Simulates an action. Returns true if the requirements passes successfully, False otherwise.

main_map.testMove(caster, target, move)

Standard

Xml

udebs.loadxml.battleStart(xml_file=None, field=<class 'udebs.instance.Instance'>, **overwrite)[source]

Creates an instance object from given xml file.

xml_file - String representing file to look in. debug - Boolean that gets passed to the interpret function. script - Override the script that runs after initialization

udebs.loadxml.battleWrite(env, location, pretty=False)[source]

Writes an instance object to file.

env - Instance object to write. location - Variable to pass to xml.etree.write.

Utilities

class udebs.utilities.Timer(verbose=True, name='')[source]

Basic Timing context manager. Prints out the time it takes its context to close.

udebs.utilities.alternate(*args)[source]

An alternation function for processing moves.

udebs.utilities.modify_state(state, entities=None, logging=True, revert=True)[source]

Experimental: Creates a copy of an Instance object with modifications designed for improved tree search.

udebs.utilities.no_recurse(f)[source]

Wrapper function that forces a function to return True if it recurse.

udebs.utilities.register(local_raw=None, globs_raw=None, name=None)[source]

Register a function with udebs using a decorator.

@udebs.register({"args": ["$1", "$2", "$3"]})
def TEST(arg1, arg2, arg3):
    return "hello world"

@udebs.register({"args": ["$1", $2, $3]})
class Test3:
    def __init__(self):
        self.message = "hello "

    def __call__(self, world):
        return self.message + world
<i>TEST one two three</i>
udebs.utilities.register_raw(func, local=None, globs=None, name=None)[source]

Use this to register a function without using a decorator. func - The function to register local - Local call pattern for given function. globs - Dictionary of global objects to add to udebs. name - Name to give function (defaults to func.__name__)

def TEST2(arg1, arg2, arg3):
        return "hello world"

udebs.register(TEST2, {"args": ["$1", "$2", "$3"]})

Errors

exception udebs.errors.UdebsError[source]

Base class for all Udebs errors.

exception udebs.errors.UdebsExecutionError(script)[source]

Is raised when an error occurs during execution of an udebs action.

exception udebs.errors.UdebsSyntaxError(string)[source]

Is raised when an effect or require is malformed and fails to parse.

exception udebs.errors.UndefinedSelectorError(target, _type)[source]

Is raised when udebs encounters an invalid reference to an udebs object.