pyforgeai-engine 1.0.0__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.
- pyforgeai/AI_Controller.py +156 -0
- pyforgeai/AI_Factory.py +176 -0
- pyforgeai/Adapters/Mock_Adapter.py +31 -0
- pyforgeai/Adapters/PyTorch_Adapter.py +44 -0
- pyforgeai/Adapters/TensorFlow_Adapter.py +46 -0
- pyforgeai/Adapters/__init__.py +28 -0
- pyforgeai/Environments/Game_Bridge_Env.py +117 -0
- pyforgeai/Environments/Target_Seek_Env.py +69 -0
- pyforgeai/Environments/__init__.py +8 -0
- pyforgeai/Interfaces/IAIModel.py +60 -0
- pyforgeai/Interfaces/IEnvironment.py +48 -0
- pyforgeai/Interfaces/ITrainer.py +46 -0
- pyforgeai/Interfaces/__init__.py +12 -0
- pyforgeai/Models/Model_Builder.py +162 -0
- pyforgeai/Models/Neural_Network_Pytorch.py +72 -0
- pyforgeai/Models/Neural_Network_Tensorflow.py +91 -0
- pyforgeai/Models/__init__.py +28 -0
- pyforgeai/Serialization/Model_Serializer.py +307 -0
- pyforgeai/Serialization/__init__.py +21 -0
- pyforgeai/Trainers/Genetic_Algorithm.py +417 -0
- pyforgeai/Trainers/Q_Learning.py +413 -0
- pyforgeai/Trainers/Training_Callbacks.py +97 -0
- pyforgeai/Trainers/__init__.py +53 -0
- pyforgeai/__init__.py +109 -0
- pyforgeai_engine-1.0.0.dist-info/METADATA +200 -0
- pyforgeai_engine-1.0.0.dist-info/RECORD +29 -0
- pyforgeai_engine-1.0.0.dist-info/WHEEL +5 -0
- pyforgeai_engine-1.0.0.dist-info/licenses/LICENSE +21 -0
- pyforgeai_engine-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyforgeai-engine
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A modular, multi-backend game AI training and inference library featuring Neuroevolution (Genetic Algorithms) and Deep Q-Learning (DQN) for Pygame and Python simulations.
|
|
5
|
+
Author: Drakonosinc
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Drakonosinc/PyForgeAI
|
|
8
|
+
Project-URL: Repository, https://github.com/Drakonosinc/PyForgeAI
|
|
9
|
+
Project-URL: Documentation, https://deepwiki.com/Drakonosinc/PyForgeAI
|
|
10
|
+
Keywords: ai,gamedev,pygame,pytorch,tensorflow,reinforcement-learning,q-learning,dqn,genetic-algorithm,neuroevolution,neural-network
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Games/Entertainment
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=1.24.0
|
|
26
|
+
Requires-Dist: torch>=2.0.0
|
|
27
|
+
Provides-Extra: tensorflow
|
|
28
|
+
Requires-Dist: tensorflow>=2.12.0; extra == "tensorflow"
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# PyForgeAI
|
|
34
|
+
|
|
35
|
+
[](https://deepwiki.com/Drakonosinc/PyForgeAI)
|
|
36
|
+
[](https://www.python.org/)
|
|
37
|
+
[](https://pytorch.org/)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
|
|
40
|
+
**PyForgeAI** is a modular, multi-backend game AI training and inference library built for **Pygame** and real-time Python simulations. Designed around the `AIFactory`, `ITrainer`, and `IAIModel` patterns, it unifies **Neuroevolution (Genetic Algorithms)** and **Deep Q-Learning (Double-DQN)** into a clean, zero-boilerplate package with automatic HUD activation tracking and backward-compatible checkpoint serialization.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Unified Training Algorithms (`Trainers`)**:
|
|
47
|
+
- **`GeneticTrainer` (Neuroevolution)**: Elitism, multi-trial fitness averaging, uniform tensor crossover, **adaptive mutation scaling** on fitness stagnation, and periodic **random diversity injection**.
|
|
48
|
+
- **`QLearningTrainer` & `DQNAgent` (Deep Reinforcement Learning)**: Experience `ReplayMemory`, **Double-DQN** action evaluation, Huber/MSE loss, gradient clipping, and epsilon-greedy exploration decay.
|
|
49
|
+
- **Multi-Backend Neural Networks & Adapters (`Models` & `Adapters`)**:
|
|
50
|
+
- Dynamic multi-layer perceptrons (`SimpleNN_Pytorch` & `SimpleNN_Tensorflow`) with configurable `hidden_sizes` and activation functions (`relu`, `tanh`, `leaky_relu`, `elu`).
|
|
51
|
+
- Built-in normalized layer-1 activation capture (`model.activations` in `[0, 1]`) for real-time HUD neural network rendering, with a headless fast-mode toggle (`record_activations=False`).
|
|
52
|
+
- `PyTorchAdapter`, `TensorFlowAdapter`, and `MockAdapter` implementing the unified `IAIModel` contract (`predict`, `predict_action`, `predict_probabilities`, `get_weights`, `set_weights`).
|
|
53
|
+
- **Flexible Environment Integration (`Environments`)**:
|
|
54
|
+
- Works seamlessly with step-by-step Gym-like environments (`IEnvironment`), pure fitness callables (`fn(model) -> float`), or legacy Pygame loops (`game.run_with_model()` via `GameFitnessBridge`).
|
|
55
|
+
- **Smart Checkpoint Serialization (`Serialization`)**:
|
|
56
|
+
- Automatic architecture metadata persistence and legacy layer remapping (`fc1`/`fc2` $\rightarrow$ `hidden_layers.*`) via `save_model`, `load_model`, and configuration-driven `AILoader`.
|
|
57
|
+
- **Training Lifecycle Callbacks**:
|
|
58
|
+
- Built-in `EarlyStoppingCallback`, `CheckpointCallback`, and `HistoryCallback`.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Architecture
|
|
63
|
+
|
|
64
|
+
```mermaid
|
|
65
|
+
flowchart TD
|
|
66
|
+
Factory["AIFactory"] --> Models["Models (SimpleNN_Pytorch / SimpleNN_Tensorflow)"]
|
|
67
|
+
Factory --> Adapters["Adapters (PyTorchAdapter / TensorFlowAdapter / MockAdapter)"]
|
|
68
|
+
Factory --> Trainers["Trainers (GeneticTrainer / QLearningTrainer)"]
|
|
69
|
+
Factory --> Controller["AIController (Runtime Inference & Episodic DQN State)"]
|
|
70
|
+
|
|
71
|
+
Trainers --> Env["Environments (IEnvironment / IFitnessEnvironment / GameFitnessBridge)"]
|
|
72
|
+
Trainers --> Callbacks["Callbacks (EarlyStopping / Checkpoint / History)"]
|
|
73
|
+
Controller --> Adapters
|
|
74
|
+
Adapters --> Serializer["Serialization (save_model / load_model / AILoader)"]
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Installation
|
|
80
|
+
|
|
81
|
+
### From PyPI (once published)
|
|
82
|
+
```bash
|
|
83
|
+
pip install pyforgeai-engine
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Local Editable Install (for development or local game projects)
|
|
87
|
+
```bash
|
|
88
|
+
pip install -e .
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Optional TensorFlow backend support:
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e ".[tensorflow]"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Quickstart
|
|
99
|
+
|
|
100
|
+
### 1. Neuroevolution (`GeneticTrainer`)
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from pyforgeai import AIFactory, EarlyStoppingCallback, TargetSeekEnvironment, save_model
|
|
104
|
+
|
|
105
|
+
env = TargetSeekEnvironment(max_steps=80, seed=42)
|
|
106
|
+
|
|
107
|
+
factory = AIFactory({
|
|
108
|
+
"type_model": "Pytorch",
|
|
109
|
+
"input_size": env.state_size,
|
|
110
|
+
"output_size": env.action_size,
|
|
111
|
+
"hidden_sizes": [16, 16],
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
trainer = factory.create_GeneticTrainer(
|
|
115
|
+
generations=50,
|
|
116
|
+
population_size=20,
|
|
117
|
+
elitism=2,
|
|
118
|
+
num_trials=3,
|
|
119
|
+
adaptive_mutation=True,
|
|
120
|
+
diversity_interval=10,
|
|
121
|
+
callbacks=[EarlyStoppingCallback(patience=10)],
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
result = trainer.train_with_result(env)
|
|
125
|
+
save_model(result.best_model, "AI/best_genetic_model.pth")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 2. Deep Q-Learning (`QLearningTrainer` / `DQNAgent`)
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from pyforgeai import AIFactory, TargetSeekEnvironment
|
|
132
|
+
|
|
133
|
+
env = TargetSeekEnvironment(max_steps=80)
|
|
134
|
+
factory = AIFactory({
|
|
135
|
+
"input_size": env.state_size,
|
|
136
|
+
"output_size": env.action_size,
|
|
137
|
+
"hidden_sizes": [32, 32],
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
dqn_trainer = factory.create_QLearningTrainer(
|
|
141
|
+
episodes=200,
|
|
142
|
+
lr=1e-3,
|
|
143
|
+
gamma=0.99,
|
|
144
|
+
epsilon_start=1.0,
|
|
145
|
+
epsilon_end=0.02,
|
|
146
|
+
epsilon_decay=0.995,
|
|
147
|
+
double_dqn=True,
|
|
148
|
+
save_path="AI/best_dqn_model.pth",
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
result = dqn_trainer.train_environment_with_result(env)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 3. Runtime Inference in Pygame (`AIController`)
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from pyforgeai import AIController, load_model
|
|
158
|
+
|
|
159
|
+
model = load_model("AI/best_genetic_model.pth", "Pytorch")
|
|
160
|
+
|
|
161
|
+
controller = AIController(
|
|
162
|
+
state_provider=lambda: game.get_observation_array(),
|
|
163
|
+
action_dispatcher=lambda action_idx: game.apply_ai_action(action_idx),
|
|
164
|
+
)
|
|
165
|
+
controller.set_runtime_model(model)
|
|
166
|
+
|
|
167
|
+
# Inside your Pygame loop:
|
|
168
|
+
chosen_action = controller.select_action(deterministic=True)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Running the Showcase Demo & Unit Tests
|
|
174
|
+
|
|
175
|
+
Run the standalone training and inference showcase:
|
|
176
|
+
```bash
|
|
177
|
+
python demo_ai_training.py
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Run the automated test suite:
|
|
181
|
+
```bash
|
|
182
|
+
python -m unittest discover -s tests -v
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Build `.whl` and `.tar.gz` distributions for PyPI:
|
|
186
|
+
```bash
|
|
187
|
+
pip install build twine
|
|
188
|
+
python -m build
|
|
189
|
+
twine upload dist/*
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
This project is licensed under the [MIT License](LICENSE).
|
|
197
|
+
|
|
198
|
+
## Author
|
|
199
|
+
|
|
200
|
+
Developed by [Drakonosinc](https://github.com/Drakonosinc)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
pyforgeai/AI_Controller.py,sha256=rsURpGQkQ0pdX6C9ApKL6HViEDoLSx6YT5_m8IEJxT0,6124
|
|
2
|
+
pyforgeai/AI_Factory.py,sha256=iZ4Dv2riUf1NakSwgB2GT7ZfES7_y95C3Fu81AIcO28,8087
|
|
3
|
+
pyforgeai/__init__.py,sha256=dskbHnxxDdOqzPJ9rjFxKCwlot3oWDurKGk6P8MIFL0,2487
|
|
4
|
+
pyforgeai/Adapters/Mock_Adapter.py,sha256=Wxl_hJdVSeVaqy5mqPnLqwjiO4ueEvnOGtoEYqLydnw,1071
|
|
5
|
+
pyforgeai/Adapters/PyTorch_Adapter.py,sha256=xba_UPxZW4smvQFBV_6WgQ980yG7Ci-fORTzq3BBzkc,1654
|
|
6
|
+
pyforgeai/Adapters/TensorFlow_Adapter.py,sha256=vG7vdBqlOVK06ORw0zlaz7FufTFF4YjPAy5J45cvdAA,1610
|
|
7
|
+
pyforgeai/Adapters/__init__.py,sha256=_hwyUm8JU3CX30PGTnUxexdDR8cxo6tC0zj_HIjkzW4,805
|
|
8
|
+
pyforgeai/Environments/Game_Bridge_Env.py,sha256=FSh3c09G7_aKHbcDJ5ha5bKEFD0rwRXGfG7wtUFBTZE,4317
|
|
9
|
+
pyforgeai/Environments/Target_Seek_Env.py,sha256=mAdYg06zVKRPODTsDX71NDGiBGvOAY4oPoR135pJSPM,2402
|
|
10
|
+
pyforgeai/Environments/__init__.py,sha256=Q9mw74j4HimiUvtztS1cjjtGHqiZHmAE02e-lElZnBU,219
|
|
11
|
+
pyforgeai/Interfaces/IAIModel.py,sha256=3-FKVTrtt-ZcmHPLTqxGO3_9Vu7oW-WmWUJGFmNPngg,2534
|
|
12
|
+
pyforgeai/Interfaces/IEnvironment.py,sha256=UTzcAswx6ib_zpQ9lXX58jFHKi5FNoff56ufcJtoVwk,1507
|
|
13
|
+
pyforgeai/Interfaces/ITrainer.py,sha256=lb42X7ZZWL3RgMYgT9lAfzwnn5kBvkfAHf-5WBnQnJw,1342
|
|
14
|
+
pyforgeai/Interfaces/__init__.py,sha256=i2fsWbBjPtRDH6fyvra2Q85Zq9k1Ylk_uWwDPjUn_PQ,298
|
|
15
|
+
pyforgeai/Models/Model_Builder.py,sha256=-cXACwDbF99bVNJwqXHF9YIOiRuJDktVpZOPkRcWeXg,6160
|
|
16
|
+
pyforgeai/Models/Neural_Network_Pytorch.py,sha256=alnt46fpD9cXidF6hlGKozTBO3I3DzR3HZxVuSPMaOo,2582
|
|
17
|
+
pyforgeai/Models/Neural_Network_Tensorflow.py,sha256=reW-NLFpa8nXNvvAwWFK5jXUzJgB89UZeYkOTsVSL0Q,3345
|
|
18
|
+
pyforgeai/Models/__init__.py,sha256=XPUjlLQJiuFLus5YVCqGbMOpB1BHKMcgajURBlPv9Fo,613
|
|
19
|
+
pyforgeai/Serialization/Model_Serializer.py,sha256=8IYanCKXZ6zasNmbF9XOzmCOL4NABxLxdCMlto21YTc,12327
|
|
20
|
+
pyforgeai/Serialization/__init__.py,sha256=Pka8ZANIupmCOqHl2IbrXQX7Qs1sBsGKjB-j_YSO1ys,403
|
|
21
|
+
pyforgeai/Trainers/Genetic_Algorithm.py,sha256=DaNIpYBaYhB3y8FnV0-M7Z_fJa_ITIBTW-9qCyuKLsQ,15367
|
|
22
|
+
pyforgeai/Trainers/Q_Learning.py,sha256=h8I8dg4bWMnTQRTApGOU4j7_23kKtKmfiAI-PIXjaQQ,15480
|
|
23
|
+
pyforgeai/Trainers/Training_Callbacks.py,sha256=SCyuNJmvmnBiALlg2EunC-XSVo3reDDVLtvgfSBYGMY,2922
|
|
24
|
+
pyforgeai/Trainers/__init__.py,sha256=a4GQZ8qNYs4QM8rFBFGvMhg3XFkcsiSqHHITkrwjK3A,1142
|
|
25
|
+
pyforgeai_engine-1.0.0.dist-info/licenses/LICENSE,sha256=x8s2HRsd0gxpsrFqAlcb7IJQtmeHlejtdJCO181QbO4,1068
|
|
26
|
+
pyforgeai_engine-1.0.0.dist-info/METADATA,sha256=P-OT1oXKx8hubKQ6eddUcvJCi2xmGoiAJgDDl3EpdMk,7483
|
|
27
|
+
pyforgeai_engine-1.0.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
28
|
+
pyforgeai_engine-1.0.0.dist-info/top_level.txt,sha256=NtYFKFQwae_2QmIZvodyO8uATnWzmJGy4r_jRhz_7_I,10
|
|
29
|
+
pyforgeai_engine-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Drakonosinc
|
|
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 @@
|
|
|
1
|
+
pyforgeai
|