Players module
Provide the classes handle human players.
This module allows the handle CLI arguments and options.
The module contains the following classes:
- ConsolePlayer(Player)
- A class that represents human players.
The module contains the following functions:
- grid_to_index(grid: str) -> int:
- Return infex of the next move.
ConsolePlayer
Bases: Player
A class that represents human players. Extend abstract class for the creation of players.
Methods:
Name | Description |
---|---|
get_move |
GameState) -> Move | None: Return the current player's move based on the human player choice. |
Source code in src\frontend\console\players.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
get_move(game_state)
Return the current player's move based on the human player choice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
game_state |
GameState
|
current GameState, consisting of a current Grid (9 elemets that that can be X, O or spaces) and a starting Mark (default X). |
required |
Returns:
Type | Description |
---|---|
Move | None
|
Move | None: return a move class or none. |
Source code in src\frontend\console\players.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
grid_to_index(grid)
Return infex of the next move. Input must be in format A1 or 1A. Letters can be A, B or C, and number 1, 2, or 3.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grid |
str
|
String with the position option from human input |
required |
Raises:
Type | Description |
---|---|
ValueError
|
Exception when a value of the index is outside bounds. |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
index of move |
Source code in src\frontend\console\players.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|