components

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

Bases: object

A cell in the board.

Note

All attributes except mail after initialization shouldn’t be changed.

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

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

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

  • target (int) – Number of the mail that robot have to delivery to this cell. 0 if cell isn’t receiving station.

  • robot (Optional[Robot]) – The located in this cell robot.

  • mail (Optional[Mail]) – Generated mail in this cell.

  • front (Optional[Cell]) – The front cell of this cell.

  • back (Optional[Cell]) – The back cell of this cell.

  • left (Optional[Cell]) – The left cell of this cell.

  • right (Optional[Cell]) – The right cell of this cell.

draw(surface)[source]

Draw this cell in a surface.

Parameters:

surface (Surface) – Surface to draw this cell in.

Return type:

None

generate_mail(sprites_mail, render_mode)[source]

Generate a new mail and add it to sprites_mail.

Parameters:
  • sprites_mail (Group) – Group of sprites to add new mail.

  • render_mode (str | None) – Render mode of new generated mail.

Return type:

None

property neighbors: list[Cell]

Returns neighboring cells of this cell.

class rbgame.game.components.Board(colors_map, targets_map)[source]

Bases: object

A object representing game board. It is set of Cell.

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

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

reset()[source]

Reset board to empty board.

Return type:

None

class rbgame.game.components.Robot(pos, index, color, sprites_group, clock, mail=None, count_mail=0, battery=10, with_battery=True, render_mode=None, log_to_file=False)[source]

Bases: Sprite

Robot in the board.

Note

Attributes index and color after initialization shouldn’t be changed.

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

  • index (int) – The index of the robot.

  • color (str) – The color of the robot.

  • sprites_group (Group) – Group of mails. We need to add new mail to this group when robot pick up a mail and leaves green cell.

  • clock (Clock) – The game clock. For each step of the robot, time increases by \(\Delta t\).

  • mail (Optional[Mail]) – The mail that robot are carring.

  • count_mail (int) – Number of deliveried mails by robot.

  • battery (int) – The battery.

  • with_battery (bool) – Battery is considered or not.

  • render_mode (Optional[str]) – The render mode. It can be None or 'human'.

  • _to_file (log) – Log game process to file or not.

charge()[source]

Charge.

Return type:

None

drop_off()[source]

Drop off a mail.

Return type:

None

property is_charged: bool

Robot is charging or not.

Check if action is legal.

Parameters:

action (int) – Action to check.

Return type:

bool

Returns:

Possibility of action

property mask: ndarray

Action mask for legal actions.

move_down()[source]

Move back. Pick up or drop off mail if possible.

Return type:

tuple[bool, float]

Returns:

Two value. First, have some movements or not. Second, the reward.

move_left()[source]

Move left. Pick up or drop off mail if possible.

Return type:

tuple[bool, float]

Returns:

Two value. First, have some movements or not. Second, the reward.

move_right()[source]

Move right. Pick up or drop off mail if possible.

Return type:

tuple[bool, float]

Returns:

Two value. First, have some movements or not. Second, the reward.

move_up()[source]

Move forward. Pick up or drop off mail if possible.

Return type:

tuple[bool, float]

Returns:

Two value. First, have some movements or not. Second, the reward.

property next_rect: Rect

Next rectangle, where we should draw it after its movement.

property observation: ndarray

Observation of the single robot. Each of attributes x, y, mail, battery is normalized to forward in neural network.

pick_up()[source]

Pick up a mail.

Return type:

None

reset(pos)[source]

Reset robot to initial state in pos.

Parameters:

pos (Cell) – Position to place robot.

Return type:

None

stand()[source]

Don’t move. Charge if possible.

Return type:

tuple[bool, float]

Returns:

Two value. First, have some movements or not. Second, the reward.

step(action)[source]

Do robot move base on action.

Parameters:

action (int) – Action to execute.

Return type:

tuple[bool, float]

Returns:

Two value. First, have some movements or not. Second, the reward.

class rbgame.game.components.Mail(mail_number, pos, render_mode=None)[source]

Bases: Sprite

A object representing a mail.

Parameters:
  • mail_number (int) – The number of the mail.

  • pos (Cell) – Current location of the mail.

  • render_mode – The render mode. It can be None or 'human'.

class rbgame.game.components.Clock(delta_t=1)[source]

Bases: object

A object measuring game time. For each step of the robot time increases by \(\Delta t\).

Parameters:

delta_t (float) – \(\Delta t\) - time span that we assume for one move.

reset()[source]

Reset to zero time.

Return type:

None

up()[source]

Increases time by \(\Delta t\).

Return type:

None