TemplatePlayer¶
This module provides a template for creating a new player in a PyRat game.
It defines a class that inherits from Player
and provides methods that can be overridden to implement your own player.
You can use this template to create a new player by copying this file and renaming it.
You can then modify the class name and the methods to implement your own player logic.
- class TemplatePlayer.TemplatePlayer(*args, **kwargs)[source]¶
(This class inherits from
Player
).This player is basically a player that does nothing except printing the phase of the game. It is meant to be used as a template to create new players. Methods
preprocessing()
, andpostprocessing()
are optional. Methodturn()
is mandatory.- __init__(*args, **kwargs)[source]¶
This function is the constructor of the class. When an object is instantiated, this method is called to initialize the object. This is where you should define the attributes of the object. We advise that you initialize these attributes of the object in the
preprocessing()
method to allow the game to be reset.- Parameters:
args (
object
) – Arguments to pass to the parent constructor.kwargs (
object
) – Keyword arguments to pass to the parent constructor.
- preprocessing(maze, game_state)[source]¶
(This method redefines the method of the parent class with the same name).
This method is called once at the beginning of the game. It can be used to initialize attributes or to perform any other setup that is needed before the game starts. It typically is given more computational resources than the
turn()
method. Therefore, it is a good place to perform any heavy computations that are needed for the player to function correctly.- 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:
None
- turn(maze, game_state)[source]¶
(This method redefines the method of the parent class with the same name).
This method is called at each turn of the game. It returns an action to perform among the possible actions, defined in the
Action
enumeration. It is generally given less computational resources than thepreprocessing()
method. Therefore, you should limit the amount of computations you perform in this method to those that require real-time information.- 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 action, defined in the
Action
enumeration.
- postprocessing(maze, game_state, stats)[source]¶
(This method redefines the method of the parent class with the same name).
This method is called once at the end of the game. It can be used to perform any cleanup that is needed after the game ends. It is not timed, and can be used to analyze the completed game, train models, etc.
- Parameters:
maze (
Maze
) – An object representing the maze in which the player plays.game_state (
GameState
) – An object representing the state of the game.stats (
dict
[str
,object
]) – A dictionary containing statistics about the game.
- Return type:
None