Skip to content

class aicafe.SnakeSet

This class represents a set of snakes. To initialize a snake set, see __init__() below.

__init__(self, snakes, types=None)

Initialize a snake set.

Parameters:

Name Type Description Default
snakes Sequence[ArrayLike]

Each array is used to initialize one snake, so it must satisfy the requirements for initializing a snake, see __new__() of Snake for more information.

required
types Sequence[int]

The types of snakes represented by integers. Only used when values in snakes are ArrayLike.

None

lengths(self, idxs=None)

Lengths of some snakes in self.

Parameters:

Name Type Description Default
idxs Sequence[int]

List of integer indexes of snakes. If None, the lengths of all snakes will be calculated.

None

Returns:

Type Description
list[float]

The lengths of designated snakes.

Examples:

>>> # 3 snakes
>>> ss = ac.SnakeSet([[[0, 0, 0], [1, 0, 0]], 
...                   [[2, 0, 0], [4, 0, 0]], 
...                   [[6, 0, 0], [9, 0, 0]]])
>>> ss.lengths()
[1.0, 2.0, 3.0]
>>> ss.lengths([2, 0])
[3.0, 1.0]

n_snakes(self)

The number of snakes. Can also get it using len(self).

types(self)

Types of snakes, represented by integers, as defined in TYPES_SNAKES.

Back to top