Skip to content
Snippets Groups Projects
Commit 02072585 authored by OUAGAGUE Loqman's avatar OUAGAGUE Loqman
Browse files

cleaninig up

parent 0171e6a1
No related branches found
No related tags found
No related merge requests found
#####################################################################################################################################################
######################################################################## INFO #######################################################################
#####################################################################################################################################################
"""
This file contains useful elements to define a particular player.
In order to use this player, you need to instanciate it and add it to a game.
Please refer to example games to see how to do it properly.
"""
#####################################################################################################################################################
###################################################################### IMPORTS ######################################################################
#####################################################################################################################################################
# External imports
from typing import *
from typing_extensions import *
from numbers import *
# PyRat imports
from pyrat import Player, Maze, GameState, Action
#####################################################################################################################################################
###################################################################### CLASSES ######################################################################
#####################################################################################################################################################
class TemplatePlayer (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" and "postprocessing" are optional.
Method "turn" is mandatory.
"""
#############################################################################################################################################
# CONSTRUCTOR #
#############################################################################################################################################
def __init__ ( self: Self,
*args: Any,
**kwargs: Any
) -> Self:
"""
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 and set their initial values.
Arguments *args and **kwargs are used to pass arguments to the parent constructor.
This is useful not to declare again all the parent's attributes in the child class.
In:
* self: Reference to the current object.
* args: Arguments to pass to the parent constructor.
* kwargs: Keyword arguments to pass to the parent constructor.
Out:
* A new instance of the class.
"""
# Inherit from parent class
super().__init__(*args, **kwargs)
# Print phase of the game
print("Constructor")
#############################################################################################################################################
# PYRAT METHODS #
#############################################################################################################################################
@override
def preprocessing ( self: Self,
maze: Maze,
game_state: GameState,
) -> None:
"""
This method redefines the method of the parent class.
It is called once at the beginning of the game.
In:
* self: Reference to the current object.
* maze: An object representing the maze in which the player plays.
* game_state: An object representing the state of the game.
Out:
* None.
"""
# Print phase of the game
print("Preprocessing")
#############################################################################################################################################
@override
def turn ( self: Self,
maze: Maze,
game_state: GameState,
) -> Action:
"""
This method redefines the abstract method of the parent class.
It is called at each turn of the game.
It returns an action to perform among the possible actions, defined in the Action enumeration.
In:
* self: Reference to the current object.
* maze: An object representing the maze in which the player plays.
* game_state: An object representing the state of the game.
Out:
* action: One of the possible actions.
"""
# Print phase of the game
print("Turn", game_state.turn)
# Return an action
return Action.NOTHING
#############################################################################################################################################
@override
def postprocessing ( self: Self,
maze: Maze,
game_state: GameState,
stats: Dict[str, Any],
) -> None:
"""
This method redefines the method of the parent class.
It is called once at the end of the game.
In:
* self: Reference to the current object.
* maze: An object representing the maze in which the player plays.
* game_state: An object representing the state of the game.
* stats: Statistics about the game.
Out:
* None.
"""
# Print phase of the game
print("Postprocessing")
#####################################################################################################################################################
#####################################################################################################################################################
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment