ti4-rules-engine 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ti4_rules_engine-0.1.0/.github/workflows/analyze-game.yml +33 -0
- ti4_rules_engine-0.1.0/.github/workflows/publish.yml +50 -0
- ti4_rules_engine-0.1.0/.gitignore +35 -0
- ti4_rules_engine-0.1.0/LICENSE +21 -0
- ti4_rules_engine-0.1.0/PKG-INFO +105 -0
- ti4_rules_engine-0.1.0/README.md +66 -0
- ti4_rules_engine-0.1.0/adapters/__init__.py +16 -0
- ti4_rules_engine-0.1.0/adapters/asyncti4.py +463 -0
- ti4_rules_engine-0.1.0/data/leaders.json +731 -0
- ti4_rules_engine-0.1.0/data/objectives.json +485 -0
- ti4_rules_engine-0.1.0/data/technologies.json +1037 -0
- ti4_rules_engine-0.1.0/data/units/baseUnits.json +354 -0
- ti4_rules_engine-0.1.0/data/units/pok.json +1435 -0
- ti4_rules_engine-0.1.0/docs/contributing.md +94 -0
- ti4_rules_engine-0.1.0/docs/implementation.md +491 -0
- ti4_rules_engine-0.1.0/engine/__init__.py +40 -0
- ti4_rules_engine-0.1.0/engine/combat.py +296 -0
- ti4_rules_engine-0.1.0/engine/history.py +148 -0
- ti4_rules_engine-0.1.0/engine/movement.py +204 -0
- ti4_rules_engine-0.1.0/engine/options.py +434 -0
- ti4_rules_engine-0.1.0/engine/round_engine.py +281 -0
- ti4_rules_engine-0.1.0/engine/scoring.py +371 -0
- ti4_rules_engine-0.1.0/models/__init__.py +46 -0
- ti4_rules_engine-0.1.0/models/card.py +54 -0
- ti4_rules_engine-0.1.0/models/faction.py +63 -0
- ti4_rules_engine-0.1.0/models/map.py +112 -0
- ti4_rules_engine-0.1.0/models/objective.py +249 -0
- ti4_rules_engine-0.1.0/models/planet.py +45 -0
- ti4_rules_engine-0.1.0/models/state.py +248 -0
- ti4_rules_engine-0.1.0/models/technology.py +39 -0
- ti4_rules_engine-0.1.0/models/unit.py +72 -0
- ti4_rules_engine-0.1.0/pyproject.toml +36 -0
- ti4_rules_engine-0.1.0/registry/__init__.py +16 -0
- ti4_rules_engine-0.1.0/registry/component_registry.py +149 -0
- ti4_rules_engine-0.1.0/registry/effect_registry.py +201 -0
- ti4_rules_engine-0.1.0/scripts/__init__.py +0 -0
- ti4_rules_engine-0.1.0/scripts/analyze_game.py +1434 -0
- ti4_rules_engine-0.1.0/tests/conftest.py +150 -0
- ti4_rules_engine-0.1.0/tests/test_analyze_game.py +1298 -0
- ti4_rules_engine-0.1.0/tests/test_asyncti4_adapter.py +663 -0
- ti4_rules_engine-0.1.0/tests/test_combat.py +260 -0
- ti4_rules_engine-0.1.0/tests/test_engine.py +94 -0
- ti4_rules_engine-0.1.0/tests/test_history.py +110 -0
- ti4_rules_engine-0.1.0/tests/test_models.py +234 -0
- ti4_rules_engine-0.1.0/tests/test_movement.py +285 -0
- ti4_rules_engine-0.1.0/tests/test_options.py +452 -0
- ti4_rules_engine-0.1.0/tests/test_phase_steps.py +369 -0
- ti4_rules_engine-0.1.0/tests/test_registry.py +215 -0
- ti4_rules_engine-0.1.0/tests/test_scoring.py +972 -0
- ti4_rules_engine-0.1.0/tests/test_utils.py +79 -0
- ti4_rules_engine-0.1.0/utils/__init__.py +9 -0
- ti4_rules_engine-0.1.0/utils/asset_mapping.py +151 -0
- ti4_rules_engine-0.1.0/uv.lock +524 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Analyze TI4 Game
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
game_number:
|
|
7
|
+
description: "AsyncTI4 game number (e.g. pbd22295)"
|
|
8
|
+
required: true
|
|
9
|
+
type: string
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
analyze:
|
|
13
|
+
name: Fetch and analyze game ${{ inputs.game_number }}
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout repository
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.14"
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: pip install .
|
|
29
|
+
|
|
30
|
+
- name: Analyze game ${{ inputs.game_number }}
|
|
31
|
+
run: python scripts/analyze_game.py "${{ inputs.game_number }}"
|
|
32
|
+
env:
|
|
33
|
+
PYTHONPATH: ${{ github.workspace }}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
run-tests:
|
|
9
|
+
name: Runs Tests
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout repository
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: "3.14"
|
|
20
|
+
|
|
21
|
+
- name: Install Dependencies
|
|
22
|
+
run: pip install ".[dev]"
|
|
23
|
+
|
|
24
|
+
- name: Run Unit Tests
|
|
25
|
+
run: python -m pytest tests
|
|
26
|
+
|
|
27
|
+
publish:
|
|
28
|
+
name: Build and publish to PyPI
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
needs: run-tests
|
|
31
|
+
permissions:
|
|
32
|
+
id-token: write
|
|
33
|
+
|
|
34
|
+
steps:
|
|
35
|
+
- name: Checkout repository
|
|
36
|
+
uses: actions/checkout@v4
|
|
37
|
+
|
|
38
|
+
- name: Set up Python
|
|
39
|
+
uses: actions/setup-python@v5
|
|
40
|
+
with:
|
|
41
|
+
python-version: "3.14"
|
|
42
|
+
|
|
43
|
+
- name: Install build tools
|
|
44
|
+
run: pip install build
|
|
45
|
+
|
|
46
|
+
- name: Build package
|
|
47
|
+
run: python -m build
|
|
48
|
+
|
|
49
|
+
- name: Publish to PyPI
|
|
50
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Virtual environments
|
|
2
|
+
.venv/
|
|
3
|
+
venv/
|
|
4
|
+
env/
|
|
5
|
+
|
|
6
|
+
# Python cache
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[cod]
|
|
9
|
+
*.pyo
|
|
10
|
+
*.pyd
|
|
11
|
+
.Python
|
|
12
|
+
|
|
13
|
+
# Build / distribution
|
|
14
|
+
dist/
|
|
15
|
+
build/
|
|
16
|
+
*.egg-info/
|
|
17
|
+
*.egg
|
|
18
|
+
|
|
19
|
+
# pytest / coverage
|
|
20
|
+
.pytest_cache/
|
|
21
|
+
.coverage
|
|
22
|
+
htmlcov/
|
|
23
|
+
coverage.xml
|
|
24
|
+
|
|
25
|
+
# Editor
|
|
26
|
+
.vscode/
|
|
27
|
+
.idea/
|
|
28
|
+
*.swp
|
|
29
|
+
|
|
30
|
+
# OS
|
|
31
|
+
.DS_Store
|
|
32
|
+
Thumbs.db
|
|
33
|
+
|
|
34
|
+
# uv lock (optional, commit if you want reproducible installs)
|
|
35
|
+
# uv.lock
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adam B
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ti4-rules-engine
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Pythonic, structured data engine for Twilight Imperium 4th Edition
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 Adam B
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Python: >=3.14
|
|
28
|
+
Requires-Dist: pydantic>=2.0
|
|
29
|
+
Requires-Dist: structlog>=24.0
|
|
30
|
+
Requires-Dist: transitions>=0.9
|
|
31
|
+
Provides-Extra: api
|
|
32
|
+
Requires-Dist: fastapi>=0.110; extra == 'api'
|
|
33
|
+
Requires-Dist: uvicorn[standard]>=0.29; extra == 'api'
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# TI4 Rules Engine
|
|
41
|
+
|
|
42
|
+
A Pythonic, structured data engine for Twilight Imperium 4th Edition. Tracks
|
|
43
|
+
game state, provides rule references, and calculates player options from a live
|
|
44
|
+
[AsyncTI4](https://github.com/AsyncTI4/TI4_map_generator_bot) Discord bot game.
|
|
45
|
+
|
|
46
|
+
## Analyse a game in one command
|
|
47
|
+
|
|
48
|
+
No installation required — just `uvx`:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
uvx --from ti4-rules-engine ti4-analyze <game_name>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Replace `<game_name>` with the name of your AsyncTI4 game (the identifier shown
|
|
55
|
+
by the bot, e.g. `pbd22295`):
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
uvx --from ti4-rules-engine ti4-analyze pbd22295
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The command fetches the live game snapshot from the AsyncTI4 API and prints:
|
|
62
|
+
|
|
63
|
+
- Current round, phase, and active player
|
|
64
|
+
- Per-player summary: faction, VP, resources, planets, technologies, and leaders
|
|
65
|
+
- Every legal action available to each player under TI4 rules right now
|
|
66
|
+
- Reachable systems for each fleet (movement + anomaly rules applied)
|
|
67
|
+
|
|
68
|
+
> **Note:** `uvx --from ti4-rules-engine` requires the package to be published
|
|
69
|
+
> on PyPI. Until then, clone the repo and use the local install instead:
|
|
70
|
+
>
|
|
71
|
+
> ```bash
|
|
72
|
+
> git clone https://github.com/adam133/ti4-rules-engine
|
|
73
|
+
> cd ti4-rules-engine
|
|
74
|
+
> uv tool install .
|
|
75
|
+
> ti4-analyze pbd22295
|
|
76
|
+
> ```
|
|
77
|
+
|
|
78
|
+
### What it shows
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
============================================================
|
|
82
|
+
Game: pbd22295 Round: 3 Phase: action
|
|
83
|
+
Active: sargun
|
|
84
|
+
============================================================
|
|
85
|
+
|
|
86
|
+
sargun [ACTIVE]
|
|
87
|
+
Faction: Nekro Virus
|
|
88
|
+
VP: 5
|
|
89
|
+
TG: 3 | Commodities: 0
|
|
90
|
+
Tokens: 3 tactical / 5 fleet / 2 strategy
|
|
91
|
+
Planets: 8 controlled, 2 exhausted
|
|
92
|
+
...
|
|
93
|
+
Actions available:
|
|
94
|
+
• tactical_action
|
|
95
|
+
• component_action
|
|
96
|
+
• strategic_action
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Further reading
|
|
100
|
+
|
|
101
|
+
- **[docs/implementation.md](docs/implementation.md)** — module reference and
|
|
102
|
+
API examples (game session setup, modifier system, combat simulation, scoring,
|
|
103
|
+
movement, opponent public info)
|
|
104
|
+
- **[docs/contributing.md](docs/contributing.md)** — local dev setup, running
|
|
105
|
+
tests, and project roadmap
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# TI4 Rules Engine
|
|
2
|
+
|
|
3
|
+
A Pythonic, structured data engine for Twilight Imperium 4th Edition. Tracks
|
|
4
|
+
game state, provides rule references, and calculates player options from a live
|
|
5
|
+
[AsyncTI4](https://github.com/AsyncTI4/TI4_map_generator_bot) Discord bot game.
|
|
6
|
+
|
|
7
|
+
## Analyse a game in one command
|
|
8
|
+
|
|
9
|
+
No installation required — just `uvx`:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uvx --from ti4-rules-engine ti4-analyze <game_name>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Replace `<game_name>` with the name of your AsyncTI4 game (the identifier shown
|
|
16
|
+
by the bot, e.g. `pbd22295`):
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
uvx --from ti4-rules-engine ti4-analyze pbd22295
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The command fetches the live game snapshot from the AsyncTI4 API and prints:
|
|
23
|
+
|
|
24
|
+
- Current round, phase, and active player
|
|
25
|
+
- Per-player summary: faction, VP, resources, planets, technologies, and leaders
|
|
26
|
+
- Every legal action available to each player under TI4 rules right now
|
|
27
|
+
- Reachable systems for each fleet (movement + anomaly rules applied)
|
|
28
|
+
|
|
29
|
+
> **Note:** `uvx --from ti4-rules-engine` requires the package to be published
|
|
30
|
+
> on PyPI. Until then, clone the repo and use the local install instead:
|
|
31
|
+
>
|
|
32
|
+
> ```bash
|
|
33
|
+
> git clone https://github.com/adam133/ti4-rules-engine
|
|
34
|
+
> cd ti4-rules-engine
|
|
35
|
+
> uv tool install .
|
|
36
|
+
> ti4-analyze pbd22295
|
|
37
|
+
> ```
|
|
38
|
+
|
|
39
|
+
### What it shows
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
============================================================
|
|
43
|
+
Game: pbd22295 Round: 3 Phase: action
|
|
44
|
+
Active: sargun
|
|
45
|
+
============================================================
|
|
46
|
+
|
|
47
|
+
sargun [ACTIVE]
|
|
48
|
+
Faction: Nekro Virus
|
|
49
|
+
VP: 5
|
|
50
|
+
TG: 3 | Commodities: 0
|
|
51
|
+
Tokens: 3 tactical / 5 fleet / 2 strategy
|
|
52
|
+
Planets: 8 controlled, 2 exhausted
|
|
53
|
+
...
|
|
54
|
+
Actions available:
|
|
55
|
+
• tactical_action
|
|
56
|
+
• component_action
|
|
57
|
+
• strategic_action
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Further reading
|
|
61
|
+
|
|
62
|
+
- **[docs/implementation.md](docs/implementation.md)** — module reference and
|
|
63
|
+
API examples (game session setup, modifier system, combat simulation, scoring,
|
|
64
|
+
movement, opponent public info)
|
|
65
|
+
- **[docs/contributing.md](docs/contributing.md)** — local dev setup, running
|
|
66
|
+
tests, and project roadmap
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TI4 Rules Engine – adapters package.
|
|
3
|
+
|
|
4
|
+
Provides converters from external game-state formats into the engine's
|
|
5
|
+
native :class:`~models.state.GameState`.
|
|
6
|
+
|
|
7
|
+
Currently supported formats
|
|
8
|
+
---------------------------
|
|
9
|
+
* **AsyncTI4** – the JSON snapshot produced by the `AsyncTI4 Discord bot
|
|
10
|
+
<https://github.com/AsyncTI4/TI4_map_generator_bot>`_.
|
|
11
|
+
See :mod:`adapters.asyncti4` for details.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from adapters.asyncti4 import AsyncTI4GameData, from_asyncti4
|
|
15
|
+
|
|
16
|
+
__all__ = ["AsyncTI4GameData", "from_asyncti4"]
|