44 lines
1.1 KiB
Markdown
44 lines
1.1 KiB
Markdown
# The `Player` class
|
|
|
|
The only thing the `player` module contains is the `Player` class.
|
|
|
|
Your AI will basically be a class that will extend the `Player` class.
|
|
|
|
Since your AI is not interactive, the only method you have to implement is the
|
|
`action` method. This method takes as parameters `self`, of course, and also:
|
|
- `map`, which is the current map of the game
|
|
- `id` which is the id of your player (because the map refers to player 1 and
|
|
2 but you don't know if you're player one or two)
|
|
|
|
You can refer to the [game page of the wiki](/wiki/Game) to have more
|
|
information about this class.
|
|
|
|
This function will return a `Direction`. It is a python enum that you can use
|
|
directly, like in
|
|
|
|
```python
|
|
return Direction.UP
|
|
```
|
|
|
|
or with an integer, like in
|
|
|
|
```python
|
|
i = 2
|
|
return Direction(i) # returns Direction.RIGHT
|
|
```
|
|
|
|
Your class may then look like this:
|
|
|
|
``` python
|
|
class MyMonsterAI(Player):
|
|
def __init__(self):
|
|
super(MyMonsterAI, self).__init__()
|
|
|
|
def action(self, map, id):
|
|
# Analyse the map
|
|
# Do many computations
|
|
# Make a sacrifice to the gods of tron
|
|
# Return a direction
|
|
return Direction.UP
|
|
```
|