Cold-FR / ConnectFour

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Puissance 4

Le jeu du Puissance 4 en Python/PyGame (pour la SAE 1 & 2)

Préparer l'environnement Python

Vérifiez que PyGame est bien installé sur le système utilisé. Le plus simple est de lancer la commande d'installation :

pip install pygame

Si la commande est refusée (vous n'avez pas les droits administrateur par exemple), il faudra peut-être créer son environnement de développement.

Il sera peut-être utile de mettre à jour PyGame :

pip install pygame --upgrade

Commencez par vérifier que PyGame est installé ou non avec la commande :

pip freeze | grep pygame

Sous Windows :

pip freeze | findstr pygame

Si PyGame n'est pas installé et que vous n'êtes pas administrateur de la machine, créez votre environnement de développement avec la commande :

python -m venv venv

Cette commande crée un répertoire venv/ contenant une "copie" de l'environnement Python.

Placez-vous dans l'environnement de développement venv/ en tapant la commande :

source venv/bin/activate

Sous Windows

venv\Scripts\activate

Dans cet environnement, vous pouvez alors installer PyGame avec la commande :

pip install pygame

Pour quitter l'environnement venv/, il suffit de taper la commande :

deactivate

Remarque

Pour mettre à jour le package PyGame, il faut taper la commande :

pip install pygame --upgrade

Documentation

Pour mettre en place les outils de documentation Sphinx, suivre les étapes suivantes.

Installer Sphinx :

pip install sphinx

Vérifier que l'installation est correcte :

sphinx-build --version

Configurer la documentation

Pour configurer la documentation, le plus simple est d'exécuter la commande suivante dans le répertoire de base.

sphinx-quickstart

Cette commande crée les fichiers suivants :

  • Makefile : Permet de générer la documentation
  • make.bat: Pour Windows, remplace la commande make de linux.

La commande crée également les répertoires suivants :

  • build/ : répertoire qui contiendra la documentation générée par Sphinx (à exclure du dépôt Git).
  • source: répertoire qui contient les fichiers de configuration conf.py et index.rst.

Le fichier conf.py

Dans ce fichier, on retrouve les paramètres entrés lors de la configuration de la documentation.

On peut notamment ajouter dans ce fichier des options pour "enjoliver" la documentation.

Un thème souvent utilisé est le thème sphinx-rtd-theme. Pour l'installer, il faut lancer la commande :

pip install sphinx-rtd-theme

Enfin, dans le fichier source\conf.py, on ajoute la ligne :

html_theme = 'sphinx_rtd_theme'
Les options

Une option utile est (toujours dans le fichier source/conf.py) :

extensions = [
    'sphinx.ext.autodoc',
]

Cette option permet d'inclure la documentation au format docstring utilisé dans les fichiers python.

Par contre, dans la "docstring", il faut séparer la description de la méthode de celle des paramètres par une ligne vide :

    """
    Retourne la colonne de la coordonnée donnée en paramètre

    :param coord: Coordonnée
    :return: Colonne de la coordonnée
    :raise TypeError: s'il ne s'agit pas d'une coordonnée

Ne pas oublier d'ajouter les ':' derrière le type des exceptions, sinon l'option :raise n'est pas reconnue.

Si vous voulez inclure le type des paramètres dans la documentation, il faut installer le module sphinx-autodoc-typehints :

pip install sphinx-autodoc-typehints

Sans oublier de l'ajouter dans les extensions (fichier conf.py) :

extensions = [
    ...,
    'sphinx_autodoc_typehints',
]

Remarque : Pour le typage en Python, on peut améliorer le typage grâce au module typing :

from typing import Union

def format_unit(value: Union[float, int], unit: str) -> str:
   ...
Emplacement des modules

Si les modules ne se trouvent pas dans le même répertoire que le fichier conf.py, il faut préciser le chemin en ajoutant ces lignes dans le fichier conf.py :

import os
import sys
sys.path.insert(0, os.path.abspath('..')) # Mettre le bon chemin...

Le fichier index.rst

Dans ce fichier, on ajoute les documents que l'on veut voir apparaître dans la documentation.

Ceci se fait dans le paragraphe `toctree``:

.. toctree::
   :maxdepth: 2
   :caption: Contents:
   
   ./Fichier01.rst
   ./Fichier02.rst

Cas des classes

Les fichiers Fichier0x.rst commencent par une présentation de leur contenu, puis les classes à documenter, les éventuelles notes et les fonctions associées :

view.Canvas
===========

    Classe permettant de créer et gérer une fenêtre.

    Exemple d'utilisation :

    .. code-block:: python

        from view.Canvas import Canvas

        # Création de la fenêtre
        cv = Canvas( (640, 480) )
        # Afficher/mettre à jour la fenêtre
        cv.display()

.. autoclass:: view.Canvas.Canvas
   :members:

.. NOTE::

    Fonction attachée à la fenêtre

.. autofunction:: view.Canvas.waitClick
.. autofunction:: view.Canvas.pause

Cas de fonctions

Si les fichiers ne contiennent que des fonctions (à la place de classes, comme c'est le cas ici), il faut préciser toutes les fonctions à documenter.

Par exemple, supposons que l'on veut écrire la documentation des fonctions contenues dans le fichier Model/Pion.py :

  • On crée un fichier de documentation associé (par exemple : pion.rst). Le fait de créer un fichier spécifique permet d'avoir une entrée propre à ce module dans le menu de la documentation.
  • Le contenu du fichier pion.rst pourra ressembler à ceci :
Model.Pion
==========

    Fonctions permettant de gérer les pions du jeu.

    Exemple d'utilisation :

    .. code-block:: python

        from Model.Constantes import *
        from Model.Pion import construirePion

        # Création d'un pion
        pion = construirePion(const.ROUGE)

.. autofunction:: Model.Pion.construirePion
.. autofunction:: Model.Pion.getCouleurPion
.. autofunction:: Model.Pion.setCouleurPion
.. autofunction:: Model.Pion.getIdPion
.. autofunction:: Model.Pion.setIdPion

Générer la documentation

Sphinx permet de générer plusieurs formats de documentation (html, json, epub, latex, text, man, xml).

Pour le format HTML, il suffit de taper :

make html

Sous Windows :

make.bat html

Documentation classique sur Git/GitLab

Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? Use the template at the bottom!

Add your files

cd existing_repo
git remote add origin https://iut-info.univ-reims.fr/gitlab/vautro01/pydemineur.git
git branch -M main
git push -uf origin main

Integrate with your tools

Collaborate with your team

Test and Deploy

Use the built-in continuous integration in GitLab.


Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to makeareadme.com for this template.

Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

Name

Choose a self-explaining name for your project.

Description

Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

Badges

On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

Visuals

Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

Installation

Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

Usage

Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

Support

Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

Roadmap

If you have ideas for releases in the future, it is a good idea to list them in the README.

Contributing

State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

Authors and acknowledgment

Show your appreciation to those who have contributed to the project.

License

For open source projects, say how it is licensed.

Project status

If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

About


Languages

Language:Python 100.0%