![Graphical output example](./images/headban.png)
# SantorinAI
AI Player tester for the Santorini game
## How to use
### 1. Install
With pip:
```bash
pip install --upgrade santorinai
```
You can also clone the repository and install it manually:
```bash
git clone https://github.com/Tomansion/SantorinAI.git
cd SantorinAI
pip install -r requirements.txt
```
### 2. Create a player
Create an override of the `Player` class in the `santorinai.player.py` file.
```python
from santorinai.player import Player
class MyPlayer(Player):
"""
My player description
"""
def name(self):
return "My player name"
# Placement of the pawns
def place_pawn(self, board, pawn):
my_pawn_number = pawn.number # Between 1 and 6 depending on the game mode
my_player_number = pawn.player_number # Between 1 and 3 depending on the game mode
# Do some magic here to choose a position
my_choice = (2, 3) # A position on the 5x5 board
return my_choice
# Movement and building
def play_move(self, board, pawn):
my_pawn_pos = pawn.pos
board_array = board.board # A 5x5 array of integers representing the board
# 0: empty
# 1: tower level 1
# 2: tower level 2
# 3: tower level 3
# 4: terminated tower
pawns = board.pawns # The other pawns on the board
# Do some magic here to choose a position
my_move_position = ( # Moving top right
my_pawn_pos[0] + 1,
my_pawn_pos[1] + 1
)
my_build_position = ( # Building right (relative to the new position)
my_move_position[0] + 1,
my_move_position[1] + 0
)
return my_move_position, my_build_position
```
Check our random players example in [our player examples folder](./santorinai/player_examples/) to help you create your own.
### 3. Test your player
```python
from santorinai.tester import Tester
from santorinai.player_examples.random_player import RandomPlayer
from my_player import MyPlayer
# Init the tester
tester = Tester()
tester.verbose_level = 2 # 0: no output, 1: Each game results, 2: Each move summary
tester.delay_between_moves = 0.1 # Delay between each move in seconds
tester.display_board = True # Display a graphical view of the board in a window
# Init the players
my_player = MyPlayer()
random_payer = RandomPlayer()
# Play 100 games
tester.play_1v1(my_player, random_payer, nb_games=100)
```
Output example:
```
Results:
Player Randy Random won 10 times
Player My player won 70 times
```
Graphical output example:
![Graphical output example](./images/board_image.png)
## Board utilities
We provide some utilities to help you manipulate the board.
```python
# Game informations
board.nb_players # Number of players in the game (2 or 3)
board.nb_pawns # Number of pawns (4 or 6) depending on the game mode
board.pawn_turn # Pawn that is currently playing
board.turn_number # Number of turn played since the beginning of the game
# Pawns
board_pawns = board.pawns # The other pawns on the board
pawn = board_pawns[0] # The first pawn on the board
pawn.pos # The position a pawn on the board (x, y), or (None, None) if it is not placed yet
pawn.number # The number of the pawn on the board (between 1 and 6) depending on the game mode
pawn.player_number # The number of the player owning the pawn (between 1 and 3) depending on the game mode
playing_pawn = board.get_playing_pawn() # The pawn that is currently playing
# Board
board_array = board.board # A 5x5 array of integers representing the board
# 0: empty
# 1: tower level 1
# 2: tower level 2
# 3: tower level 3
# 4: terminated tower
# Movements
available_move_positions = board.get_possible_movement_positions(pawn)
available_build_positions = board.get_possible_building_positions(pawn)
# Board control
board.place_pawn(pos) # Place the current playing pawn on the board
board.play_move(move_position, build_position) # Play a move (move and build) with the current playing pawn
# Other
board.is_position_valid(position)
board.is_move_possible(start_pos, end_pos)
board.is_position_within_board(pos)
board.is_position_adjacent(pos1, pos2)
board.is_pawn_on_position(pos)
board.is_build_possible(builder_pos, build_pos)
board.copy() # Create a copy of the board, useful to test moves
print(board) # Print the board
# Display
from santorinai.board_displayer.board_displayer import init_window, update_board
window = init_window([player1.name(), player2.name()])
update_board(window, board)
```
## Credits
Creator of Santorini: [Roxley Games](https://roxley.com/)
Board 2D Gui library: [PySimpleGUI](https://www.pysimplegui.org/en/latest/)
Raw data
{
"_id": null,
"home_page": "https://github.com/tomansion/santorinai",
"name": "SantorinAI",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "santorini,ai,boardgame",
"author": "Tom Mansion",
"author_email": "tomansion@yahoo.fr",
"download_url": "https://files.pythonhosted.org/packages/01/bb/d5bfc30c0ae25c98a2eaef31fae2fc915b3d1ef09a2463117ed424356220/SantorinAI-1.3.3.tar.gz",
"platform": null,
"description": "![Graphical output example](./images/headban.png)\n\n# SantorinAI\nAI Player tester for the Santorini game\n\n## How to use\n### 1. Install\n\nWith pip:\n```bash\npip install --upgrade santorinai\n```\n\nYou can also clone the repository and install it manually:\n```bash\ngit clone https://github.com/Tomansion/SantorinAI.git\ncd SantorinAI\npip install -r requirements.txt\n```\n\n### 2. Create a player\n\nCreate an override of the `Player` class in the `santorinai.player.py` file.\n\n```python\nfrom santorinai.player import Player\n\nclass MyPlayer(Player):\n \"\"\"\n My player description\n \"\"\"\n\n def name(self):\n return \"My player name\"\n\n # Placement of the pawns\n def place_pawn(self, board, pawn):\n my_pawn_number = pawn.number # Between 1 and 6 depending on the game mode\n my_player_number = pawn.player_number # Between 1 and 3 depending on the game mode\n\n # Do some magic here to choose a position\n my_choice = (2, 3) # A position on the 5x5 board\n\n return my_choice\n\n # Movement and building\n def play_move(self, board, pawn):\n my_pawn_pos = pawn.pos\n\n board_array = board.board # A 5x5 array of integers representing the board\n # 0: empty\n # 1: tower level 1\n # 2: tower level 2\n # 3: tower level 3\n # 4: terminated tower\n\n pawns = board.pawns # The other pawns on the board\n\n # Do some magic here to choose a position\n my_move_position = ( # Moving top right\n my_pawn_pos[0] + 1, \n my_pawn_pos[1] + 1\n ) \n\n my_build_position = ( # Building right (relative to the new position)\n my_move_position[0] + 1, \n my_move_position[1] + 0\n ) \n\n return my_move_position, my_build_position\n```\n\nCheck our random players example in [our player examples folder](./santorinai/player_examples/) to help you create your own.\n\n### 3. Test your player\n\n```python\nfrom santorinai.tester import Tester\nfrom santorinai.player_examples.random_player import RandomPlayer\nfrom my_player import MyPlayer\n\n# Init the tester\ntester = Tester()\ntester.verbose_level = 2 # 0: no output, 1: Each game results, 2: Each move summary\ntester.delay_between_moves = 0.1 # Delay between each move in seconds\ntester.display_board = True # Display a graphical view of the board in a window\n\n# Init the players\nmy_player = MyPlayer()\nrandom_payer = RandomPlayer()\n\n# Play 100 games\ntester.play_1v1(my_player, random_payer, nb_games=100)\n```\nOutput example:\n```\nResults:\nPlayer Randy Random won 10 times\nPlayer My player won 70 times\n```\nGraphical output example:\n![Graphical output example](./images/board_image.png)\n\n## Board utilities\nWe provide some utilities to help you manipulate the board.\n\n```python\n# Game informations\nboard.nb_players # Number of players in the game (2 or 3)\nboard.nb_pawns # Number of pawns (4 or 6) depending on the game mode\nboard.pawn_turn # Pawn that is currently playing\nboard.turn_number # Number of turn played since the beginning of the game\n\n# Pawns\nboard_pawns = board.pawns # The other pawns on the board\npawn = board_pawns[0] # The first pawn on the board\npawn.pos # The position a pawn on the board (x, y), or (None, None) if it is not placed yet\npawn.number # The number of the pawn on the board (between 1 and 6) depending on the game mode\npawn.player_number # The number of the player owning the pawn (between 1 and 3) depending on the game mode\nplaying_pawn = board.get_playing_pawn() # The pawn that is currently playing\n\n\n# Board\nboard_array = board.board # A 5x5 array of integers representing the board\n# 0: empty\n# 1: tower level 1\n# 2: tower level 2\n# 3: tower level 3\n# 4: terminated tower\n\n# Movements\navailable_move_positions = board.get_possible_movement_positions(pawn)\navailable_build_positions = board.get_possible_building_positions(pawn)\n\n# Board control\nboard.place_pawn(pos) # Place the current playing pawn on the board\nboard.play_move(move_position, build_position) # Play a move (move and build) with the current playing pawn\n\n# Other\nboard.is_position_valid(position)\nboard.is_move_possible(start_pos, end_pos)\nboard.is_position_within_board(pos)\nboard.is_position_adjacent(pos1, pos2)\nboard.is_pawn_on_position(pos)\nboard.is_build_possible(builder_pos, build_pos)\nboard.copy() # Create a copy of the board, useful to test moves\nprint(board) # Print the board\n\n# Display\nfrom santorinai.board_displayer.board_displayer import init_window, update_board\nwindow = init_window([player1.name(), player2.name()])\nupdate_board(window, board)\n```\n\n## Credits\n\nCreator of Santorini: [Roxley Games](https://roxley.com/)\n\nBoard 2D Gui library: [PySimpleGUI](https://www.pysimplegui.org/en/latest/)\n",
"bugtrack_url": null,
"license": "",
"summary": "A Python library for the Santorini board game",
"version": "1.3.3",
"project_urls": {
"Homepage": "https://github.com/tomansion/santorinai"
},
"split_keywords": [
"santorini",
"ai",
"boardgame"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2c654611f87d24613e7df3c524429ffe5a4ce2b6485723b9afc5cf042f4729a9",
"md5": "a83461baa03fb5dbf4e24598c30fa5f4",
"sha256": "4382c51e79ab9fc912a3332d1725d5dbfa8d92ea0573ef7ff7b841e897acf845"
},
"downloads": -1,
"filename": "SantorinAI-1.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a83461baa03fb5dbf4e24598c30fa5f4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 21741,
"upload_time": "2023-07-02T19:51:34",
"upload_time_iso_8601": "2023-07-02T19:51:34.202482Z",
"url": "https://files.pythonhosted.org/packages/2c/65/4611f87d24613e7df3c524429ffe5a4ce2b6485723b9afc5cf042f4729a9/SantorinAI-1.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "01bbd5bfc30c0ae25c98a2eaef31fae2fc915b3d1ef09a2463117ed424356220",
"md5": "9040abad7ded24bdd0ec8f11dfefc47e",
"sha256": "c30c7c88014acaf056f9091d289885b09fa8796e3e61c2b5ef1b1a4c3c793dea"
},
"downloads": -1,
"filename": "SantorinAI-1.3.3.tar.gz",
"has_sig": false,
"md5_digest": "9040abad7ded24bdd0ec8f11dfefc47e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 18270,
"upload_time": "2023-07-02T19:51:35",
"upload_time_iso_8601": "2023-07-02T19:51:35.352124Z",
"url": "https://files.pythonhosted.org/packages/01/bb/d5bfc30c0ae25c98a2eaef31fae2fc915b3d1ef09a2463117ed424356220/SantorinAI-1.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-02 19:51:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tomansion",
"github_project": "santorinai",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pysimplegui",
"specs": [
[
"==",
"4.60.0"
]
]
}
],
"lcname": "santorinai"
}