Discover the project and the PyRat software

Project – Session 1

  • The PyRat game
  • The project objectives
  • Organization & evaluation
  • How to write a PyRat program
  • Recap of the session

The PyRat game

What does it look like?

The PyRat game

Elements of the game

The PyRat game

Goal of the game

How to win?

  • Single team game $\rightarrow$ catch all cheese
  • Multi team game $\rightarrow$ catch more cheese than others

How to play?

The PyRat game

Alternate situations

When a timing is missed


Other modes

  • Synchronous $\rightarrow$ Wait for everyone to apply decision
  • Sequential $\rightarrow$ Synchronous + single-process
  • Simulation $\rightarrow$ Sequential + no GUI

The project objectives

Global view

What to do in the project?

  • Program players for a PyRat game
  • Objectives of gradually increasing difficulty

How to do it?

  • Python programming language
  • More details later in the slides

The project objectives

Session 1


  • Configuration $\rightarrow$ No mud / One cheese
  • Strategy $\rightarrow$ Random exploration

The project objectives

Session 2


  • Configuration $\rightarrow$ No mud / One cheese
  • Strategy $\rightarrow$ DFS / BFS

The project objectives

Session 3


  • Configuration $\rightarrow$ Mud / One cheese
  • Strategy $\rightarrow$ Dijkstra's algorithm

The project objectives

Session 4


  • Configuration $\rightarrow$ Mud / $N$ cheese
  • Strategy $\rightarrow$ TSP resolution (exhaustive)

The project objectives

Session 5


  • Configuration $\rightarrow$ Mud / $N$ cheese
  • Strategy $\rightarrow$ TSP approximation (heuristic)

The project objectives

Session 6


  • Configuration $\rightarrow$ Mud / $N$ cheese / Opponent
  • Strategy $\rightarrow$ Your choice!

The project objectives

The PyRat tournament


Organization & evaluation

Flipped classes

Organization & evaluation

Preparing a session

Organization & evaluation

Evaluation

What?

  • Regular work $\rightarrow$ Quizzes
  • Project milestones $\rightarrow$ Deliverables
  • Final exam $\rightarrow$ Oral presentation

When?

How to write a PyRat program

A tour of the default workspace

The two main directories

  • Games $\rightarrow$ Notebooks that create the learning situation
  • Players $\rightarrow$ Python modules that describe what a player can do

Example of a game

# 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()

How to write a PyRat program

A player is described in a Python class

Definition of a class in 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.
    """

Usage

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

How to write a PyRat program

Specifying what is done at instantiation

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

How to write a PyRat program

Recall – The phases of the game

How to write a PyRat program

The preprocessing method

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)

How to write a PyRat program

The turn method

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

How to write a PyRat program

The postprocessing method

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.

Recap of the session

Main elements to remember

  • The project is the main evaluation situation for this semester

  • Graph theory as a central mathematical framework

  • Put in application what you see in environment, algorithmics and programming courses

  • Objectives of gradually increasing difficulty $\rightarrow$ Try to keep up!

  • Flipped classes $\rightarrow$ You have to work between sessions!

Recap of the session

What’s next?

Practical activity (~2h30)

Set up everything for the project

  • Join a group (3 students with similar level)
  • Install PyRat
  • Set up your tools to work collaboratively
  • Discover PyRat
  • Write your first PyRat programs

After the session

  • Complete the practical activity
  • Check next session’s “Before the class” section