Description of the Lab

There are two parts in this Lab:

  • First, we guide you in setting up the PyRat environment, that we will use extensively in the next Episodes;
  • Then, we propose you to play an online game to refresh you Python memories, or to discover the language if you have never practiced.

If you are sufficiently confident in your Python skills (i.e., you know how to write loops, conditional structures, variable assignments, functions…), then you may skip the second part.

Setting up the PyRat environment

Installing the PyRat software

A first step before starting is to install the PyRat software (either locally on your computer or using the provided virtual machine). Please follow the instructions on this page. Once done, start a terminal, navigate to the PyRat directory on the machine where it is installed, and run the following command:

python --rat AIs/

If everything is fine, you should see a maze, in which a rat is moving randomly.

Before anything else, please type the following command in your terminal:

python -h

You will see a big text appear, which lists all possible options you can use with PyRat. Some of them allow you to customize the maze, others can be used to run multiple games, etc.

Now, we ask you to read this page, which describes how the PyRat software works.

Preparing a Google Colab workspace

There are two ways of submitting a program to the PyRat software:

  • You can give it a local file, which is either a Python code, or a Jupyter notebook. This is what you did in the previous section with the following command:
python --rat AIs/
  • The second way of submitting a program to PyRat is to give it the shared link to a Jupyter notebook, stored either on your computer, or on your Google Drive. For instance, the Google Colab PyRat template file can be used to control the rat as follows:
python --rat ""

Note that this link is the shared link you would obtain from the Google Colab file. To obtain it, click on Share (top right corner of the navigator). Then, change sharing method to Anyone with the link, and copy the sharing link.

In this course, we will favor the Google Colab option. There are many reasons for this, among which the two main are:

  • You can share the link to this file with your team member to ease collaboration on files;
  • You can share the link with your teacher on Mattermost, so that they can come and see if everything is right, and help you if you seem to need so.

In order to set up your working environment, we ask you to watch the following video, and follow all instructions given there:

This video was captured during the Covid-19 period, and I forgot to update it before the course started again 🙂 So please note that there is no virtual machine anymore. The rest of this video (Mattermost, Google Colab…) is still valid thouth.

Addendum : It was omitted in the video, but you have to make sure the Google Colab shared link you create is in edition mode. Also, make sure you share the link to your Google Colab directory and not to a single notebook.

Python reminders

In this section, we offer you a few pointers to refresh or initiate your Python skills. If you already feel comfortable with that language, you may just start working on the next Episode.

Note that these are Python exercises, not PyRat ones. We will start developing an AI for the game in next Episode.

Python basics

Normally, before coming to this Lab, you should have read this article, which presents you the Python language, and gives a few elements of its syntax. If you haven’t read it already, please do.

Let’s solve some problems!

In this first part of the Lab, we ask you to solve a few challenges on this website. Just create an account and see how far you can go (but first read the next few paragraphs)!

Typically, a CheckIO problem consists of an objective (e.g., « return the length of a given string »), a function to fill (where you write your solution), and a few tests to pass

Example of a CheckIO problem. The instructions are given in the right column. The left column provides you an editor where to write your code (the area where to do it is highlighted), as well as a Python interpreter. You can click « Run » to test your code, and « Check » to submit your solution.

The only thing we explicitly ask is that you don’t stay blocked. When solving the problems, you should acquire the following two reflexes:

  1. Google the problem! As an example, consider the problem of reversing the order of the letters in a word. Obviously, thousands of people have done that before and there should be an easy way of doing this in Python, but maybe you just don’t know the syntax or the function name that does that. A quick Google search for « python reverse string » should give you the solution;
  2. Ask people on the Mattermost! Sometimes, you cannot find a solution online, or just don’t understand it. In that case, you should go to the Mattermost of the course and ask in the Question & Answers channel so that other students or teachers give you an explanation.

Important! Asking someone or Googling a problem is not cheating! For basic stuff like counting words, iterating over a structure, calling a complex function that does what you want… this is just the way to do! However, when you use a long and complex code you found online, which seems to solve the problem you are considering, you should:

  • Check that you have the right to use it (some codes are subject to proprietary licenses);
  • Understand what it does before using it (and if there are exceptions in its usage for instance);
  • Put a comment in your code indicating where you found it.