Discover the project and the PyRat software

Project – Session 1

  • Le jeu PyRat
  • Les objectifs du projet
  • Organisation & évaluation
  • Comment écrire un programme PyRat
  • Récapitulatif de la session

Le jeu PyRat

À quoi ça ressemble ?

Le jeu PyRat

Éléments du jeu

Le jeu PyRat

But du jeu

Comment gagner ?

  • Jeu en équipe unique $\rightarrow$ attraper tout le fromage
  • Jeu en équipes multiples $\rightarrow$ attraper plus de fromage que les autres

Comment jouer ?

Le jeu PyRat

Situations alternatives

Quand un timing est manqué


Autres modes

  • Synchronisé $\rightarrow$ Attendre que tout le monde applique la décision
  • Séquentiel $\rightarrow$ Synchronisé + processus unique
  • Simulation $\rightarrow$ Séquentiel + pas d’interface graphique

Les objectifs du projet

Vue globale

Que faire dans le projet ?

  • Programmer des joueurs pour un jeu PyRat
  • Objectifs de difficulté croissante

Comment faire ?

  • Langage de programmation Python
  • Plus de détails dans les diapositives suivantes

Les objectifs du projet

Session 1


  • Configuration $\rightarrow$ Pas de boue / Un fromage
  • Stratégie $\rightarrow$ Exploration aléatoire

Les objectifs du projet

Session 2


  • Configuration $\rightarrow$ Pas de boue / Un fromage
  • Stratégie $\rightarrow$ DFS / BFS

Les objectifs du projet

Session 3


  • Configuration $\rightarrow$ Boue / Un fromage
  • Stratégie $\rightarrow$ Algorithme de Dijkstra

Les objectifs du projet

Session 4


  • Configuration $\rightarrow$ Boue / $N$ fromages
  • Stratégie $\rightarrow$ Résolution TSP (exhaustive)

Les objectifs du projet

Session 5


  • Configuration $\rightarrow$ Boue / $N$ fromages
  • Stratégie $\rightarrow$ Approximation TSP (heuristique)

Les objectifs du projet

Session 6


  • Configuration $\rightarrow$ Boue / $N$ fromages / Adversaire
  • Stratégie $\rightarrow$ À votre choix !

Les objectifs du projet

Le tournoi PyRat


Organisation & évaluation

Classes inversées

Organisation & évaluation

Préparer une session

Organisation & évaluation

Évaluation

Quoi ?

  • Travail régulier $\rightarrow$ Quiz
  • Étapes du projet $\rightarrow$ Livrables
  • Examen final $\rightarrow$ Présentation orale

Quand ?

Comment écrire un programme PyRat

Tour d’horizon de l’espace de travail par défaut

Les deux principaux répertoires

  • Games $\rightarrow$ Notebooks qui créent la situation d’apprentissage
  • Players $\rightarrow$ Modules Python qui décrivent ce qu’un joueur peut faire

Exemple d’un jeu

# Customize the game elements
CONFIG = {"maze_width": 10, "maze_height": 10, "nb_cheese": 1}

# Instantiate a game with specified arguments
game = Game(**CONFIG)

# Instantiate a player and add it to the game
player = Random1()
game.add_player(player)

# Start the game
stats = game.start()

Comment écrire un programme PyRat

Un joueur est décrit dans une classe Python

Définition d’une classe en Python

class ExamplePlayer (Player):

    """
        This is an example player, meant to illustrate how to create a player.
        Here, it is named "ExamplePlayer" you can customize this.
        We will see in the next slides how to specify a few things.
    """

Utilisation

# Instantiate a variable of type ExamplePlayer
p = ExamplePlayer(name="My example player")

Comment écrire un programme PyRat

Spécifier ce qui est fait à l’instanciation

class ExamplePlayer (Player):

    ...

    def __init__ (self, *args, **kwargs):

        """
            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)

        # Here, you can initialize attributes, e.g.,
        self.preprocessing_results = None

Comment écrire un programme PyRat

Rappel – Les phases du jeu

Comment écrire un programme PyRat

La méthode preprocessing

class ExamplePlayer (Player):

    ...

    def preprocessing (self, maze, game_state):
        
        """
            This method is called once at the beginning of the game.
            It is optional to define it.
            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.
        """
        
        # This is where you describe what to do at the beginning of the game
        # To make these results accessible to the turns, store them as class attributes, e.g.
        self.preprocessing_results = some_computation(maze, game_state)

Comment écrire un programme PyRat

La méthode turn

class ExamplePlayer (Player):

    ...

    def turn (self, maze, game_state):

        """
            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.
            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.
        """

        # This is where you describe what to do at each turn of the game
        # Don't forget to return an action, e.g.,
        return Action.NOTHING

Comment écrire un programme PyRat

La méthode postprocessing

class ExamplePlayer (Player):

    ...

    def postprocessing (self, maze, game_state, stats):

        """
            This method is called once at the end of the game.
            It is optional to define it.
            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.
        """

        # This is where you write the code that will be executed once the game is over
        # Typically, this can be organized for cleaning temporary files, etc.

Récapitulatif de la session

Éléments principaux à retenir

  • Le projet est la principale situation d’évaluation de ce semestre

  • La théorie des graphes comme cadre mathématique central

  • Mettre en application ce que vous voyez en environnement, algorithmique et programmation

  • Objectifs de difficulté croissante $\rightarrow$ Essayez de suivre !

  • Classes inversées $\rightarrow$ Vous devez travailler entre les sessions !

Récapitulatif de la session

Et après ?

Activité pratique (~2h30)

Mettre en place tout pour le projet

  • Rejoindre un groupe (3 étudiants de niveau similaire)
  • Installer PyRat
  • Configurer vos outils pour travailler en collaboration
  • Découvrir PyRat
  • Écrire vos premiers programmes PyRat

Après la session

  • Compléter l’activité pratique
  • Vérifier la section “Avant la classe” de la prochaine session