feat: TrictracBoard for kZero

This commit is contained in:
Henri Bourcereau 2025-09-01 14:47:09 +02:00
parent 4e299b04e2
commit e66d8b6624
5 changed files with 22 additions and 8 deletions

View file

@ -20,7 +20,7 @@ serde_json = "1.0"
store = { path = "../store" } store = { path = "../store" }
rand = "0.8" rand = "0.8"
env_logger = "0.10" env_logger = "0.10"
burn = { version = "0.17", 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"

View file

@ -4,6 +4,10 @@ use std::fmt::{Debug, Display, Formatter};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use store::{CheckerMove, GameEvent, GameState}; use store::{CheckerMove, GameEvent, GameState};
// 1 (Roll) + 1 (Go) + mouvements possibles
// Pour les mouvements : 2*16*16 = 514 (choix du dé + choix de la dame 0-15 pour chaque from)
pub const ACTION_SPACE_SIZE: usize = 514;
/// Types d'actions possibles dans le jeu /// Types d'actions possibles dans le jeu
#[derive(Debug, Copy, Clone, Eq, Serialize, Deserialize, PartialEq)] #[derive(Debug, Copy, Clone, Eq, Serialize, Deserialize, PartialEq)]
pub enum TrictracAction { pub enum TrictracAction {
@ -158,10 +162,7 @@ impl TrictracAction {
/// Retourne la taille de l'espace d'actions total /// Retourne la taille de l'espace d'actions total
pub fn action_space_size() -> usize { pub fn action_space_size() -> usize {
// 1 (Roll) + 1 (Go) + mouvements possibles ACTION_SPACE_SIZE
// Pour les mouvements : 2*25*25 = 1250 (choix du dé + position 0-24 pour chaque from)
// Mais on peut optimiser en limitant aux positions valides (1-24)
2 + (2 * 16 * 16) // = 514
} }
// pub fn to_game_event(&self, player_id: PlayerId, dice: Dice) -> GameEvent { // pub fn to_game_event(&self, player_id: PlayerId, dice: Dice) -> GameEvent {

View file

@ -6,10 +6,11 @@ use board_game::board::{
use board_game::impl_unit_symmetry_board; use board_game::impl_unit_symmetry_board;
use internal_iterator::InternalIterator; use internal_iterator::InternalIterator;
use std::fmt; use std::fmt;
use std::hash::Hash;
use std::ops::ControlFlow; use std::ops::ControlFlow;
use store::Color; use store::Color;
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct TrictracBoard(crate::GameState); pub struct TrictracBoard(crate::GameState);
impl Default for TrictracBoard { impl Default for TrictracBoard {
@ -78,6 +79,10 @@ impl BoardGameBoard for TrictracBoard {
} }
impl TrictracBoard { impl TrictracBoard {
pub fn inner(&self) -> &crate::GameState {
&self.0
}
pub fn to_fen(&self) -> String { pub fn to_fen(&self) -> String {
self.0.to_string_id() self.0.to_string_id()
} }

View file

@ -22,6 +22,7 @@ nombres aléatoires avec seed : <https://richard.dallaway.com/posts/2021-01-04-r
- rayon ( sync <-> parallel ) - rayon ( sync <-> parallel )
- front : yew + tauri - front : yew + tauri
- egui - egui
- <https://docs.rs/board-game/latest/board_game/> - <https://docs.rs/board-game/latest/board_game/>
@ -31,6 +32,7 @@ nombres aléatoires avec seed : <https://richard.dallaway.com/posts/2021-01-04-r
- <https://www.mattkeeter.com/projects/pont/> - <https://www.mattkeeter.com/projects/pont/>
- <https://github.com/jackadamson/onitama> (wasm, rooms) - <https://github.com/jackadamson/onitama> (wasm, rooms)
- <https://github.com/UkoeHB/renet2> - <https://github.com/UkoeHB/renet2>
- <https://github.com/UkoeHB/bevy_simplenet>
## Others ## Others

View file

@ -9,12 +9,13 @@ use log::{debug, error};
// use itertools::Itertools; // use itertools::Itertools;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::{fmt, str}; use std::{fmt, str};
use base64::{engine::general_purpose, Engine as _}; use base64::{engine::general_purpose, Engine as _};
/// The different stages a game can be in. (not to be confused with the entire "GameState") /// The different stages a game can be in. (not to be confused with the entire "GameState")
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Stage { pub enum Stage {
PreGame, PreGame,
InGame, InGame,
@ -22,7 +23,7 @@ pub enum Stage {
} }
/// The different stages a game turn can be in. /// The different stages a game turn can be in.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum TurnStage { pub enum TurnStage {
RollDice, RollDice,
RollWaiting, RollWaiting,
@ -114,6 +115,11 @@ impl Default for GameState {
} }
} }
} }
impl Hash for GameState {
fn hash<H: Hasher>(&self, state: &mut H) {
self.to_string_id().hash(state);
}
}
impl GameState { impl GameState {
/// Create a new default game /// Create a new default game