diff --git a/README.md b/README.md index 14d1fd6..9c5656f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Python Snake +# Pytron This program is a simple python game, made for implementing your own AIs. @@ -12,7 +12,7 @@ This program is a simple python game, made for implementing your own AIs. The first step is to clone the repository: ``` sh -git clone https://gitea.tforgione.fr/tforgione/python-snake +git clone https://gitea.tforgione.fr/tforgione/pytron ``` Then, ensure you have `python3` and `pygame` installed. You can test you have everything by executing the following command: @@ -40,16 +40,16 @@ There are two runnable scripts in the repository, which are mostly here to be ex ## How to create your own AI -You need to write a class that derives from `snake.player.Decision`. You have to define a constructor, so you can instanciate it, and implement the method `action` which takes as parameter the map of the game, and returns the direction you want to take. +You need to write a class that derives from `snake.player.Player`. You have to define a constructor, so you can instanciate it, and implement the method `action` which takes as parameter the map of the game, and returns the direction you want to take. -For example, you can create a file `mydecision.py` at the root of this repository containing the following: +For example, you can create a file `myplayer.py` at the root of this repository containing the following: ``` python -from snake.player import Decision, Direction +from snake.player import Player, Direction -class MyDecision(Decision): +class MyPlayer(Player): def __init__(self): - super(MyDecision, self).__init__() + super(MyPlayer, self).__init__() def action(self, game_map): # Do stuff @@ -66,11 +66,9 @@ with contextlib.redirect_stdout(None): import pygame from snake.map import Map -from snake.game import Game +from snake.game import Game, PositionPlayer from snake.window import Window -from snake.player import Player, Direction, ConstantDecision, KeyboardDecision - -from other import MyDecision +from snake.player import Player, Direction, ConstantPlayer, KeyboardPlayer def main(): pygame.init() @@ -79,8 +77,8 @@ def main(): height = 40 game = Game(width, height, [ - Player(0, 0, (255, 0, 0), KeyboardDecision(Direction.RIGHT)), - Player(width - 1, height - 1, (0, 255, 0), MyDecision()), + PositionPlayer(1, KeyboardPlayer(Direction.RIGHT), [0, 0]), + PositionPlayer(2, ConstantPlayer(Direction.LEFT), [width - 1, height - 1]), ]) window = Window(game, 20) diff --git a/play.py b/play.py index 22352c8..ee0f2d0 100755 --- a/play.py +++ b/play.py @@ -4,10 +4,10 @@ import contextlib with contextlib.redirect_stdout(None): import pygame -from snake.map import Map -from snake.game import Game, PositionPlayer -from snake.window import Window -from snake.player import Player, Direction, ConstantPlayer, KeyboardPlayer +from tron.map import Map +from tron.game import Game, PositionPlayer +from tron.window import Window +from tron.player import Player, Direction, ConstantPlayer, KeyboardPlayer def main(): pygame.init() diff --git a/snake/game.py b/tron/game.py similarity index 99% rename from snake/game.py rename to tron/game.py index 9b4f990..e64f5f0 100644 --- a/snake/game.py +++ b/tron/game.py @@ -5,7 +5,7 @@ This module contains everything related to the game. from time import sleep from enum import Enum -from snake.map import Map +from tron.map import Map class Case(Enum): EMPTY = 0 @@ -61,7 +61,7 @@ class Game: """ Returns a new game from its width, height, and number of players. - Width and height are the number of blocs available in the snake map. + Width and height are the number of blocs available in the tron map. """ self.width = width self.height = height diff --git a/snake/map.py b/tron/map.py similarity index 100% rename from snake/map.py rename to tron/map.py diff --git a/snake/player.py b/tron/player.py similarity index 91% rename from snake/player.py rename to tron/player.py index d68a0b3..9b1ea09 100644 --- a/snake/player.py +++ b/tron/player.py @@ -7,7 +7,7 @@ from enum import Enum class Direction(Enum): """ - This enum represents the different directions a snake can go to. + This enum represents the different directions a tron can go to. """ UP = 1 RIGHT = 2 @@ -56,7 +56,7 @@ class KeyboardPlayer(Player): """" This is the key board interaction. - It uses Z, Q, S and D keys to move the snake. + It uses Z, Q, S and D keys to move the tron. """ def __init__(self, initial_direction): """ @@ -67,7 +67,7 @@ class KeyboardPlayer(Player): def manage_event(self, event): """ - Changes the direction of the snake depending on the keyboard inputs. + Changes the direction of the tron depending on the keyboard inputs. """ import pygame if event.type == pygame.KEYDOWN: @@ -82,7 +82,7 @@ class KeyboardPlayer(Player): def action(self, game): """ - Returns the direction of the snake. + Returns the direction of the tron. """ return self.direction diff --git a/snake/window.py b/tron/window.py similarity index 91% rename from snake/window.py rename to tron/window.py index ccac73d..ec585d0 100644 --- a/snake/window.py +++ b/tron/window.py @@ -1,5 +1,5 @@ """ -This module contains the classes that helps us watch a game of snake. +This module contains the classes that helps us watch a game of tron. """ import pygame @@ -12,7 +12,7 @@ class Window: """ Creates a new window from a game - Factor is the size of a square of the snake. + Factor is the size of a square of the tron. """ self.factor = factor