Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,50 +1,65 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: pytorch
|
| 3 |
+
tags:
|
| 4 |
+
- reinforcement-learning
|
| 5 |
+
- dqn
|
| 6 |
+
- onnx
|
| 7 |
+
- fruitbox
|
| 8 |
+
- gamesaien
|
| 9 |
+
- chrome-extension
|
| 10 |
+
- gymnasium
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# AlphaApple - FruitBox DQN
|
| 14 |
+
|
| 15 |
+
This model plays the FruitBox (Fruit Box) puzzle game hosted on Gamesaien. It predicts Q-values over all axis-aligned rectangles on a 10x17 board. A valid action is a rectangle whose cell sum is exactly 10; you must apply an action mask to filter invalid rectangles before selecting the best move.
|
| 16 |
+
|
| 17 |
+
## Model summary
|
| 18 |
+
- Architecture: CNN-based DQN
|
| 19 |
+
- Input: one-hot board (10 channels) with shape `[1, 10, 10, 17]`
|
| 20 |
+
- Output: Q-values for all rectangles (8415 actions)
|
| 21 |
+
- Training: curriculum + backward board generator to ensure solvable boards
|
| 22 |
+
|
| 23 |
+
## Files in this repo
|
| 24 |
+
- `model.pth`: PyTorch checkpoint dict with `policy_net`, `target_net`, `optimizer`
|
| 25 |
+
- `model.onnx`: Exported ONNX model for browser/runtime inference
|
| 26 |
+
|
| 27 |
+
## How to use (PyTorch)
|
| 28 |
+
```python
|
| 29 |
+
import torch
|
| 30 |
+
from src.models import FruitBoxDQN
|
| 31 |
+
|
| 32 |
+
rows, cols = 10, 17
|
| 33 |
+
n_actions = 55 * 153 # (rows*(rows+1)/2) * (cols*(cols+1)/2) = 8415
|
| 34 |
+
model = FruitBoxDQN(rows, cols, n_actions)
|
| 35 |
+
|
| 36 |
+
ckpt = torch.load("model.pth", map_location="cpu")
|
| 37 |
+
state = ckpt["policy_net"] if "policy_net" in ckpt else ckpt
|
| 38 |
+
model.load_state_dict(state)
|
| 39 |
+
model.eval()
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
## How to use (ONNX / browser)
|
| 43 |
+
```js
|
| 44 |
+
const session = await ort.InferenceSession.create("model.onnx");
|
| 45 |
+
// input: Float32Array with shape [1, 10, 10, 17]
|
| 46 |
+
const output = await session.run({ input });
|
| 47 |
+
// output.output.data: Q-values for 8415 rectangles
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
## Action masking (required)
|
| 51 |
+
You must mask invalid rectangles before selecting an action. A rectangle is valid if the sum of its cells equals 10. Without the mask, the model can pick illegal moves.
|
| 52 |
+
|
| 53 |
+
## Training details
|
| 54 |
+
- Environment: FruitBoxEnvImproved (10x17)
|
| 55 |
+
- Curriculum: target coverage ramps from 0.3 to 0.95
|
| 56 |
+
- Optimizer: Adam, gamma=0.99
|
| 57 |
+
- Episodes: 10k (Colab integrated script)
|
| 58 |
+
|
| 59 |
+
## Limitations
|
| 60 |
+
- Trained on generated boards; performance may vary on edge cases.
|
| 61 |
+
- Requires an accurate action mask and correct board extraction.
|
| 62 |
+
|
| 63 |
+
## Links
|
| 64 |
+
- Game: https://en.gamesaien.com/game/fruit_box/
|
| 65 |
+
- Project: https://github.com/kbsooo/AlphaApple
|