SimpleActuators

This module contains the simple actuators classes. Simple actuators are movement related one. They allow for predetermined movements patterns.

class gamelib.Actuators.SimpleActuators.PathActuator(path=None, parent=None)

Bases: gamelib.Actuators.Actuator.Actuator

The path actuator is a subclass of Actuator. The move inside the function next_move depends on path and index. If the state is not running it returns None otherwise it increments the index & then, further compares the index with length of the path. If they both are same then, index is set to value zero and the move is returned back.

Parameters:
next_move()

Return the movement based on current index

The movement is selected from path if state is RUNNING, otherwise it should return None. When state is RUNNING, the movement is selected before incrementing the index by 1. When the index equal the length of path, the index should return back to 0.

Returns:The next movement
Return type:int | None

Example:

pathactuator.next_move()
pause()

Set the actuator state to PAUSED.

Example:

mygame.pause()
set_path(path)

Defines a new path

This will also reset the index back to 0.

Parameters:path (list) – A list of movements.

Example:

pathactuator.set_path([Constants.UP,Constants.DOWN,Constants.LEFT,Constants.RIGHT])
start()

Set the actuator state to RUNNING.

If the actuator state is not RUNNING, actuators’ next_move() function (and all derivatives) should not return anything.

Example:

mygame.start()
stop()

Set the actuator state to STOPPED.

Example:

mygame.stop()
class gamelib.Actuators.SimpleActuators.PatrolActuator(path=None, parent=None)

Bases: gamelib.Actuators.SimpleActuators.PathActuator

The patrol actuator is a subclass of PathActuator. The move inside the function next_move depends on path and index and the mode. Once it reaches the end of the move list it will start cycling back to the beggining of the list. Once it reaches the beggining it will start moving forwards If the state is not running it returns None otherwise it increments the index & then, further compares the index with length of the path. If they both are same then, index is set to value zero and the move is returned back.

Parameters:path (list) – A list of directions.
next_move()

Return the movement based on current index

The movement is selected from path if state is RUNNING, otherwise it should return None. When state is RUNNING, the movement is selected before incrementing the index by 1. When the index equals the length of path, the index should return back to 0 and the path list should be reversed before the next call.

Returns:The next movement
Return type:int | None

Example:

patrolactuator.next_move()
pause()

Set the actuator state to PAUSED.

Example:

mygame.pause()
set_path(path)

Defines a new path

This will also reset the index back to 0.

Parameters:path (list) – A list of movements.

Example:

pathactuator.set_path([Constants.UP,Constants.DOWN,Constants.LEFT,Constants.RIGHT])
start()

Set the actuator state to RUNNING.

If the actuator state is not RUNNING, actuators’ next_move() function (and all derivatives) should not return anything.

Example:

mygame.start()
stop()

Set the actuator state to STOPPED.

Example:

mygame.stop()
class gamelib.Actuators.SimpleActuators.RandomActuator(moveset=None, parent=None)

Bases: gamelib.Actuators.Actuator.Actuator

A class that implements a random choice of movement.

The random actuator is a subclass of Actuator. It is simply implementing a random choice in a predefined move set.

Parameters:
next_move()

Return a randomly selected movement

The movement is randomly selected from moveset if state is RUNNING, otherwise it should return None.

Returns:The next movement
Return type:int | None

Example:

randomactuator.next_move()
pause()

Set the actuator state to PAUSED.

Example:

mygame.pause()
start()

Set the actuator state to RUNNING.

If the actuator state is not RUNNING, actuators’ next_move() function (and all derivatives) should not return anything.

Example:

mygame.start()
stop()

Set the actuator state to STOPPED.

Example:

mygame.stop()
class gamelib.Actuators.SimpleActuators.UnidirectionalActuator(direction=10000100, parent=None)

Bases: gamelib.Actuators.Actuator.Actuator

A class that implements a single movement.

The unidirectional actuator is a subclass of Actuator. It is simply implementing a mono directional movement. It is primarily target at projectiles.

Parameters:
  • direction (int) – A single direction from the Constants module.
  • parent (gamelib.BoardItem.BoardItem) – The parent object to actuate.
next_move()

Return the direction.

The movement is always direction if state is RUNNING, otherwise it returns None.

Returns:The next movement
Return type:int | None

Example:

unidirectional_actuator.next_move()
pause()

Set the actuator state to PAUSED.

Example:

mygame.pause()
start()

Set the actuator state to RUNNING.

If the actuator state is not RUNNING, actuators’ next_move() function (and all derivatives) should not return anything.

Example:

mygame.start()
stop()

Set the actuator state to STOPPED.

Example:

mygame.stop()