# Gameboard
This library creates a 3-dimensional grid object with 2 fixed-length dimensions (x, y) and a third unfixed-length dimension (z).
Example use cases include multi-agent simulations where multiple agents can be placed on a 2D grid and be in the same cell, or board games where the board is a 2D grid and pieces can be stacked on top of or adjacent to each other.
The primary purpose of this project is to be able to access coordinates just as on a coordinate plane.
e.g. with the variable `board` of type `grid`, `board[0, 0]` will return the bottom-left corner of the grid.
## Install
Run:
```bash
pip install gameboard
```
## Example Usage
```python
from gameboard.grid import grid
board = grid(grid_size = 3, fill = True)
print(board)
# [[[1], [2], [3]],
#
# [[4], [5], [6]],
#
# [[7], [8], [9]]]
print(board[2, 1])
# [6]
board[2, 1].append('a')
print(board)
# [[[1], [2], [3]],
#
# [[4], [5], [6, 'a']],
#
# [[7], [8], [9]]]
board[2, 2].remove(3)
print(board)
# [[[1], [2], []],
#
# [[4], [5], [6, 'a']],
#
# [[7], [8], [9]]]
print(2 in board[1, 2])
# True
print(2 in board[2, 1])
# False
position = [1, 0]
print(board[position])
# [8]
data = [2, 3, 4]
board[position].append(3)
board[position].append(data)
# [[[1], [2], []],
#
# [[4], [5], [6, 'a']],
#
# [[7], [8, 3, [2, 3, 4]], [9]]]
import numpy as np
pos = np.array([0, 0])
board[pos] = ['0']
print(board)
# [[[1], [2], []],
#
# [[4], [5], [6, 'a']],
#
# [['0'], [8, 3, [2, 3, 4]], [9]]]
```
The `fill` parameter is set to `True` for the example, where all squares are numbered.
If you set the `fill` parameter to `False` ***or*** do not specify (default is `False`), all z-axis arrays will be empty.
## Warning
This project does not currently work with negative indices for the y-coordinate when accessing the grid.
This project is in an early development stage and may not be suitable for all use cases. For ease of use, the `__iter__` dunder method has been implemented for both the y-axis and x-axis arrays, and the `append`/`remove` methods and `__iter__` dunder method work for adding, removing and iterating through elements in the z-dimension arrays as the z-dimension arrays are simply Python lists.
Raw data
{
"_id": null,
"home_page": "https://github.com/Sprocketer/gameboard",
"name": "gameboard",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "pypi, python",
"author": "Alex",
"author_email": "sprocketerdev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f5/12/8c623cb3073cbcdcb662158f6b834c9417f4e1984b20ad7da95800d66bd9/gameboard-1.0.9.tar.gz",
"platform": null,
"description": "\n# Gameboard\n\nThis library creates a 3-dimensional grid object with 2 fixed-length dimensions (x, y) and a third unfixed-length dimension (z).\n\nExample use cases include multi-agent simulations where multiple agents can be placed on a 2D grid and be in the same cell, or board games where the board is a 2D grid and pieces can be stacked on top of or adjacent to each other.\n\nThe primary purpose of this project is to be able to access coordinates just as on a coordinate plane.\n\ne.g. with the variable `board` of type `grid`, `board[0, 0]` will return the bottom-left corner of the grid.\n\n## Install\n\nRun:\n\n```bash\npip install gameboard\n```\n\n## Example Usage\n\n```python\nfrom gameboard.grid import grid\n\nboard = grid(grid_size = 3, fill = True)\nprint(board)\n\n# [[[1], [2], [3]],\n#\n# [[4], [5], [6]],\n#\n# [[7], [8], [9]]]\n\nprint(board[2, 1])\n\n# [6]\n\nboard[2, 1].append('a')\nprint(board)\n\n# [[[1], [2], [3]],\n#\n# [[4], [5], [6, 'a']],\n#\n# [[7], [8], [9]]]\n\nboard[2, 2].remove(3)\nprint(board)\n\n# [[[1], [2], []],\n#\n# [[4], [5], [6, 'a']],\n#\n# [[7], [8], [9]]]\n\nprint(2 in board[1, 2])\n\n# True\n\nprint(2 in board[2, 1])\n\n# False\n\nposition = [1, 0]\nprint(board[position])\n\n# [8]\n\ndata = [2, 3, 4]\nboard[position].append(3)\nboard[position].append(data)\n\n# [[[1], [2], []],\n#\n# [[4], [5], [6, 'a']],\n#\n# [[7], [8, 3, [2, 3, 4]], [9]]]\n\nimport numpy as np\npos = np.array([0, 0])\nboard[pos] = ['0']\nprint(board)\n\n# [[[1], [2], []],\n#\n# [[4], [5], [6, 'a']],\n#\n# [['0'], [8, 3, [2, 3, 4]], [9]]]\n```\n\nThe `fill` parameter is set to `True` for the example, where all squares are numbered.\nIf you set the `fill` parameter to `False` ***or*** do not specify (default is `False`), all z-axis arrays will be empty.\n\n## Warning\n\nThis project does not currently work with negative indices for the y-coordinate when accessing the grid.\n\nThis project is in an early development stage and may not be suitable for all use cases. For ease of use, the `__iter__` dunder method has been implemented for both the y-axis and x-axis arrays, and the `append`/`remove` methods and `__iter__` dunder method work for adding, removing and iterating through elements in the z-dimension arrays as the z-dimension arrays are simply Python lists.\n",
"bugtrack_url": null,
"license": null,
"summary": "A 3D grid creation library for simulation and games.",
"version": "1.0.9",
"project_urls": {
"Homepage": "https://github.com/Sprocketer/gameboard"
},
"split_keywords": [
"pypi",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9aa598fc7421706dd080268e9e5ac9c6bcab9a56c26fb197a68e90cf141ecb31",
"md5": "40c39a034cc72e0d21737dacd8121d7c",
"sha256": "956d29c43bc56a438b15e7d79665bee793ab5a7b08ccd3145174aa0069280450"
},
"downloads": -1,
"filename": "gameboard-1.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "40c39a034cc72e0d21737dacd8121d7c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3073,
"upload_time": "2024-08-14T14:23:23",
"upload_time_iso_8601": "2024-08-14T14:23:23.437468Z",
"url": "https://files.pythonhosted.org/packages/9a/a5/98fc7421706dd080268e9e5ac9c6bcab9a56c26fb197a68e90cf141ecb31/gameboard-1.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f5128c623cb3073cbcdcb662158f6b834c9417f4e1984b20ad7da95800d66bd9",
"md5": "7d3d21ad282e65ba30cf5a0babab4544",
"sha256": "7fdaec0d197dc5e5c163d34851656856d4ecfaa3d7beb8073f00eb0fb22481c0"
},
"downloads": -1,
"filename": "gameboard-1.0.9.tar.gz",
"has_sig": false,
"md5_digest": "7d3d21ad282e65ba30cf5a0babab4544",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3079,
"upload_time": "2024-08-14T14:23:24",
"upload_time_iso_8601": "2024-08-14T14:23:24.672003Z",
"url": "https://files.pythonhosted.org/packages/f5/12/8c623cb3073cbcdcb662158f6b834c9417f4e1984b20ad7da95800d66bd9/gameboard-1.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-14 14:23:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Sprocketer",
"github_project": "gameboard",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "gameboard"
}