sample_game

Source Code

 1#####################################################################################################################################################
 2######################################################################## INFO #######################################################################
 3#####################################################################################################################################################
 4
 5# This file is provided as an example by the PyRat library.
 6# It describes a script that creates a PyRat game.
 7# Please import necessary elements using the following syntax:
 8#     from pyrat import <element_name>
 9#     from players.<player_name> import <player_name>
10
11"""
12This file is a script that creates a PyRat game.
13In this script, we create a match between two players.
14We also configure the game with specific parameters such as the maze size, cheese count, and wall percentage.
15"""
16
17#####################################################################################################################################################
18###################################################################### IMPORTS ######################################################################
19#####################################################################################################################################################
20
21# External imports
22import pprint
23
24# PyRat imports
25from pyrat import Game, PlayerSkin
26from players.Random2 import Random2
27from players.Random3 import Random3
28
29#####################################################################################################################################################
30####################################################################### SCRIPT ######################################################################
31#####################################################################################################################################################
32
33if __name__ == "__main__":
34
35    # First, let's customize the game elements
36    # This is done by setting the arguments of the Game class when instantiating it
37    # In Python, we can also create a dictionary `d` with these arguments and pass it to the Game class using `game = Game(**d)`
38    # This can be convenient for code organization and readability
39    game_config = {"mud_percentage": 20.0,
40                   "cell_percentage": 80.0,
41                   "wall_percentage": 60.0,
42                   "maze_width": 13,
43                   "maze_height": 10,
44                   "nb_cheese": 5}
45
46    # Instantiate a game with specified arguments
47    game = Game(**game_config)
48
49    # Instantiate players with different skins, and add them to the game in distinct teams
50    player_1 = Random2(skin=PlayerSkin.RAT)
51    player_2 = Random3(skin=PlayerSkin.PYTHON)
52    game.add_player(player_1, team="Team Ratz")
53    game.add_player(player_2, team="Team Pythonz")
54
55    # Start the game
56    stats = game.start()
57    pprint.pprint(stats)
58
59#####################################################################################################################################################
60#####################################################################################################################################################