astar_agent

class rbgame.agent.astar_agent.Vertex(y, x, color='w', target=0, robot=None, mail=0, *, front=None, back=None, left=None, right=None)[source]

Bases: object

Similar to Cell.

Parameters:
  • x (int) – The abscissa in the graph. The coordinate origin is at the top left point, positive direction from left to right.

  • y (int) – The ordinate in the graph. The coordinate origin is at the top left point, positive direction from top to bottom.

  • color (str) – The color of the vertex. Possible colors are 'w' - white, 'b' - blue, 'r' - red, 'y' - yellow, 'gr' - green, 'g' - gray.

  • target (int) – The target of this vertex.

  • robot (Optional[VRobot]) – The located in this vertex robot.

  • mail (int) – Generated mail in this vertex.

  • front (Optional[Vertex]) – The front vertex of this vertex.

  • back (Optional[Vertex]) – The back vertex of this vertex.

  • left (Optional[Vertex]) – The left vertex of this vertex.

  • right (Optional[Vertex]) – The right vertex of this vertex.

property is_blocked: bool

Vertex is blocked (robot shouldn’t go there) if it has too much robots waiting to go to this vertex.

property neighbors: list[Vertex]

Returns neighboring verties of this vertex.

class rbgame.agent.astar_agent.Graph(colors_map, targets_map)[source]

Bases: object

Similar to Board. It is set of Vertex.

Parameters:
  • colors_map (str) – csv file name for color map. Each element define color of each Vertex.

  • targets_map (str) – csv file name for target map. Each element define target of each Vertex.

A* search for shortest path from start to goal . About algorithm, go here.

Parameters:
  • start (Vertex) – start vertex.

  • goal (Vertex) – end vertex.

Return type:

list[Vertex]

Returns:

Path from start vertex to end vertex. Start vertex doesn’t includes in found path. Return to empty list if path not found.

class rbgame.agent.astar_agent.VRobot(pos, battery=0, mail=0)[source]

Bases: object

Similar to Robot.

Parameters:
  • pos (Vertex) – Current position of the robot.

  • mail (int) – The mail that robot are carring.

  • battery (int) – The battery.

property is_charged: bool

Robot is charging or not.

set_destination(board, blocked=[])[source]

Set destination for robot base on its state.

Parameters:
  • board (Graph) – A graph to get destination from it.

  • blocked (list[Vertex]) – List of blocked vertices that destination shouldn’t be in.

Return type:

None

class rbgame.agent.astar_agent.AStarAgent(colors_map, targets_map, num_robots, maximum_battery=None)[source]

Bases: BaseAgent

A controller for single robot, using A* star search shortest path. See algorithm in Pure agent using A* path finding algorithm.

Parameters:
  • colors_map (str) – Colors map of the graph.

  • targets_map (str) – Target map of the graph.

  • num_robots (int) – Number of robots on the game board.

  • maximum_battery (Optional[int]) – Maximum battery for robot.

get_action(obs)[source]

Compute action from observation.

Parameters:

obs (dict[str, ndarray]) – Observation and action mask from game.

Return type:

int

Returns:

Action.