trianglengin 1.0.6__py3-none-any.whl
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.
- tests/__init__.py +0 -0
- tests/conftest.py +108 -0
- tests/core/__init__.py +2 -0
- tests/core/environment/README.md +47 -0
- tests/core/environment/__init__.py +2 -0
- tests/core/environment/test_action_codec.py +50 -0
- tests/core/environment/test_game_state.py +483 -0
- tests/core/environment/test_grid_data.py +205 -0
- tests/core/environment/test_grid_logic.py +362 -0
- tests/core/environment/test_shape_logic.py +171 -0
- tests/core/environment/test_step.py +372 -0
- tests/core/structs/__init__.py +0 -0
- tests/core/structs/test_shape.py +83 -0
- tests/core/structs/test_triangle.py +97 -0
- tests/utils/__init__.py +0 -0
- tests/utils/test_geometry.py +93 -0
- trianglengin/__init__.py +18 -0
- trianglengin/app.py +110 -0
- trianglengin/cli.py +134 -0
- trianglengin/config/__init__.py +9 -0
- trianglengin/config/display_config.py +47 -0
- trianglengin/config/env_config.py +103 -0
- trianglengin/core/__init__.py +8 -0
- trianglengin/core/environment/__init__.py +31 -0
- trianglengin/core/environment/action_codec.py +37 -0
- trianglengin/core/environment/game_state.py +217 -0
- trianglengin/core/environment/grid/README.md +46 -0
- trianglengin/core/environment/grid/__init__.py +18 -0
- trianglengin/core/environment/grid/grid_data.py +140 -0
- trianglengin/core/environment/grid/line_cache.py +189 -0
- trianglengin/core/environment/grid/logic.py +131 -0
- trianglengin/core/environment/logic/__init__.py +3 -0
- trianglengin/core/environment/logic/actions.py +38 -0
- trianglengin/core/environment/logic/step.py +134 -0
- trianglengin/core/environment/shapes/__init__.py +19 -0
- trianglengin/core/environment/shapes/logic.py +84 -0
- trianglengin/core/environment/shapes/templates.py +587 -0
- trianglengin/core/structs/__init__.py +27 -0
- trianglengin/core/structs/constants.py +28 -0
- trianglengin/core/structs/shape.py +61 -0
- trianglengin/core/structs/triangle.py +48 -0
- trianglengin/interaction/README.md +45 -0
- trianglengin/interaction/__init__.py +17 -0
- trianglengin/interaction/debug_mode_handler.py +96 -0
- trianglengin/interaction/event_processor.py +43 -0
- trianglengin/interaction/input_handler.py +82 -0
- trianglengin/interaction/play_mode_handler.py +141 -0
- trianglengin/utils/__init__.py +9 -0
- trianglengin/utils/geometry.py +73 -0
- trianglengin/utils/types.py +10 -0
- trianglengin/visualization/README.md +44 -0
- trianglengin/visualization/__init__.py +61 -0
- trianglengin/visualization/core/README.md +52 -0
- trianglengin/visualization/core/__init__.py +12 -0
- trianglengin/visualization/core/colors.py +117 -0
- trianglengin/visualization/core/coord_mapper.py +73 -0
- trianglengin/visualization/core/fonts.py +55 -0
- trianglengin/visualization/core/layout.py +101 -0
- trianglengin/visualization/core/visualizer.py +232 -0
- trianglengin/visualization/drawing/README.md +45 -0
- trianglengin/visualization/drawing/__init__.py +30 -0
- trianglengin/visualization/drawing/grid.py +156 -0
- trianglengin/visualization/drawing/highlight.py +30 -0
- trianglengin/visualization/drawing/hud.py +39 -0
- trianglengin/visualization/drawing/previews.py +172 -0
- trianglengin/visualization/drawing/shapes.py +36 -0
- trianglengin-1.0.6.dist-info/METADATA +367 -0
- trianglengin-1.0.6.dist-info/RECORD +72 -0
- trianglengin-1.0.6.dist-info/WHEEL +5 -0
- trianglengin-1.0.6.dist-info/entry_points.txt +2 -0
- trianglengin-1.0.6.dist-info/licenses/LICENSE +22 -0
- trianglengin-1.0.6.dist-info/top_level.txt +2 -0
@@ -0,0 +1,367 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: trianglengin
|
3
|
+
Version: 1.0.6
|
4
|
+
Summary: Core engine (game logic, features, data) for a triangle puzzle game.
|
5
|
+
Author-email: "Luis Guilherme P. M." <lgpelin92@gmail.com>
|
6
|
+
License:
|
7
|
+
MIT License
|
8
|
+
|
9
|
+
Copyright (c) 2025 Luis Guilherme P. M.
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
13
|
+
in the Software without restriction, including without limitation the rights
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
16
|
+
furnished to do so, subject to the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
19
|
+
copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
27
|
+
SOFTWARE.
|
28
|
+
Project-URL: Homepage, https://github.com/lguibr/trianglengin
|
29
|
+
Project-URL: Bug Tracker, https://github.com/lguibr/trianglengin/issues
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
31
|
+
Classifier: Programming Language :: Python :: 3.10
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
34
|
+
Classifier: Operating System :: OS Independent
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
36
|
+
Classifier: Topic :: Games/Entertainment :: Puzzle Games
|
37
|
+
Classifier: Development Status :: 4 - Beta
|
38
|
+
Requires-Python: >=3.10
|
39
|
+
Description-Content-Type: text/markdown
|
40
|
+
License-File: LICENSE
|
41
|
+
Requires-Dist: numpy>=1.20.0
|
42
|
+
Requires-Dist: pydantic>=2.0.0
|
43
|
+
Requires-Dist: typing_extensions>=4.0.0
|
44
|
+
Requires-Dist: pygame>=2.1.0
|
45
|
+
Requires-Dist: typer[all]>=0.9.0
|
46
|
+
Provides-Extra: dev
|
47
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
48
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
49
|
+
Requires-Dist: pytest-mock>=3.0.0; extra == "dev"
|
50
|
+
Requires-Dist: ruff; extra == "dev"
|
51
|
+
Requires-Dist: mypy; extra == "dev"
|
52
|
+
Requires-Dist: build; extra == "dev"
|
53
|
+
Requires-Dist: twine; extra == "dev"
|
54
|
+
Requires-Dist: codecov; extra == "dev"
|
55
|
+
Dynamic: license-file
|
56
|
+
|
57
|
+
|
58
|
+
[](https://github.com/lguibr/trianglengin/actions/workflows/ci_cd.yml) <!-- Update workflow name if changed -->
|
59
|
+
[](https://codecov.io/gh/lguibr/trianglengin) <!-- Update repo name -->
|
60
|
+
[](https://badge.fury.io/py/trianglengin)
|
61
|
+
[](https://opensource.org/licenses/MIT)
|
62
|
+
[](https://www.python.org/downloads/)
|
63
|
+
|
64
|
+
# Triangle Engine (`trianglengin`)
|
65
|
+
<img src="bitmap.png" alt="trianglengin logo" width="300"/>
|
66
|
+
|
67
|
+
This library provides the core, reusable components for reinforcement learning agents playing a triangle puzzle game.
|
68
|
+
|
69
|
+
It encapsulates:
|
70
|
+
|
71
|
+
1. **Core Game Logic:** Environment rules, state representation, actions.
|
72
|
+
2. **Basic Visualization:** Pygame rendering for interactive play/debug modes.
|
73
|
+
3. **Interaction Handling:** Input processing for interactive modes.
|
74
|
+
4. **Utilities:** General helpers, geometry functions, shared types.
|
75
|
+
5. **Configuration:** Pydantic models for environment and display settings.
|
76
|
+
6. **(Planned) Feature Extraction:** Logic to convert game state to NN input format.
|
77
|
+
7. **(Planned) Data Management Framework:** Structure for saving/loading checkpoints and buffers.
|
78
|
+
8. **(Planned) Statistics Collection:** Components for tracking game/training stats.
|
79
|
+
|
80
|
+
---
|
81
|
+
|
82
|
+
## 🎮 The Ultimate Triangle Puzzle Guide 🧩
|
83
|
+
|
84
|
+
Get ready to become a Triangle Master! This guide explains everything you need to know to play the game, step-by-step, with lots of details!
|
85
|
+
|
86
|
+
### 1. Introduction: Your Mission! 🎯
|
87
|
+
|
88
|
+
Your goal is to place colorful shapes onto a special triangular grid. By filling up lines of triangles, you make them disappear and score points! Keep placing shapes and clearing lines for as long as possible to get the highest score before the grid fills up and you run out of moves. Sounds simple? Let's dive into the details!
|
89
|
+
|
90
|
+
### 2. The Playing Field: The Grid 🗺️
|
91
|
+
|
92
|
+
- **Triangle Cells:** The game board is a grid made of many small triangles. Some point UP (🔺) and some point DOWN (🔻). They alternate like a checkerboard pattern based on their row and column index (specifically, `(row + col) % 2 != 0` means UP).
|
93
|
+
- **Shape:** The grid itself is rectangular overall, but the playable area within it is typically shaped like a triangle or hexagon, wider in the middle and narrower at the top and bottom.
|
94
|
+
- **Playable Area:** You can only place shapes within the designated playable area.
|
95
|
+
- **Death Zones 💀:** Around the edges of the playable area (often at the start and end of rows), some triangles are marked as "Death Zones". You **cannot** place any part of a shape onto these triangles. They are off-limits! Think of them as the boundaries within the rectangular grid.
|
96
|
+
|
97
|
+
### 3. Your Tools: The Shapes 🟦🟥🟩
|
98
|
+
|
99
|
+
- **Shape Formation:** Each shape is a collection of connected small triangles (🔺 and 🔻). They come in different colors and arrangements. Some might be a single triangle, others might be long lines, L-shapes, or more complex patterns.
|
100
|
+
- **Relative Positions:** The triangles within a shape have fixed positions _relative to each other_. When you move the shape, all its triangles move together as one block.
|
101
|
+
- **Preview Area:** You will always have **three** shapes available to choose from at any time. These are shown in a special "preview area" on the side of the screen.
|
102
|
+
|
103
|
+
### 4. Making Your Move: Placing Shapes 🖱️➡️▦
|
104
|
+
|
105
|
+
This is the core action! Here's exactly how to place a shape:
|
106
|
+
|
107
|
+
- **Step 4a: Select a Shape:** Look at the three shapes in the preview area. Click on the one you want to place. It should highlight 💡 to show it's selected.
|
108
|
+
- **Step 4b: Aim on the Grid:** Move your mouse cursor over the main grid. You'll see a faint "ghost" image of your selected shape following your mouse. This preview helps you aim.
|
109
|
+
- **Step 4c: The Placement Rules (MUST Follow!)**
|
110
|
+
- 📏 **Rule 1: Fit Inside Playable Area:** ALL triangles of your chosen shape must land within the playable grid area. No part of the shape can land in a Death Zone 💀.
|
111
|
+
- 🧱 **Rule 2: No Overlap:** ALL triangles of your chosen shape must land on currently _empty_ spaces on the grid. You cannot place a shape on top of triangles that are already filled with color from previous shapes.
|
112
|
+
- 📐 **Rule 3: Orientation Match!** This is crucial!
|
113
|
+
- If a part of your shape is an UP triangle (🔺), it MUST land on an UP space (🔺) on the grid.
|
114
|
+
- If a part of your shape is a DOWN triangle (🔻), it MUST land on a DOWN space (🔻) on the grid.
|
115
|
+
- 🔺➡️🔺 (OK!)
|
116
|
+
- 🔻➡️🔻 (OK!)
|
117
|
+
- 🔺➡️🔻 (INVALID! ❌)
|
118
|
+
- 🔻➡️🔺 (INVALID! ❌)
|
119
|
+
- **Visual Feedback:** The game helps you!
|
120
|
+
- 👍 **Valid Spot:** If the position under your mouse follows ALL three rules, the ghost preview will usually look solid and possibly greenish. This means you _can_ place the shape here.
|
121
|
+
- 👎 **Invalid Spot:** If the position breaks _any_ of the rules (out of bounds, overlaps, wrong orientation), the ghost preview will usually look faded and possibly reddish. This means you _cannot_ place the shape here.
|
122
|
+
- **Step 4d: Confirm Placement:** Once you find a **valid** spot (👍), click the left mouse button again. _Click!_ The shape is now placed permanently on the grid! ✨
|
123
|
+
|
124
|
+
### 5. Scoring Points: How You Win! 🏆
|
125
|
+
|
126
|
+
You score points in two main ways:
|
127
|
+
|
128
|
+
- **Placing Triangles:** You get a small number of points for _every single small triangle_ that makes up the shape you just placed. (e.g., placing a 3-triangle shape might give you 3 \* tiny_score points).
|
129
|
+
- **Clearing Lines:** This is where the BIG points come from! You get a much larger number of points for _every single small triangle_ that disappears when you clear a line (or multiple lines at once!). See the next section for details!
|
130
|
+
|
131
|
+
### 6. Line Clearing Magic! ✨ (The Key to High Scores!)
|
132
|
+
|
133
|
+
This is the most exciting part! When you place a shape, the game immediately checks if you've completed any lines. This section explains how the game _finds_ and _clears_ these lines.
|
134
|
+
|
135
|
+
- **What Lines Can Be Cleared?** There are **three** types of lines the game looks for:
|
136
|
+
|
137
|
+
- **Horizontal Lines ↔️:** A straight, unbroken line of filled triangles going across a single row.
|
138
|
+
- **Diagonal Lines (Top-Left to Bottom-Right) ↘️:** An unbroken diagonal line of filled triangles stepping down and to the right.
|
139
|
+
- **Diagonal Lines (Bottom-Left to Top-Right) ↗️:** An unbroken diagonal line of filled triangles stepping up and to the right.
|
140
|
+
|
141
|
+
- **How Lines are Found: Pre-calculation of Maximal Lines**
|
142
|
+
|
143
|
+
- **The Idea:** Instead of checking every possible line combination all the time, the game pre-calculates all *maximal* continuous lines of playable triangles when it starts. A **maximal line** is the longest possible straight segment of *playable* triangles (not in a Death Zone) in one of the three directions (Horizontal, Diagonal ↘️, Diagonal ↗️).
|
144
|
+
- **Tracing:** For every playable triangle on the grid, the game traces outwards in each of the three directions to find the full extent of the continuous playable line passing through that triangle in that direction.
|
145
|
+
- **Storing Maximal Lines:** Only the complete maximal lines found are stored. For example, if tracing finds a playable sequence `A-B-C-D`, only the line `(A,B,C,D)` is stored, not the sub-segments like `(A,B,C)` or `(B,C,D)`. These maximal lines represent the *potential* lines that can be cleared.
|
146
|
+
- **Coordinate Map:** The game also builds a map linking each playable triangle coordinate `(r, c)` to the set of maximal lines it belongs to. This allows for quick lookup.
|
147
|
+
|
148
|
+
- **Defining the Paths (Neighbor Logic):** How does the game know which triangle is "next" when tracing? It depends on the current triangle's orientation (🔺 or 🔻) and the direction being traced:
|
149
|
+
|
150
|
+
- **Horizontal ↔️:**
|
151
|
+
- Left Neighbor: `(r, c-1)` (Always in the same row)
|
152
|
+
- Right Neighbor: `(r, c+1)` (Always in the same row)
|
153
|
+
- **Diagonal ↘️ (TL-BR):**
|
154
|
+
- If current is 🔺 (Up): Next is `(r+1, c)` (Down triangle directly below)
|
155
|
+
- If current is 🔻 (Down): Next is `(r, c+1)` (Up triangle to the right)
|
156
|
+
- **Diagonal ↗️ (BL-TR):**
|
157
|
+
- If current is 🔻 (Down): Next is `(r-1, c)` (Up triangle directly above)
|
158
|
+
- If current is 🔺 (Up): Next is `(r, c+1)` (Down triangle to the right)
|
159
|
+
|
160
|
+
- **Visualizing the Paths:**
|
161
|
+
|
162
|
+
- **Horizontal ↔️:**
|
163
|
+
```
|
164
|
+
... [🔻][🔺][🔻][🔺][🔻][🔺] ... (Moves left/right in the same row)
|
165
|
+
```
|
166
|
+
- **Diagonal ↘️ (TL-BR):** (Connects via shared horizontal edges)
|
167
|
+
```
|
168
|
+
...[🔺]...
|
169
|
+
...[🔻][🔺] ...
|
170
|
+
... [🔻][🔺] ...
|
171
|
+
... [🔻] ...
|
172
|
+
(Path alternates row/col increments depending on orientation)
|
173
|
+
```
|
174
|
+
- **Diagonal ↗️ (BL-TR):** (Connects via shared horizontal edges)
|
175
|
+
```
|
176
|
+
... [🔺] ...
|
177
|
+
... [🔺][🔻] ...
|
178
|
+
... [🔺][🔻] ...
|
179
|
+
... [🔻] ...
|
180
|
+
(Path alternates row/col increments depending on orientation)
|
181
|
+
```
|
182
|
+
|
183
|
+
- **The "Full Line" Rule:** After you place a piece, the game looks at the coordinates `(r, c)` of the triangles you just placed. Using the pre-calculated map, it finds all the *maximal* lines that contain _any_ of those coordinates. For each of those maximal lines (that have at least 2 triangles), it checks: "Is _every single triangle coordinate_ in this maximal line now occupied?" If yes, that line is complete! (Note: Single isolated triangles don't count as clearable lines).
|
184
|
+
|
185
|
+
- **The _Poof_! 💨:**
|
186
|
+
- If placing your shape completes one or MORE maximal lines (of any type, length >= 2) simultaneously, all the triangles in ALL completed lines vanish instantly!
|
187
|
+
- The spaces become empty again.
|
188
|
+
- You score points for _every single triangle_ that vanished. Clearing multiple lines at once is the best way to rack up points! 🥳
|
189
|
+
|
190
|
+
### 7. Getting New Shapes: The Refill 🪄
|
191
|
+
|
192
|
+
- **The Trigger:** The game only gives you new shapes when a specific condition is met.
|
193
|
+
- **The Condition:** New shapes appear **only when all three of your preview slots become empty at the exact same time.**
|
194
|
+
- **How it Happens:** This usually occurs right after you place your _last_ available shape (the third one).
|
195
|
+
- **The Refill:** As soon as the third slot becomes empty, _BAM!_ 🪄 Three brand new, randomly generated shapes instantly appear in the preview slots.
|
196
|
+
- **Important:** If you place a shape and only one or two slots are empty, you **do not** get new shapes yet. You must use up all three before the refill happens.
|
197
|
+
|
198
|
+
### 8. The End of the Road: Game Over 😭
|
199
|
+
|
200
|
+
So, how does the game end?
|
201
|
+
|
202
|
+
- **The Condition:** The game is over when you **cannot legally place _any_ of the three shapes currently available in your preview slots anywhere on the grid.**
|
203
|
+
- **The Check:** After every move (placing a shape and any resulting line clears), and after any potential shape refill, the game checks: "Is there at least one valid spot on the grid for Shape 1? OR for Shape 2? OR for Shape 3?"
|
204
|
+
- **No More Moves:** If the answer is "NO" for all three shapes (meaning none of them can be placed anywhere according to the Placement Rules), then the game immediately ends.
|
205
|
+
- **Strategy:** This means you need to be careful! Don't fill up the grid in a way that leaves no room for the types of shapes you might get later. Always try to keep options open! 🤔
|
206
|
+
|
207
|
+
That's it! Now you know all the rules. Go forth and conquer the Triangle Puzzle! 🏆
|
208
|
+
|
209
|
+
---
|
210
|
+
|
211
|
+
## Purpose
|
212
|
+
|
213
|
+
The primary goal is to provide a self-contained, installable library for the core logic and basic interactive UI of the triangle puzzle game. This allows different RL agent implementations or other applications to build upon a consistent and well-defined game backend, avoiding code duplication.
|
214
|
+
|
215
|
+
## Installation
|
216
|
+
|
217
|
+
```bash
|
218
|
+
# For standard use (once published or built):
|
219
|
+
pip install trianglengin
|
220
|
+
```
|
221
|
+
|
222
|
+
## Running Interactive Modes
|
223
|
+
|
224
|
+
After installing (`pip install trianglengin`), you can run the interactive modes directly:
|
225
|
+
|
226
|
+
- **Play Mode:**
|
227
|
+
```bash
|
228
|
+
trianglengin play [--seed 42] [--log-level INFO]
|
229
|
+
```
|
230
|
+
- **Debug Mode:**
|
231
|
+
```bash
|
232
|
+
trianglengin debug [--seed 42] [--log-level DEBUG]
|
233
|
+
```
|
234
|
+
|
235
|
+
---
|
236
|
+
|
237
|
+
## Local Development & Testing
|
238
|
+
|
239
|
+
These instructions are for developers contributing to `trianglengin`.
|
240
|
+
|
241
|
+
1. **Clone the Repository:**
|
242
|
+
```bash
|
243
|
+
git clone https://github.com/lguibr/trianglengin.git
|
244
|
+
cd trianglengin
|
245
|
+
```
|
246
|
+
|
247
|
+
2. **Create and Activate Virtual Environment:**
|
248
|
+
* **Using `venv` (Recommended):**
|
249
|
+
```bash
|
250
|
+
python -m venv venv
|
251
|
+
# On Linux/macOS:
|
252
|
+
source venv/bin/activate
|
253
|
+
# On Windows (Command Prompt):
|
254
|
+
# .\venv\Scripts\activate
|
255
|
+
# On Windows (PowerShell):
|
256
|
+
# .\venv\Scripts\Activate.ps1
|
257
|
+
```
|
258
|
+
* **Using `conda`:**
|
259
|
+
```bash
|
260
|
+
conda create -n trianglengin python=3.10
|
261
|
+
conda activate trianglengin
|
262
|
+
```
|
263
|
+
**IMPORTANT:** Ensure your virtual environment is activated in your terminal *before* proceeding to the next step. You should see `(venv)` or `(trianglengin)` at the beginning of your terminal prompt.
|
264
|
+
|
265
|
+
3. **Install in Editable Mode with Dev Dependencies:**
|
266
|
+
* **Make sure your virtual environment is active!**
|
267
|
+
* Run the following command from the project root directory (where `pyproject.toml` is located):
|
268
|
+
```bash
|
269
|
+
# Use quotes to prevent shell expansion issues (especially in Zsh)
|
270
|
+
pip install -e '.[dev]'
|
271
|
+
```
|
272
|
+
**Note the syntax:** `'.[dev]'` includes the optional development dependencies, and the quotes prevent the shell from misinterpreting the brackets.
|
273
|
+
This installs the `trianglengin` package itself in a way that your code changes are immediately reflected, *and* it installs all the tools needed for testing and development (`pytest`, `ruff`, `mypy`, etc.).
|
274
|
+
|
275
|
+
4. **Running Checks:**
|
276
|
+
* **Make sure your virtual environment is active!**
|
277
|
+
* **Tests & Coverage:**
|
278
|
+
```bash
|
279
|
+
pytest tests/ --cov=trianglengin --cov-report=xml
|
280
|
+
```
|
281
|
+
(This generates `coverage.xml` for upload if using Codecov).
|
282
|
+
To just run tests: `pytest`
|
283
|
+
* **Linting:**
|
284
|
+
```bash
|
285
|
+
ruff check .
|
286
|
+
```
|
287
|
+
* **Formatting:**
|
288
|
+
```bash
|
289
|
+
ruff format .
|
290
|
+
```
|
291
|
+
* **Type Checking:**
|
292
|
+
```bash
|
293
|
+
mypy trianglengin/
|
294
|
+
```
|
295
|
+
|
296
|
+
5. **Troubleshooting "command not found" errors:**
|
297
|
+
* If you see errors like `pytest: command not found`, `ruff: command not found`, or `mypy: command not found`, the **most likely cause** is that your virtual environment is **not activated**. Go back to Step 2 and activate it.
|
298
|
+
* If the environment is active, double-check that you ran `pip install -e '.[dev]'` correctly in Step 3 (with the quotes and square brackets).
|
299
|
+
|
300
|
+
---
|
301
|
+
|
302
|
+
## Project Structure
|
303
|
+
|
304
|
+
```
|
305
|
+
trianglengin/
|
306
|
+
├── .github/workflows/ # GitHub Actions CI/CD
|
307
|
+
│ └── ci_cd.yml
|
308
|
+
├── trianglengin/ # Source code for the library package
|
309
|
+
│ ├── __init__.py # Exposes public API
|
310
|
+
│ ├── app.py # Interactive mode application runner
|
311
|
+
│ ├── cli.py # CLI definition (play/debug)
|
312
|
+
│ ├── core/ # Core game logic
|
313
|
+
│ │ ├── __init__.py
|
314
|
+
│ │ ├── structs/ # Triangle, Shape, constants
|
315
|
+
│ │ │ └── README.md # Link: trianglengin/core/structs/README.md
|
316
|
+
│ │ └── environment/ # GameState, GridData, GridLogic, ShapeLogic, ActionCodec
|
317
|
+
│ │ └── README.md # Link: trianglengin/core/environment/README.md
|
318
|
+
│ ├── interaction/ # User input handling for interactive modes
|
319
|
+
│ │ └── README.md # Link: trianglengin/interaction/README.md
|
320
|
+
│ ├── visualization/ # Basic Pygame rendering components
|
321
|
+
│ │ ├── __init__.py
|
322
|
+
│ │ ├── core/ # Visualizer, layout, colors, fonts, coord_mapper
|
323
|
+
│ │ │ └── README.md # Link: trianglengin/visualization/core/README.md
|
324
|
+
│ │ └── drawing/ # Specific drawing functions (grid, shapes, previews, hud)
|
325
|
+
│ │ └── README.md # Link: trianglengin/visualization/drawing/README.md
|
326
|
+
│ ├── features/ # Feature extraction logic (Planned)
|
327
|
+
│ │ └── README.md # Link: trianglengin/features/README.md
|
328
|
+
│ ├── data/ # Data management framework (Planned)
|
329
|
+
│ │ └── README.md # Link: trianglengin/data/README.md
|
330
|
+
│ ├── stats/ # Statistics collection actor (Planned)
|
331
|
+
│ │ └── README.md # Link: trianglengin/stats/README.md
|
332
|
+
│ ├── utils/ # General utilities
|
333
|
+
│ │ └── README.md # Link: trianglengin/utils/README.md
|
334
|
+
│ └── config/ # Shared configuration models
|
335
|
+
│ ├── __init__.py
|
336
|
+
│ ├── env_config.py # Environment configuration (EnvConfig)
|
337
|
+
│ └── display_config.py # Display configuration (DisplayConfig)
|
338
|
+
├── tests/ # Unit tests for trianglengin components
|
339
|
+
│ ├── __init__.py
|
340
|
+
│ ├── conftest.py # Shared test fixtures
|
341
|
+
│ ├── core/
|
342
|
+
│ │ ├── __init__.py
|
343
|
+
│ │ ├── environment/ # Contains test_grid_logic.py now
|
344
|
+
│ │ └── structs/
|
345
|
+
│ └── README.md # Link: tests/README.md
|
346
|
+
├── .gitignore
|
347
|
+
├── pyproject.toml # Build config, dependencies
|
348
|
+
├── README.md # This file
|
349
|
+
├── LICENSE
|
350
|
+
└── MANIFEST.in
|
351
|
+
```
|
352
|
+
|
353
|
+
## Core Components
|
354
|
+
|
355
|
+
- **`trianglengin.core`**: Contains the fundamental game logic.
|
356
|
+
- **`structs`**: Defines `Triangle`, `Shape`, and related constants. ([`core/structs/README.md`](trianglengin/core/structs/README.md))
|
357
|
+
- **`environment`**: Defines `GameState`, `GridData`, `GridLogic`, `ShapeLogic`, action encoding/decoding, and step execution logic. ([`core/environment/README.md`](trianglengin/core/environment/README.md))
|
358
|
+
- **`trianglengin.config`**: Contains shared configuration models (`EnvConfig`, `DisplayConfig`).
|
359
|
+
- **`trianglengin.visualization`**: Basic Pygame rendering (`Visualizer`, drawing functions, colors, fonts, layout). ([`visualization/README.md`](trianglengin/visualization/README.md))
|
360
|
+
- **`trianglengin.interaction`**: Input handling for interactive modes (`InputHandler`). ([`interaction/README.md`](trianglengin/interaction/README.md))
|
361
|
+
- **`trianglengin.app`**: Integrates components for interactive modes.
|
362
|
+
- **`trianglengin.cli`**: Command-line interface for `play`/`debug`.
|
363
|
+
- **`trianglengin.utils`**: General utility functions and types. ([`utils/README.md`](trianglengin/utils/README.md))
|
364
|
+
|
365
|
+
## Contributing
|
366
|
+
|
367
|
+
Contributions are welcome! Please open an issue or submit a pull request on the [GitHub repository](https://github.com/lguibr/trianglengin). Ensure that changes maintain code quality (pass tests, linting, type checking) and keep READMEs updated.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
tests/conftest.py,sha256=wn4bwFCoRxHL7EBG_B39qkgARvwLc6uPwsrC3xDj-Aw,3504
|
3
|
+
tests/core/__init__.py,sha256=o64J-GTf3XaO8Y2XQSFRIiiJ4DA0ya7B7cLWEyC6GwM,69
|
4
|
+
tests/core/environment/README.md,sha256=HB98MKhLYChQTI-ciihtUt6kk4Ifn5pJJ20G1dBhfFs,3228
|
5
|
+
tests/core/environment/__init__.py,sha256=gfKZDj1vwQrS1CLB1PIC-IcO0eylJSHieujR-km2lZc,81
|
6
|
+
tests/core/environment/test_action_codec.py,sha256=nYAu-sxLDaf_vSbbsN5fFu7WiQujMJm69oczLWSaEMs,2058
|
7
|
+
tests/core/environment/test_game_state.py,sha256=OEGvz5UBoRaVSrL-fhisR2c8jux-sEJEeAopes1Wy7c,18987
|
8
|
+
tests/core/environment/test_grid_data.py,sha256=KqU0yD2VTaKl2-IBKVGnOErEKi2K_kCbfHqb5LJ1NRo,7877
|
9
|
+
tests/core/environment/test_grid_logic.py,sha256=LP_Gmw7F-EfSimpujqqkV2gs0g7bBF7BZFjXHo_GpkY,14168
|
10
|
+
tests/core/environment/test_shape_logic.py,sha256=VgEUl2Mg2xUGcaeD1dKDDvqqsXqHfdPiR2Xr5Xhdr7A,6997
|
11
|
+
tests/core/environment/test_step.py,sha256=cay499ZqijLljzaE1SIyRWFlPvaGxenSS0qshEerqZE,14053
|
12
|
+
tests/core/structs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
+
tests/core/structs/test_shape.py,sha256=9pJ3tcrsgnsbRTwsbyJmSC-IfPFpquja4q3DgbLZW_M,2227
|
14
|
+
tests/core/structs/test_triangle.py,sha256=QcSsTahsCCuJD27xwBoY9rV4U8ShU_ssZQi3U6Ire5Y,3049
|
15
|
+
tests/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
+
tests/utils/test_geometry.py,sha256=D191IXHX25Iw7Y5_-KmWhaYoBpGvl2lqu1Qp5zUmbaQ,3732
|
17
|
+
trianglengin/__init__.py,sha256=fqX0fk-rCk68EPQPQLn293JdN3v4ISHkzigS0iM4oC8,348
|
18
|
+
trianglengin/app.py,sha256=6igqZGZ0tLvBTci3hZn4k_1pyHG24LXBsPu6NEkjJl0,4215
|
19
|
+
trianglengin/cli.py,sha256=X0Q0Qhbbm8p7205u1QBMRipS6Z4p967C4iAX-LmxAlI,3785
|
20
|
+
trianglengin/config/__init__.py,sha256=gBZOzJKHT3hxdhK2cnNruk8qrCaHKmGCy6jR7WP-HJg,264
|
21
|
+
trianglengin/config/display_config.py,sha256=FHY9iKuuk7L5h-xWtDTthHUlvyme4AJeA5kOk-zZJFg,1815
|
22
|
+
trianglengin/config/env_config.py,sha256=9504zTdABGieIbOK-fyzDS0I6VDfVb8NzRWO6dsro8Y,3591
|
23
|
+
trianglengin/core/__init__.py,sha256=qJilayEVOFQ2RjNoyZqIcryRc-7w9NqiDctWGFTr4e4,205
|
24
|
+
trianglengin/core/environment/__init__.py,sha256=7QfXQpw7J6XurbXPJRhdNi-lRvtuQnlTO-v-efF5Du0,746
|
25
|
+
trianglengin/core/environment/action_codec.py,sha256=XOGoESvkoDCkHhSu1uXFnZNTeCeue_T1DV2LlxmeiCU,1361
|
26
|
+
trianglengin/core/environment/game_state.py,sha256=9K_m6yRRfhD0pgttVbyh8m3F2vywZvdMWC6UYyQh-lQ,9142
|
27
|
+
trianglengin/core/environment/grid/README.md,sha256=BQpSfvBCM94RcrhoZdtLlYdvUdIC-T5fd8PK2R_-EnY,3827
|
28
|
+
trianglengin/core/environment/grid/__init__.py,sha256=KW_gqRAYQ0eKmGjZ6X0zfWRukfAEiWwuCCZujOSfZjY,577
|
29
|
+
trianglengin/core/environment/grid/grid_data.py,sha256=360_Q66emJYOvZGbh4Xso52XpuJgNNGOQzHTkwTvyHI,4705
|
30
|
+
trianglengin/core/environment/grid/line_cache.py,sha256=seJuCw1ndg2epSW3UXK2T6O_1vcl7Tl1ad0YoOyM5f8,7011
|
31
|
+
trianglengin/core/environment/grid/logic.py,sha256=tKXZ7qoa8U3yLR5Mk54lZsB1XESCYRhD0oP3wu4yBA0,4921
|
32
|
+
trianglengin/core/environment/logic/__init__.py,sha256=YOFuDJPE66De1-XJkNAtjqJQuN2XAx0ssXhzSL3EWo0,172
|
33
|
+
trianglengin/core/environment/logic/actions.py,sha256=quWQT4_TMmc1_KzzrK220vzIySyMdkbfPByhgo8Otn4,1364
|
34
|
+
trianglengin/core/environment/logic/step.py,sha256=n1kebQ0TTRcZku0AYWiSa23jC9rYN5xQMMVwCzEPhoE,4937
|
35
|
+
trianglengin/core/environment/shapes/__init__.py,sha256=AaJXyz3FSXN1fjgnM0HbRtpEdiCbSD6sh4jbbxAJu6Q,386
|
36
|
+
trianglengin/core/environment/shapes/logic.py,sha256=zYI9rCkxgniP2L81pyidB_VsH9vbj8u-imjSL8omtiA,3412
|
37
|
+
trianglengin/core/environment/shapes/templates.py,sha256=upoe8oAGxFuxGgkzvlCW6RCuwIpUioV3TQVEH8qDll0,8889
|
38
|
+
trianglengin/core/structs/__init__.py,sha256=Y5K2DqxR2yB_1C0lbi1swWQjFXrqp0bBvnjEY-09DRc,625
|
39
|
+
trianglengin/core/structs/constants.py,sha256=_cHd8xgB4Zjn0t6j-w0uwcGHHRQ8kg1HfFuisS5Tahw,996
|
40
|
+
trianglengin/core/structs/shape.py,sha256=S_9UnRNN_dPiTncvsdpVSYTk_8j43Kg_ghr87KeysAg,2382
|
41
|
+
trianglengin/core/structs/triangle.py,sha256=kZ81iJ03G7nKUu1f9JcQsHlEyawM-016ViHTgLJFKl4,1730
|
42
|
+
trianglengin/interaction/README.md,sha256=6z3QkAOqyneqUneYBlTBZ95tbaMpsh0BQXCwK8yItCA,3673
|
43
|
+
trianglengin/interaction/__init__.py,sha256=Gvi9tJIz_fmVFcmOqQ9IdiFzBIKf2wLLcpuboiomsDY,469
|
44
|
+
trianglengin/interaction/debug_mode_handler.py,sha256=tXRPPtXHNMZgVS0x1o-gB2F0q2PSET7A-zQz9ZeuwrE,3425
|
45
|
+
trianglengin/interaction/event_processor.py,sha256=4C9FBgmkISMyvSbsDONVtja6KqzFBf5lDsTD3DvpgDs,1451
|
46
|
+
trianglengin/interaction/input_handler.py,sha256=uGTnVxgowrpU-M0rmXofwrg6q4IkCSeh092CZCl1Ugk,2906
|
47
|
+
trianglengin/interaction/play_mode_handler.py,sha256=PGAXl4hsTADaOwzBLwNnt04i6KQYYDaycjxAlkwKbVM,5561
|
48
|
+
trianglengin/utils/__init__.py,sha256=907xXfoKmxOc86noqwOtnomajkrkbInWvAhR-h5coow,176
|
49
|
+
trianglengin/utils/geometry.py,sha256=oh53Fs1yGEDSQQ6zIXl4lAaqm3JvqUWKBkq4uBlt74w,2749
|
50
|
+
trianglengin/utils/types.py,sha256=u5VALmDiCCWpYdtxS4rMgW5uxNtIEfpjH3tRg12yjYM,231
|
51
|
+
trianglengin/visualization/README.md,sha256=CRKj8CCeMXV9G6HIiw8ursT4_n-UjVne-2iCsSocuOQ,2437
|
52
|
+
trianglengin/visualization/__init__.py,sha256=TGBh7CnSGdh7nfK9NaTiaBHQ4DsmzhAc_jyaMw8KbQU,1676
|
53
|
+
trianglengin/visualization/core/README.md,sha256=ie3IPPXT4SYUNwZ05Fi4aetfUMqXMv-ZWS966d3xo7U,3562
|
54
|
+
trianglengin/visualization/core/__init__.py,sha256=TPKv_bYoHa3L2Nf8VSLetYtUbcGBFcI4UEUHdFN2Olo,271
|
55
|
+
trianglengin/visualization/core/colors.py,sha256=97OpxpgpIEwkGTPk1BWshDZNJ4iU-edoSo6T2N_cgm0,3231
|
56
|
+
trianglengin/visualization/core/coord_mapper.py,sha256=WOP8ZQ2uQOU8cfuh4-4toJ1w6CxjwvXVjFxegUVvKjk,2609
|
57
|
+
trianglengin/visualization/core/fonts.py,sha256=VYYu2AZDTBwV1Os7yxWo5HAxTrwSW5CH7O2_D1ofXfY,1675
|
58
|
+
trianglengin/visualization/core/layout.py,sha256=-MBk29mnIawQe_qj-cjhoKRY6lAv18Heic5cIc8lpQY,3365
|
59
|
+
trianglengin/visualization/core/visualizer.py,sha256=ecyF2tTmXaCsNOTUh47B9W3PUVrm2R3FJmgJg6bV8bQ,8248
|
60
|
+
trianglengin/visualization/drawing/README.md,sha256=YmbxOKrf8iIiKX1UXtuyp7mdpqMaC77OljKOro3zorg,2694
|
61
|
+
trianglengin/visualization/drawing/__init__.py,sha256=O05AHItrGFSIQj3tEn4X9ZtKc1lXpMxrOuH2CA-dgQk,840
|
62
|
+
trianglengin/visualization/drawing/grid.py,sha256=1l7uH9KFqsA2WSjQSvpj_cGDpXHBXaz503xLFjOs8m4,5199
|
63
|
+
trianglengin/visualization/drawing/highlight.py,sha256=pK4tN-P6x7Woe23SwvWT0bxyXI8ec2AIMrfE1YsAOG8,762
|
64
|
+
trianglengin/visualization/drawing/hud.py,sha256=6rAudUnWcyd_mH5snd1bWxmCBXN7IRpajNjeO8a6JgY,1114
|
65
|
+
trianglengin/visualization/drawing/previews.py,sha256=3EoFuGDrH3KyC1AGL3JGzafu_zWayI4voptkA7e74Vo,5754
|
66
|
+
trianglengin/visualization/drawing/shapes.py,sha256=4oYtP3lCmHKJ0IJGG3iYlMjAshBasPMyR-YHkTKG1V8,982
|
67
|
+
trianglengin-1.0.6.dist-info/licenses/LICENSE,sha256=So3rgoJp-HgoxkclxZLIBC3pmmTwshN4tUO8KiQ6akc,1077
|
68
|
+
trianglengin-1.0.6.dist-info/METADATA,sha256=BFCK7UGXIxw_xBjqB3dNdzbfnb_1x7Yi1YklO_UL0JY,21967
|
69
|
+
trianglengin-1.0.6.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
|
70
|
+
trianglengin-1.0.6.dist-info/entry_points.txt,sha256=Rz6Rovq4J5i6JyoWy4erUoTF3hoE4llpR3Jw5meqP7w,54
|
71
|
+
trianglengin-1.0.6.dist-info/top_level.txt,sha256=Kk0sX2_amNO42W7_nFllW6_A_dq5D_XlgV_y0IeuoBE,19
|
72
|
+
trianglengin-1.0.6.dist-info/RECORD,,
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Copyright (c) 2025 Luis Guilherme P. M.
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|