Compare commits
4 commits
20b5920718
...
1271672341
| Author | SHA1 | Date | |
|---|---|---|---|
| 1271672341 | |||
| 39fd807339 | |||
| 13ec2009a5 | |||
| 8be1071291 |
30 changed files with 1606 additions and 2178 deletions
44
.beads/.gitignore
vendored
Normal file
44
.beads/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
# SQLite databases
|
||||||
|
*.db
|
||||||
|
*.db?*
|
||||||
|
*.db-journal
|
||||||
|
*.db-wal
|
||||||
|
*.db-shm
|
||||||
|
|
||||||
|
# Daemon runtime files
|
||||||
|
daemon.lock
|
||||||
|
daemon.log
|
||||||
|
daemon.pid
|
||||||
|
bd.sock
|
||||||
|
sync-state.json
|
||||||
|
last-touched
|
||||||
|
|
||||||
|
# Local version tracking (prevents upgrade notification spam after git ops)
|
||||||
|
.local_version
|
||||||
|
|
||||||
|
# Legacy database files
|
||||||
|
db.sqlite
|
||||||
|
bd.db
|
||||||
|
|
||||||
|
# Worktree redirect file (contains relative path to main repo's .beads/)
|
||||||
|
# Must not be committed as paths would be wrong in other clones
|
||||||
|
redirect
|
||||||
|
|
||||||
|
# Merge artifacts (temporary files from 3-way merge)
|
||||||
|
beads.base.jsonl
|
||||||
|
beads.base.meta.json
|
||||||
|
beads.left.jsonl
|
||||||
|
beads.left.meta.json
|
||||||
|
beads.right.jsonl
|
||||||
|
beads.right.meta.json
|
||||||
|
|
||||||
|
# Sync state (local-only, per-machine)
|
||||||
|
# These files are machine-specific and should not be shared across clones
|
||||||
|
.sync.lock
|
||||||
|
sync_base.jsonl
|
||||||
|
|
||||||
|
# NOTE: Do NOT add negation patterns (e.g., !issues.jsonl) here.
|
||||||
|
# They would override fork protection in .git/info/exclude, allowing
|
||||||
|
# contributors to accidentally commit upstream issue databases.
|
||||||
|
# The JSONL files (issues.jsonl, interactions.jsonl) and config files
|
||||||
|
# are tracked by git by default since no pattern above ignores them.
|
||||||
81
.beads/README.md
Normal file
81
.beads/README.md
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
# Beads - AI-Native Issue Tracking
|
||||||
|
|
||||||
|
Welcome to Beads! This repository uses **Beads** for issue tracking - a modern, AI-native tool designed to live directly in your codebase alongside your code.
|
||||||
|
|
||||||
|
## What is Beads?
|
||||||
|
|
||||||
|
Beads is issue tracking that lives in your repo, making it perfect for AI coding agents and developers who want their issues close to their code. No web UI required - everything works through the CLI and integrates seamlessly with git.
|
||||||
|
|
||||||
|
**Learn more:** [github.com/steveyegge/beads](https://github.com/steveyegge/beads)
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Essential Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create new issues
|
||||||
|
bd create "Add user authentication"
|
||||||
|
|
||||||
|
# View all issues
|
||||||
|
bd list
|
||||||
|
|
||||||
|
# View issue details
|
||||||
|
bd show <issue-id>
|
||||||
|
|
||||||
|
# Update issue status
|
||||||
|
bd update <issue-id> --status in_progress
|
||||||
|
bd update <issue-id> --status done
|
||||||
|
|
||||||
|
# Sync with git remote
|
||||||
|
bd sync
|
||||||
|
```
|
||||||
|
|
||||||
|
### Working with Issues
|
||||||
|
|
||||||
|
Issues in Beads are:
|
||||||
|
- **Git-native**: Stored in `.beads/issues.jsonl` and synced like code
|
||||||
|
- **AI-friendly**: CLI-first design works perfectly with AI coding agents
|
||||||
|
- **Branch-aware**: Issues can follow your branch workflow
|
||||||
|
- **Always in sync**: Auto-syncs with your commits
|
||||||
|
|
||||||
|
## Why Beads?
|
||||||
|
|
||||||
|
✨ **AI-Native Design**
|
||||||
|
- Built specifically for AI-assisted development workflows
|
||||||
|
- CLI-first interface works seamlessly with AI coding agents
|
||||||
|
- No context switching to web UIs
|
||||||
|
|
||||||
|
🚀 **Developer Focused**
|
||||||
|
- Issues live in your repo, right next to your code
|
||||||
|
- Works offline, syncs when you push
|
||||||
|
- Fast, lightweight, and stays out of your way
|
||||||
|
|
||||||
|
🔧 **Git Integration**
|
||||||
|
- Automatic sync with git commits
|
||||||
|
- Branch-aware issue tracking
|
||||||
|
- Intelligent JSONL merge resolution
|
||||||
|
|
||||||
|
## Get Started with Beads
|
||||||
|
|
||||||
|
Try Beads in your own projects:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Beads
|
||||||
|
curl -sSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash
|
||||||
|
|
||||||
|
# Initialize in your repo
|
||||||
|
bd init
|
||||||
|
|
||||||
|
# Create your first issue
|
||||||
|
bd create "Try out Beads"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
- **Documentation**: [github.com/steveyegge/beads/docs](https://github.com/steveyegge/beads/tree/main/docs)
|
||||||
|
- **Quick Start Guide**: Run `bd quickstart`
|
||||||
|
- **Examples**: [github.com/steveyegge/beads/examples](https://github.com/steveyegge/beads/tree/main/examples)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Beads: Issue tracking that moves at the speed of thought* ⚡
|
||||||
62
.beads/config.yaml
Normal file
62
.beads/config.yaml
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
# Beads Configuration File
|
||||||
|
# This file configures default behavior for all bd commands in this repository
|
||||||
|
# All settings can also be set via environment variables (BD_* prefix)
|
||||||
|
# or overridden with command-line flags
|
||||||
|
|
||||||
|
# Issue prefix for this repository (used by bd init)
|
||||||
|
# If not set, bd init will auto-detect from directory name
|
||||||
|
# Example: issue-prefix: "myproject" creates issues like "myproject-1", "myproject-2", etc.
|
||||||
|
# issue-prefix: ""
|
||||||
|
|
||||||
|
# Use no-db mode: load from JSONL, no SQLite, write back after each command
|
||||||
|
# When true, bd will use .beads/issues.jsonl as the source of truth
|
||||||
|
# instead of SQLite database
|
||||||
|
# no-db: false
|
||||||
|
|
||||||
|
# Disable daemon for RPC communication (forces direct database access)
|
||||||
|
# no-daemon: false
|
||||||
|
|
||||||
|
# Disable auto-flush of database to JSONL after mutations
|
||||||
|
# no-auto-flush: false
|
||||||
|
|
||||||
|
# Disable auto-import from JSONL when it's newer than database
|
||||||
|
# no-auto-import: false
|
||||||
|
|
||||||
|
# Enable JSON output by default
|
||||||
|
# json: false
|
||||||
|
|
||||||
|
# Default actor for audit trails (overridden by BD_ACTOR or --actor)
|
||||||
|
# actor: ""
|
||||||
|
|
||||||
|
# Path to database (overridden by BEADS_DB or --db)
|
||||||
|
# db: ""
|
||||||
|
|
||||||
|
# Auto-start daemon if not running (can also use BEADS_AUTO_START_DAEMON)
|
||||||
|
# auto-start-daemon: true
|
||||||
|
|
||||||
|
# Debounce interval for auto-flush (can also use BEADS_FLUSH_DEBOUNCE)
|
||||||
|
# flush-debounce: "5s"
|
||||||
|
|
||||||
|
# Git branch for beads commits (bd sync will commit to this branch)
|
||||||
|
# IMPORTANT: Set this for team projects so all clones use the same sync branch.
|
||||||
|
# This setting persists across clones (unlike database config which is gitignored).
|
||||||
|
# Can also use BEADS_SYNC_BRANCH env var for local override.
|
||||||
|
# If not set, bd sync will require you to run 'bd config set sync.branch <branch>'.
|
||||||
|
sync-branch: "beads-sync"
|
||||||
|
|
||||||
|
# Multi-repo configuration (experimental - bd-307)
|
||||||
|
# Allows hydrating from multiple repositories and routing writes to the correct JSONL
|
||||||
|
# repos:
|
||||||
|
# primary: "." # Primary repo (where this database lives)
|
||||||
|
# additional: # Additional repos to hydrate from (read-only)
|
||||||
|
# - ~/beads-planning # Personal planning repo
|
||||||
|
# - ~/work-planning # Work planning repo
|
||||||
|
|
||||||
|
# Integration settings (access with 'bd config get/set')
|
||||||
|
# These are stored in the database, not in this file:
|
||||||
|
# - jira.url
|
||||||
|
# - jira.project
|
||||||
|
# - linear.url
|
||||||
|
# - linear.api-key
|
||||||
|
# - github.org
|
||||||
|
# - github.repo
|
||||||
0
.beads/interactions.jsonl
Normal file
0
.beads/interactions.jsonl
Normal file
1
.beads/issues.jsonl
Normal file
1
.beads/issues.jsonl
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"id":"trictrac-wxm","title":"Make a python library to use in Open Spiel","description":"A python tritrac game definition for Open Spiel, without implementation, is in the project located at doc/refs/open_spiel/open_spiel/python/games/trictrac.py (doc/refs/open_spiel is a symbolic link).\n\nI want to use PYO3, like in the `store/src/pyengine.rs` file, to expose the structures and methods needed to implement the functions of the `open_spiel` `trictrac.py` game file.\n\nEstablish an action plan and create sub-tasks of this issue for each step.\n","status":"closed","priority":2,"issue_type":"task","owner":"henri.bourcereau@gmail.com","created_at":"2026-01-18T19:24:00.323375444+01:00","created_by":"Henri Bourcereau","updated_at":"2026-01-18T20:03:17.168210389+01:00","closed_at":"2026-01-18T20:03:17.168210389+01:00","close_reason":"Closed"}
|
||||||
4
.beads/metadata.json
Normal file
4
.beads/metadata.json
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"database": "beads.db",
|
||||||
|
"jsonl_export": "issues.jsonl"
|
||||||
|
}
|
||||||
3
.gitattributes
vendored
Normal file
3
.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
|
||||||
|
# Use bd merge for beads JSONL files
|
||||||
|
.beads/issues.jsonl merge=beads
|
||||||
3306
Cargo.lock
generated
3306
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "trictrac-bot"
|
name = "bot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
@ -13,10 +13,10 @@ path = "src/burnrl/main.rs"
|
||||||
pretty_assertions = "1.4.0"
|
pretty_assertions = "1.4.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
trictrac-store = { path = "../store" }
|
store = { path = "../store" }
|
||||||
rand = "0.9"
|
rand = "0.8"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
burn = { version = "0.20", features = ["ndarray", "autodiff"] }
|
burn = { version = "0.18", features = ["ndarray", "autodiff"] }
|
||||||
burn-rl = { git = "https://github.com/yunjhongwu/burn-rl-examples.git", package = "burn-rl" }
|
burn-rl = { git = "https://github.com/yunjhongwu/burn-rl-examples.git", package = "burn-rl" }
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
confy = "1.0.0"
|
confy = "1.0.0"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import trictrac_store
|
import store
|
||||||
|
|
||||||
game = trictrac_store.TricTrac()
|
game = store.TricTrac()
|
||||||
print(game.get_active_player_id())
|
print(game.get_state_dict())
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ use std::io::Write;
|
||||||
use crate::training_common;
|
use crate::training_common;
|
||||||
use burn::{prelude::Backend, tensor::Tensor};
|
use burn::{prelude::Backend, tensor::Tensor};
|
||||||
use burn_rl::base::{Action, Environment, Snapshot, State};
|
use burn_rl::base::{Action, Environment, Snapshot, State};
|
||||||
use rand::{rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use trictrac_store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||||
|
|
||||||
const ERROR_REWARD: f32 = -1.0012121;
|
const ERROR_REWARD: f32 = -1.0012121;
|
||||||
const REWARD_VALID_MOVE: f32 = 1.0012121;
|
const REWARD_VALID_MOVE: f32 = 1.0012121;
|
||||||
|
|
@ -52,10 +52,10 @@ pub struct TrictracAction {
|
||||||
|
|
||||||
impl Action for TrictracAction {
|
impl Action for TrictracAction {
|
||||||
fn random() -> Self {
|
fn random() -> Self {
|
||||||
use rand::{rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
TrictracAction {
|
TrictracAction {
|
||||||
index: rng.random_range(0..Self::size() as u32),
|
index: rng.gen_range(0..Self::size() as u32),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -288,11 +288,11 @@ impl TrictracEnvironment {
|
||||||
// reward += REWARD_VALID_MOVE;
|
// reward += REWARD_VALID_MOVE;
|
||||||
// Simuler le résultat des dés après un Roll
|
// Simuler le résultat des dés après un Roll
|
||||||
if matches!(action, TrictracAction::Roll) {
|
if matches!(action, TrictracAction::Roll) {
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
||||||
let dice_event = GameEvent::RollResult {
|
let dice_event = GameEvent::RollResult {
|
||||||
player_id: self.active_player_id,
|
player_id: self.active_player_id,
|
||||||
dice: trictrac_store::Dice {
|
dice: store::Dice {
|
||||||
values: dice_values,
|
values: dice_values,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -340,18 +340,18 @@ impl TrictracEnvironment {
|
||||||
|
|
||||||
// Exécuter l'action selon le turn_stage
|
// Exécuter l'action selon le turn_stage
|
||||||
let mut calculate_points = false;
|
let mut calculate_points = false;
|
||||||
let opponent_color = trictrac_store::Color::Black;
|
let opponent_color = store::Color::Black;
|
||||||
let event = match self.game.turn_stage {
|
let event = match self.game.turn_stage {
|
||||||
TurnStage::RollDice => GameEvent::Roll {
|
TurnStage::RollDice => GameEvent::Roll {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
},
|
},
|
||||||
TurnStage::RollWaiting => {
|
TurnStage::RollWaiting => {
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
||||||
calculate_points = true;
|
calculate_points = true;
|
||||||
GameEvent::RollResult {
|
GameEvent::RollResult {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
dice: trictrac_store::Dice {
|
dice: store::Dice {
|
||||||
values: dice_values,
|
values: dice_values,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -371,7 +371,7 @@ impl TrictracEnvironment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TurnStage::MarkAdvPoints => {
|
TurnStage::MarkAdvPoints => {
|
||||||
let opponent_color = trictrac_store::Color::Black;
|
let opponent_color = store::Color::Black;
|
||||||
let dice_roll_count = self
|
let dice_roll_count = self
|
||||||
.game
|
.game
|
||||||
.players
|
.players
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::training_common;
|
use crate::training_common;
|
||||||
use burn::{prelude::Backend, tensor::Tensor};
|
use burn::{prelude::Backend, tensor::Tensor};
|
||||||
use burn_rl::base::{Action, Environment, Snapshot, State};
|
use burn_rl::base::{Action, Environment, Snapshot, State};
|
||||||
use rand::{rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use trictrac_store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
use store::{GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||||
|
|
||||||
const ERROR_REWARD: f32 = -1.0012121;
|
const ERROR_REWARD: f32 = -1.0012121;
|
||||||
const REWARD_RATIO: f32 = 0.1;
|
const REWARD_RATIO: f32 = 0.1;
|
||||||
|
|
@ -48,10 +48,10 @@ pub struct TrictracAction {
|
||||||
|
|
||||||
impl Action for TrictracAction {
|
impl Action for TrictracAction {
|
||||||
fn random() -> Self {
|
fn random() -> Self {
|
||||||
use rand::{rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
TrictracAction {
|
TrictracAction {
|
||||||
index: rng.random_range(0..Self::size() as u32),
|
index: rng.gen_range(0..Self::size() as u32),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,11 +258,11 @@ impl TrictracEnvironment {
|
||||||
// reward += REWARD_VALID_MOVE;
|
// reward += REWARD_VALID_MOVE;
|
||||||
// Simuler le résultat des dés après un Roll
|
// Simuler le résultat des dés après un Roll
|
||||||
if matches!(action, TrictracAction::Roll) {
|
if matches!(action, TrictracAction::Roll) {
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
||||||
let dice_event = GameEvent::RollResult {
|
let dice_event = GameEvent::RollResult {
|
||||||
player_id: self.active_player_id,
|
player_id: self.active_player_id,
|
||||||
dice: trictrac_store::Dice {
|
dice: store::Dice {
|
||||||
values: dice_values,
|
values: dice_values,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -310,18 +310,18 @@ impl TrictracEnvironment {
|
||||||
|
|
||||||
// Exécuter l'action selon le turn_stage
|
// Exécuter l'action selon le turn_stage
|
||||||
let mut calculate_points = false;
|
let mut calculate_points = false;
|
||||||
let opponent_color = trictrac_store::Color::Black;
|
let opponent_color = store::Color::Black;
|
||||||
let event = match self.game.turn_stage {
|
let event = match self.game.turn_stage {
|
||||||
TurnStage::RollDice => GameEvent::Roll {
|
TurnStage::RollDice => GameEvent::Roll {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
},
|
},
|
||||||
TurnStage::RollWaiting => {
|
TurnStage::RollWaiting => {
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
let dice_values = (rng.random_range(1..=6), rng.random_range(1..=6));
|
let dice_values = (rng.gen_range(1..=6), rng.gen_range(1..=6));
|
||||||
calculate_points = true;
|
calculate_points = true;
|
||||||
GameEvent::RollResult {
|
GameEvent::RollResult {
|
||||||
player_id: self.opponent_id,
|
player_id: self.opponent_id,
|
||||||
dice: trictrac_store::Dice {
|
dice: store::Dice {
|
||||||
values: dice_values,
|
values: dice_values,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use trictrac_bot::burnrl::algos::{dqn, dqn_valid, ppo, ppo_valid, sac, sac_valid};
|
use bot::burnrl::algos::{dqn, dqn_valid, ppo, ppo_valid, sac, sac_valid};
|
||||||
use trictrac_bot::burnrl::environment::TrictracEnvironment;
|
use bot::burnrl::environment::TrictracEnvironment;
|
||||||
use trictrac_bot::burnrl::environment_valid::TrictracEnvironment as TrictracEnvironmentValid;
|
use bot::burnrl::environment_valid::TrictracEnvironment as TrictracEnvironmentValid;
|
||||||
use trictrac_bot::burnrl::utils::{demo_model, Config};
|
use bot::burnrl::utils::{demo_model, Config};
|
||||||
use burn::backend::{Autodiff, NdArray};
|
use burn::backend::{Autodiff, NdArray};
|
||||||
use burn_rl::base::ElemType;
|
use burn_rl::base::ElemType;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ pub mod training_common;
|
||||||
pub mod trictrac_board;
|
pub mod trictrac_board;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use trictrac_store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
use store::{CheckerMove, Color, GameEvent, GameState, PlayerId, PointsRules, Stage, TurnStage};
|
||||||
pub use strategy::default::DefaultStrategy;
|
pub use strategy::default::DefaultStrategy;
|
||||||
pub use strategy::dqnburn::DqnBurnStrategy;
|
pub use strategy::dqnburn::DqnBurnStrategy;
|
||||||
pub use strategy::erroneous_moves::ErroneousStrategy;
|
pub use strategy::erroneous_moves::ErroneousStrategy;
|
||||||
|
|
@ -144,7 +144,7 @@ impl Bot {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use trictrac_store::{Dice, Stage};
|
use store::{Dice, Stage};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new() {
|
fn test_new() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||||
use trictrac_store::MoveRules;
|
use store::MoveRules;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DefaultStrategy {
|
pub struct DefaultStrategy {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use burn_rl::base::{ElemType, Model, State};
|
||||||
|
|
||||||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||||
use log::info;
|
use log::info;
|
||||||
use trictrac_store::MoveRules;
|
use store::MoveRules;
|
||||||
|
|
||||||
use crate::burnrl::algos::dqn;
|
use crate::burnrl::algos::dqn;
|
||||||
use crate::burnrl::environment;
|
use crate::burnrl::environment;
|
||||||
|
|
@ -152,7 +152,7 @@ impl BotStrategy for DqnBurnStrategy {
|
||||||
to1 = if fto1 < 0 { 0 } else { fto1 as usize };
|
to1 = if fto1 < 0 { 0 } else { fto1 as usize };
|
||||||
}
|
}
|
||||||
|
|
||||||
let checker_move1 = trictrac_store::CheckerMove::new(from1, to1).unwrap_or_default();
|
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||||
|
|
||||||
let mut tmp_board = self.game.board.clone();
|
let mut tmp_board = self.game.board.clone();
|
||||||
let move_res = tmp_board.move_checker(&self.color, checker_move1);
|
let move_res = tmp_board.move_checker(&self.color, checker_move1);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
use crate::{BotStrategy, CheckerMove, Color, GameState, PlayerId};
|
||||||
use rand::{prelude::IndexedRandom, rng};
|
use store::MoveRules;
|
||||||
use trictrac_store::MoveRules;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RandomStrategy {
|
pub struct RandomStrategy {
|
||||||
|
|
@ -52,7 +51,8 @@ impl BotStrategy for RandomStrategy {
|
||||||
let rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
|
let rules = MoveRules::new(&self.color, &self.game.board, self.game.dice);
|
||||||
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
||||||
|
|
||||||
let mut rng = rng();
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
|
let mut rng = thread_rng();
|
||||||
let choosen_move = possible_moves
|
let choosen_move = possible_moves
|
||||||
.choose(&mut rng)
|
.choose(&mut rng)
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use trictrac_store::MoveRules;
|
use store::MoveRules;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StableBaselines3Strategy {
|
pub struct StableBaselines3Strategy {
|
||||||
|
|
@ -79,12 +79,12 @@ impl StableBaselines3Strategy {
|
||||||
|
|
||||||
// Convertir l'étape du tour en entier
|
// Convertir l'étape du tour en entier
|
||||||
let turn_stage = match self.game.turn_stage {
|
let turn_stage = match self.game.turn_stage {
|
||||||
trictrac_store::TurnStage::RollDice => 0,
|
store::TurnStage::RollDice => 0,
|
||||||
trictrac_store::TurnStage::RollWaiting => 1,
|
store::TurnStage::RollWaiting => 1,
|
||||||
trictrac_store::TurnStage::MarkPoints => 2,
|
store::TurnStage::MarkPoints => 2,
|
||||||
trictrac_store::TurnStage::HoldOrGoChoice => 3,
|
store::TurnStage::HoldOrGoChoice => 3,
|
||||||
trictrac_store::TurnStage::Move => 4,
|
store::TurnStage::Move => 4,
|
||||||
trictrac_store::TurnStage::MarkAdvPoints => 5,
|
store::TurnStage::MarkAdvPoints => 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Récupérer les points et trous des joueurs
|
// Récupérer les points et trous des joueurs
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::cmp::{max, min};
|
||||||
use std::fmt::{Debug, Display, Formatter};
|
use std::fmt::{Debug, Display, Formatter};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use trictrac_store::{CheckerMove, GameEvent, GameState};
|
use store::{CheckerMove, GameEvent, GameState};
|
||||||
|
|
||||||
// 1 (Roll) + 1 (Go) + 512 (mouvements possibles)
|
// 1 (Roll) + 1 (Go) + 512 (mouvements possibles)
|
||||||
// avec 512 = 2 (choix du dé) * 16 * 16 (choix de la dame 0-15 pour chaque from)
|
// avec 512 = 2 (choix du dé) * 16 * 16 (choix de la dame 0-15 pour chaque from)
|
||||||
|
|
@ -94,13 +94,13 @@ impl TrictracAction {
|
||||||
(state.dice.values.1, state.dice.values.0)
|
(state.dice.values.1, state.dice.values.0)
|
||||||
};
|
};
|
||||||
|
|
||||||
let color = &trictrac_store::Color::White;
|
let color = &store::Color::White;
|
||||||
let from1 = state
|
let from1 = state
|
||||||
.board
|
.board
|
||||||
.get_checker_field(color, *checker1 as u8)
|
.get_checker_field(color, *checker1 as u8)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
let mut to1 = from1 + dice1 as usize;
|
let mut to1 = from1 + dice1 as usize;
|
||||||
let checker_move1 = trictrac_store::CheckerMove::new(from1, to1).unwrap_or_default();
|
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||||
|
|
||||||
let mut tmp_board = state.board.clone();
|
let mut tmp_board = state.board.clone();
|
||||||
let move_result = tmp_board.move_checker(color, checker_move1);
|
let move_result = tmp_board.move_checker(color, checker_move1);
|
||||||
|
|
@ -120,8 +120,8 @@ impl TrictracAction {
|
||||||
to2 -= 1;
|
to2 -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let checker_move1 = trictrac_store::CheckerMove::new(from1, to1).unwrap_or_default();
|
let checker_move1 = store::CheckerMove::new(from1, to1).unwrap_or_default();
|
||||||
let checker_move2 = trictrac_store::CheckerMove::new(from2, to2).unwrap_or_default();
|
let checker_move2 = store::CheckerMove::new(from2, to2).unwrap_or_default();
|
||||||
|
|
||||||
Some(GameEvent::Move {
|
Some(GameEvent::Move {
|
||||||
player_id: state.active_player_id,
|
player_id: state.active_player_id,
|
||||||
|
|
@ -179,8 +179,8 @@ impl TrictracAction {
|
||||||
// from2,
|
// from2,
|
||||||
// } => {
|
// } => {
|
||||||
// // Effectuer un mouvement
|
// // Effectuer un mouvement
|
||||||
// let checker_move1 = trictrac_store::CheckerMove::new(move1.0, move1.1).unwrap_or_default();
|
// let checker_move1 = store::CheckerMove::new(move1.0, move1.1).unwrap_or_default();
|
||||||
// let checker_move2 = trictrac_store::CheckerMove::new(move2.0, move2.1).unwrap_or_default();
|
// let checker_move2 = store::CheckerMove::new(move2.0, move2.1).unwrap_or_default();
|
||||||
//
|
//
|
||||||
// Some(GameEvent::Move {
|
// Some(GameEvent::Move {
|
||||||
// player_id: self.agent_player_id,
|
// player_id: self.agent_player_id,
|
||||||
|
|
@ -193,7 +193,7 @@ impl TrictracAction {
|
||||||
|
|
||||||
/// Obtient les actions valides pour l'état de jeu actuel
|
/// Obtient les actions valides pour l'état de jeu actuel
|
||||||
pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
||||||
use trictrac_store::TurnStage;
|
use store::TurnStage;
|
||||||
|
|
||||||
let mut valid_actions = Vec::new();
|
let mut valid_actions = Vec::new();
|
||||||
|
|
||||||
|
|
@ -216,11 +216,11 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
||||||
valid_actions.push(TrictracAction::Go);
|
valid_actions.push(TrictracAction::Go);
|
||||||
|
|
||||||
// Ajoute aussi les mouvements possibles
|
// Ajoute aussi les mouvements possibles
|
||||||
let rules = trictrac_store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
let rules = store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
||||||
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
let possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
||||||
|
|
||||||
// Modififier checker_moves_to_trictrac_action si on doit gérer Black
|
// Modififier checker_moves_to_trictrac_action si on doit gérer Black
|
||||||
assert_eq!(color, trictrac_store::Color::White);
|
assert_eq!(color, store::Color::White);
|
||||||
for (move1, move2) in possible_moves {
|
for (move1, move2) in possible_moves {
|
||||||
valid_actions.push(checker_moves_to_trictrac_action(
|
valid_actions.push(checker_moves_to_trictrac_action(
|
||||||
&move1, &move2, &color, game_state,
|
&move1, &move2, &color, game_state,
|
||||||
|
|
@ -228,7 +228,7 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TurnStage::Move => {
|
TurnStage::Move => {
|
||||||
let rules = trictrac_store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
let rules = store::MoveRules::new(&color, &game_state.board, game_state.dice);
|
||||||
let mut possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
let mut possible_moves = rules.get_possible_moves_sequences(true, vec![]);
|
||||||
if possible_moves.is_empty() {
|
if possible_moves.is_empty() {
|
||||||
// Empty move
|
// Empty move
|
||||||
|
|
@ -236,7 +236,7 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modififier checker_moves_to_trictrac_action si on doit gérer Black
|
// Modififier checker_moves_to_trictrac_action si on doit gérer Black
|
||||||
assert_eq!(color, trictrac_store::Color::White);
|
assert_eq!(color, store::Color::White);
|
||||||
for (move1, move2) in possible_moves {
|
for (move1, move2) in possible_moves {
|
||||||
valid_actions.push(checker_moves_to_trictrac_action(
|
valid_actions.push(checker_moves_to_trictrac_action(
|
||||||
&move1, &move2, &color, game_state,
|
&move1, &move2, &color, game_state,
|
||||||
|
|
@ -256,7 +256,7 @@ pub fn get_valid_actions(game_state: &crate::GameState) -> Vec<TrictracAction> {
|
||||||
fn checker_moves_to_trictrac_action(
|
fn checker_moves_to_trictrac_action(
|
||||||
move1: &CheckerMove,
|
move1: &CheckerMove,
|
||||||
move2: &CheckerMove,
|
move2: &CheckerMove,
|
||||||
color: &trictrac_store::Color,
|
color: &store::Color,
|
||||||
state: &crate::GameState,
|
state: &crate::GameState,
|
||||||
) -> TrictracAction {
|
) -> TrictracAction {
|
||||||
let to1 = move1.get_to();
|
let to1 = move1.get_to();
|
||||||
|
|
@ -324,10 +324,10 @@ pub fn get_valid_action_indices(game_state: &crate::GameState) -> Vec<usize> {
|
||||||
|
|
||||||
/// Sélectionne une action valide aléatoire
|
/// Sélectionne une action valide aléatoire
|
||||||
pub fn sample_valid_action(game_state: &crate::GameState) -> Option<TrictracAction> {
|
pub fn sample_valid_action(game_state: &crate::GameState) -> Option<TrictracAction> {
|
||||||
use rand::{prelude::IndexedRandom, rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
|
|
||||||
let valid_actions = get_valid_actions(game_state);
|
let valid_actions = get_valid_actions(game_state);
|
||||||
let mut rng = rng();
|
let mut rng = thread_rng();
|
||||||
valid_actions.choose(&mut rng).cloned()
|
valid_actions.choose(&mut rng).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use internal_iterator::InternalIterator;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
use trictrac_store::Color;
|
use store::Color;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
pub struct TrictracBoard(crate::GameState);
|
pub struct TrictracBoard(crate::GameState);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "trictrac-client_cli"
|
name = "client_cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|
@ -11,8 +11,8 @@ bincode = "1.3.3"
|
||||||
pico-args = "0.5.0"
|
pico-args = "0.5.0"
|
||||||
pretty_assertions = "1.4.0"
|
pretty_assertions = "1.4.0"
|
||||||
renet = "0.0.13"
|
renet = "0.0.13"
|
||||||
trictrac-store = { path = "../store" }
|
store = { path = "../store" }
|
||||||
trictrac-bot = { path = "../bot" }
|
bot = { path = "../bot" }
|
||||||
itertools = "0.13.0"
|
itertools = "0.13.0"
|
||||||
env_logger = "0.11.6"
|
env_logger = "0.11.6"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use trictrac_bot::{
|
use bot::{
|
||||||
BotStrategy, DefaultStrategy, DqnBurnStrategy, ErroneousStrategy, RandomStrategy,
|
BotStrategy, DefaultStrategy, DqnBurnStrategy, ErroneousStrategy, RandomStrategy,
|
||||||
StableBaselines3Strategy,
|
StableBaselines3Strategy,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::game_runner::GameRunner;
|
use crate::game_runner::GameRunner;
|
||||||
use trictrac_store::{CheckerMove, GameEvent, GameState, Stage, TurnStage};
|
use store::{CheckerMove, GameEvent, GameState, Stage, TurnStage};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AppArgs {
|
pub struct AppArgs {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use trictrac_bot::{Bot, BotStrategy};
|
use bot::{Bot, BotStrategy};
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use trictrac_store::{CheckerMove, DiceRoller, GameEvent, GameState, PlayerId, TurnStage};
|
use store::{CheckerMove, DiceRoller, GameEvent, GameState, PlayerId, TurnStage};
|
||||||
|
|
||||||
// Application Game
|
// Application Game
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
|
|
@ -117,8 +117,8 @@ impl GameRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(winner) = self.state.determine_winner() {
|
if let Some(winner) = self.state.determine_winner() {
|
||||||
next_event = Some(trictrac_store::GameEvent::EndGame {
|
next_event = Some(store::GameEvent::EndGame {
|
||||||
reason: trictrac_store::EndGameReason::PlayerWon { winner },
|
reason: store::EndGameReason::PlayerWon { winner },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
30
devenv.lock
30
devenv.lock
|
|
@ -3,10 +3,10 @@
|
||||||
"devenv": {
|
"devenv": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "src/modules",
|
"dir": "src/modules",
|
||||||
"lastModified": 1770390537,
|
"lastModified": 1768056019,
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "devenv",
|
"repo": "devenv",
|
||||||
"rev": "d6f45cc00829254a9a6f8807c8fbfaf3efa7e629",
|
"rev": "9bfc4a64c3a798ed8fa6cee3a519a9eac5e73cb5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -40,10 +40,10 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1769939035,
|
"lastModified": 1767281941,
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "git-hooks.nix",
|
"repo": "git-hooks.nix",
|
||||||
"rev": "a8ca480175326551d6c4121498316261cbb5b260",
|
"rev": "f0927703b7b1c8d97511c4116eb9b4ec6645a0fa",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -74,40 +74,24 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1770136044,
|
"lastModified": 1767995494,
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "e576e3c9cf9bad747afcddd9e34f51d18c855b4e",
|
"rev": "45a1530683263666f42d1de4cdda328109d5a676",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-25.11",
|
"ref": "nixpkgs-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs-cmake3": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1758213207,
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "f4b140d5b253f5e2a1ff4e5506edbf8267724bde",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "f4b140d5b253f5e2a1ff4e5506edbf8267724bde",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"devenv": "devenv",
|
"devenv": "devenv",
|
||||||
"git-hooks": "git-hooks",
|
"git-hooks": "git-hooks",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"nixpkgs-cmake3": "nixpkgs-cmake3",
|
|
||||||
"pre-commit-hooks": [
|
"pre-commit-hooks": [
|
||||||
"git-hooks"
|
"git-hooks"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
{ inputs, pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
||||||
let
|
|
||||||
pkgs-cmake3 = import inputs.nixpkgs-cmake3 { system = pkgs.stdenv.system; };
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
|
|
||||||
# pour burn-rs
|
# pour burn-rs
|
||||||
pkgs.SDL2_gfx
|
pkgs.SDL2_gfx
|
||||||
# (compilation sdl2-sys)
|
# (compilation sdl2-sys)
|
||||||
pkgs-cmake3.cmake
|
pkgs.cmake
|
||||||
pkgs.libxcb
|
|
||||||
pkgs.libffi
|
pkgs.libffi
|
||||||
pkgs.wayland-scanner
|
pkgs.wayland-scanner
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
inputs:
|
inputs:
|
||||||
nixpkgs:
|
nixpkgs:
|
||||||
url: github:NixOS/nixpkgs/nixos-25.11
|
url: github:NixOS/nixpkgs/nixpkgs-unstable
|
||||||
nixpkgs-cmake3:
|
|
||||||
url: github:NixOS/nixpkgs/f4b140d5b253f5e2a1ff4e5506edbf8267724bde
|
|
||||||
|
|
@ -16,8 +16,8 @@ Pour vérifier l'accès à la lib : lancer le shell interactif `python`
|
||||||
```python
|
```python
|
||||||
Python 3.13.11 (main, Dec 5 2025, 16:06:33) [GCC 15.2.0] on linux
|
Python 3.13.11 (main, Dec 5 2025, 16:06:33) [GCC 15.2.0] on linux
|
||||||
Type "help", "copyright", "credits" or "license" for more information.
|
Type "help", "copyright", "credits" or "license" for more information.
|
||||||
>>> import trictrac_store
|
>>> import store
|
||||||
>>> game = trictrac_store.TricTrac()
|
>>> game = store.TricTrac()
|
||||||
>>> game.get_active_player_id()
|
>>> game.get_active_player_id()
|
||||||
1
|
1
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
[package]
|
[package]
|
||||||
name = "trictrac-store"
|
name = "store"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "trictrac_store"
|
name = "store"
|
||||||
# "cdylib" is necessary to produce a shared library for Python to import from.
|
# "cdylib" is necessary to produce a shared library for Python to import from.
|
||||||
# Only "rlib" is needed for other Rust crates to use this library
|
# Only "rlib" is needed for other Rust crates to use this library
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ build-backend = "maturin"
|
||||||
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
|
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
|
||||||
features = ["pyo3/extension-module"]
|
features = ["pyo3/extension-module"]
|
||||||
# python-source = "python"
|
# python-source = "python"
|
||||||
|
# module-name = "trictrac.game"
|
||||||
|
|
|
||||||
|
|
@ -36,52 +36,73 @@ impl TricTrac {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Obtenir l'état du jeu sous forme de dictionnaire
|
||||||
|
fn get_state_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
|
||||||
|
let dict = PyDict::new(py);
|
||||||
|
dict.set_item("stage", format!("{:?}", self.game_state.stage))?;
|
||||||
|
dict.set_item("turn_stage", format!("{:?}", self.game_state.turn_stage))?;
|
||||||
|
dict.set_item("active_player_id", self.game_state.active_player_id)?;
|
||||||
|
|
||||||
|
// Board
|
||||||
|
let board_list = self.game_state.board.to_vec(); // returns Vec<i8>
|
||||||
|
dict.set_item("board", board_list)?;
|
||||||
|
|
||||||
|
// Dice
|
||||||
|
dict.set_item("dice", (self.game_state.dice.values.0, self.game_state.dice.values.1))?;
|
||||||
|
|
||||||
|
// Players
|
||||||
|
let players_dict = PyDict::new(py);
|
||||||
|
for (id, player) in &self.game_state.players {
|
||||||
|
let p_dict = PyDict::new(py);
|
||||||
|
p_dict.set_item("color", format!("{:?}", player.color))?;
|
||||||
|
p_dict.set_item("holes", player.holes)?;
|
||||||
|
p_dict.set_item("points", player.points)?;
|
||||||
|
p_dict.set_item("can_bredouille", player.can_bredouille)?;
|
||||||
|
p_dict.set_item("dice_roll_count", player.dice_roll_count)?;
|
||||||
|
players_dict.set_item(id, p_dict)?;
|
||||||
|
}
|
||||||
|
dict.set_item("players", players_dict)?;
|
||||||
|
|
||||||
|
Ok(dict)
|
||||||
|
}
|
||||||
|
|
||||||
/// Lance les dés ou utilise la séquence prédéfinie
|
/// Lance les dés ou utilise la séquence prédéfinie
|
||||||
fn roll_dice(&mut self) -> PyResult<(u8, u8)> {
|
fn roll_dice(&mut self) -> PyResult<(u8, u8)> {
|
||||||
let player_id = self.game_state.active_player_id;
|
let player_id = self.game_state.active_player_id;
|
||||||
|
|
||||||
if self.game_state.turn_stage != TurnStage::RollDice {
|
if self.game_state.turn_stage != TurnStage::RollDice {
|
||||||
return Err(pyo3::exceptions::PyRuntimeError::new_err(
|
return Err(pyo3::exceptions::PyRuntimeError::new_err("Not in RollDice stage"));
|
||||||
"Not in RollDice stage",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.game_state.consume(&GameEvent::Roll { player_id });
|
self.game_state.consume(&GameEvent::Roll { player_id });
|
||||||
|
|
||||||
let dice = if self.current_dice_index < self.dice_roll_sequence.len() {
|
let dice = if self.current_dice_index < self.dice_roll_sequence.len() {
|
||||||
let vals = self.dice_roll_sequence[self.current_dice_index];
|
let vals = self.dice_roll_sequence[self.current_dice_index];
|
||||||
self.current_dice_index += 1;
|
self.current_dice_index += 1;
|
||||||
Dice { values: vals }
|
Dice { values: vals }
|
||||||
} else {
|
} else {
|
||||||
DiceRoller::default().roll()
|
DiceRoller::default().roll()
|
||||||
};
|
};
|
||||||
|
|
||||||
self.game_state
|
self.game_state.consume(&GameEvent::RollResult { player_id, dice });
|
||||||
.consume(&GameEvent::RollResult { player_id, dice });
|
|
||||||
|
|
||||||
Ok(dice.values)
|
Ok(dice.values)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applique un mouvement (deux déplacements de dames)
|
/// Applique un mouvement (deux déplacements de dames)
|
||||||
fn apply_move(&mut self, from1: usize, to1: usize, from2: usize, to2: usize) -> PyResult<()> {
|
fn apply_move(&mut self, from1: usize, to1: usize, from2: usize, to2: usize) -> PyResult<()> {
|
||||||
let player_id = self.game_state.active_player_id;
|
let player_id = self.game_state.active_player_id;
|
||||||
|
|
||||||
let m1 = CheckerMove::new(from1, to1)
|
let m1 = CheckerMove::new(from1, to1).map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
|
||||||
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
|
let m2 = CheckerMove::new(from2, to2).map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
|
||||||
let m2 = CheckerMove::new(from2, to2)
|
|
||||||
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e.to_string()))?;
|
|
||||||
|
|
||||||
let moves = (m1, m2);
|
let moves = (m1, m2);
|
||||||
|
|
||||||
if !self
|
if !self.game_state.validate(&GameEvent::Move { player_id, moves }) {
|
||||||
.game_state
|
return Err(pyo3::exceptions::PyValueError::new_err("Invalid move"));
|
||||||
.validate(&GameEvent::Move { player_id, moves })
|
|
||||||
{
|
|
||||||
return Err(pyo3::exceptions::PyValueError::new_err("Invalid move"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.game_state
|
self.game_state.consume(&GameEvent::Move { player_id, moves });
|
||||||
.consume(&GameEvent::Move { player_id, moves });
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,7 +223,7 @@ impl TricTrac {
|
||||||
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
|
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
|
||||||
/// import the module.
|
/// import the module.
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn trictrac_store(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
fn store(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||||
m.add_class::<TricTrac>()?;
|
m.add_class::<TricTrac>()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue