init python lib generation with pyo3
This commit is contained in:
parent
59c80c66e4
commit
883d799edb
8 changed files with 201 additions and 6 deletions
42
store/src/engine.rs
Normal file
42
store/src/engine.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//! # Expose trictrac game state and rules in a python module
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyTuple;
|
||||
|
||||
#[pyclass]
|
||||
struct TricTrac {
|
||||
state: String, // Remplace par ta structure d'état du jeu
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl TricTrac {
|
||||
#[new]
|
||||
fn new() -> Self {
|
||||
TricTrac {
|
||||
state: "Initial state".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_state(&self) -> String {
|
||||
self.state.clone()
|
||||
}
|
||||
|
||||
fn get_available_moves(&self) -> Vec<(i32, i32)> {
|
||||
vec![(0, 5), (3, 8)] // Remplace par ta logique de génération de coups
|
||||
}
|
||||
|
||||
fn play_move(&mut self, from_pos: i32, to_pos: i32) -> bool {
|
||||
// Ajoute la logique du jeu ici
|
||||
println!("Move... from {} to {}", from_pos, to_pos);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// A Python module implemented in Rust. The name of this function must match
|
||||
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
|
||||
/// import the module.
|
||||
#[pymodule]
|
||||
fn trictrac(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<TricTrac>()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -16,3 +16,6 @@ pub use board::CheckerMove;
|
|||
|
||||
mod dice;
|
||||
pub use dice::{Dice, DiceRoller};
|
||||
|
||||
// python interface "trictrac_engine" (for AI training..)
|
||||
mod engine;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue