Skip to content

Commit

Permalink
Add docs to arena
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Oct 19, 2023
1 parent a2ad9bd commit 1e98785
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@
/src/games/tutorials/nqueens
/src/games/tutorials/coins
/src/games/tutorials/mastermind


.. toctree::
:caption: Arena
:maxdepth: 2
:hidden:

/src/arena/arena
9 changes: 9 additions & 0 deletions docs/src/arena/arena.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. _arena:

#####
Arena
#####

.. warning::

Coming soon.
50 changes: 50 additions & 0 deletions docs/src/players/players.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,53 @@ The player can create its own movement or choose one from the list of possible m
rules = position.get_rules()
possible_movements = rules.possible_movements(position)
movement = possible_movements[...]
-----
Arena
-----

In order to play a game with an autonomous player, an *arena* is required.
An *Arena* is a class that implements the loop of the game, or the context in which the game is played.
For further information, see the :ref:`arena` module.

The easiest arena to use is ``GenericGame`` that implements a single loop over the game and make each player play in its turn.
If you prefer to see step by step the game playing by the player, use ``BroadcastGame``.

.. code-block:: python
from IArena.arena.GenericGame import GenericGame # or BroadcastGame
from IArena.games.Hanoi import HanoiRules, HanoiMovement, HanoiPosition
rules = HanoiRules()
my_player = MyPlayer()
arena = GenericGame(
rules=rules,
players=[my_player]
)
score = arena.play()
Multiplayer games
^^^^^^^^^^^^^^^^^

In games with more than 1 player, you would need another player to play against.
There are several generic players implemented, please check :ref:`random_player`.


.. code-block:: python
from IArena.arena.GenericGame import GenericGame # or BroadcastGame
from IArena.games.Coins import CoinsRules, CoinsMovement, CoinsPosition
from IArena.players.players import RandomPlayer
rules = CoinsRules()
my_player = MyPlayer()
other_player = RandomPlayer()
arena = GenericGame(
rules=rules,
players=[my_player, other_player]
)
score = arena.play()

0 comments on commit 1e98785

Please sign in to comment.