player

author:Laurens Koppenol

Module to handle players. See Adding AI on how to create new players

class player.DistanceSensor(player, angle, depth)[source]

Linear distance sensor using a simple raytracing algorithm. This sensor is drawable because it has percept, depth and a get_absolute_angle function. At the moment this is required to be drawn.

get_absolute_angle()[source]

Use the player’s angle and the sensor’s offset to return the absolute angle of the sensor.

Returns:angle in degrees
perceive(track)[source]

Update the sensor values. Returns them and sets them as internal value. Returns max depth if nothing is perceived

Parameters:track – Environment object
Returns:distance value
class player.HumanPlayer[source]

Human Player that does not have sensors but responds to key input

plan(percepts)[source]

Listen to key input.

Parameters:percepts – dict of keys that are pressed
Returns:acceleration_command, rotation_command
sense(track, keys)[source]

Nothing is sensed, keys are passed on to plan() function.

Parameters:
  • track – Environment object
  • keys – dictionary of keys
Returns:

keys dictionary

class player.NaiveAi[source]

Super simple Naive AI that will try to stay away from the walls. User ray-tracing sensors (DistanceSensor).

plan(percepts)[source]

Use the percepts to choose actions. This naive AI will match a certain speed and rotate away from the nearest visible wall.

Parameters:percepts
Returns:acceleration_command, rotation_command
sense(track, keys)[source]

Calls its sensors using the track information to find distance to the walls.

Parameters:
  • track – Environment object
  • keys – Not used
Returns:

a list with distances per sensor

class player.Player[source]

Abstract class. Subclass this if you want to make a new player. See readthedocs for more info.

change_position(delta_coordinate)[source]

Adjust player position

Parameters:delta_coordinate – incremental coordaintes (dx, dy)
Returns:Nothing
get_position(pixel=False, scale=1)[source]

Get player position

Parameters:
  • pixel – wether to round down to full pixels
  • scale – whether to scale (for drawing purposes)
Returns:

coordinates (x, y)

plan(percepts)[source]

Use percepts to get an action

Parameters:percepts – output of sense() function
Returns:acceleration_command, rotation_command. both in range [-1, 1]
sense(track, keys)[source]

Meant to get information about the environment from the track / key input

Parameters:
  • track – Environment object
  • keys – dictionary of keys
Returns:

percepts

set_position(coordinate)[source]

Set new player position

Parameters:coordinate – new coordinate (x, y)
Returns:Nothing