Random2

This module provides a player that performs random actions in a PyRat game. Contrary to the Random1 player, this one takes into account the maze structure to avoid hitting walls.

class Random2.Random2(*args, **kwargs)[source]

(This class inherits from Player ).

This player is an improvement of the Random1 player. Contrary to that previous version, here we take into account the maze structure. More precisely, we select at each turn a random move among those that don’t hit a wall.

__init__(*args, **kwargs)[source]

Initializes a new instance of the class. Here, the constructor is only used to initialize the player. It transmits the arguments to the parent constructor, which is responsible for initializing the name and the skin of the player.

Parameters:
  • args (object) – Arguments to pass to the parent constructor.

  • kwargs (object) – Keyword arguments to pass to the parent constructor.

turn(maze, game_state)[source]

(This method redefines the method of the parent class with the same name).

It is called at each turn of the game. It returns an action to perform among the possible actions, defined in the Action enumeration.

Parameters:
  • maze (Maze) – An object representing the maze in which the player plays.

  • game_state (GameState) – An object representing the state of the game.

Return type:

Action

Returns:

One of the possible actions.

find_next_action(maze, game_state)[source]

This method returns an action to perform among the possible actions, defined in the Action enumeration. Here, the action is chosen randomly among those that don’t hit a wall.

Parameters:
  • maze (Maze) – An object representing the maze in which the player plays.

  • game_state (GameState) – An object representing the state of the game.

Return type:

Action

Returns:

One of the possible actions that leads to a valid neighbor.