Name

Cosair::AI::Util - Cosair AI Library of miscellaneous utility functions


Synopsis

This class contains static utility functions useful for programming in the AI framework.


Description

Mathematical Functions

floor($)

Returns the passed number rounded down.

ceil($)

Returns the passed number rounded up.

round($)

Returns the passed number rounded arithmetically.

Set Functions

Sets are strings with comma delimitered elements. The following methods ease the handling with these types that often occur in the games data structures.

set_new(@)

Creates a new set containing the given values.

set_elements($)

Returns an array of the elements in a given set. The only parameter is the set.

set_contains($$)

Returns a boolean value indicating whether a given element is contained in a given set or not. The first parameter is the set to search in, the second one is the element to be searched for.

set_add($$)

Adds a given element to a given set, it it is not contained yet. The first parameter is the set to add to, the second one is the element to be added.

set_remove($$)

Removes a given element from a given set. The first parameter is the set to remove from, the second is the element to be removed.

Array Functions

min(@)

Returns the minimum value of a given array of numerical values.

max(@)

Returns the maximum value of a given array of numerical values.

sum(@)

Returns the sum of all values in a given array of numerical values. Returns undef in case of an empty list.

contained($@)

Returns a boolean value indicating whether a given value is contained in a given list of values. The first parameter is the value to search for, the following parameters from the list to search in.

first BLOCK (@)

Returns the first element of a given list matching a condition specified in a BLOCK, whereas $_ is the list element in the block.

first_index BLOCK (@)

Returns the array index of the first element of a given list matching a condition specified in a BLOCK, whereas $_ is the list element in the block.

Randomness Functions

probe($)

Returns a true boolean value with a given probability, a false boolean value otherwise. The only parameter is a floating point number between 0 and 1.

rand_element(@)

Returns an element by random from a given list. The only paramter is an array of values to choose from, the return value is one of these values.

rand_elements($@)

Returns a given number of elements by random from a given list. The first parameter is the number of elements to return. The second parameter is an array of values to choose from. The return value is an array of these values.

shuffle(@)

Returns the elements of a given array in a random order. The only parameter is the array to shuffle. The return value is an array of the same length and with the same values, but a potentially different ordering.