init python lib generation with pyo3
This commit is contained in:
parent
59c80c66e4
commit
1c87771f25
6 changed files with 192 additions and 1 deletions
|
|
@ -5,11 +5,18 @@ edition = "2021"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
name = "trictrac"
|
||||
# "cdylib" is necessary to produce a shared library for Python to import from.
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.21.7"
|
||||
# provides macros for creating log messages to be used by a logger (for example env_logger)
|
||||
log = "0.4.20"
|
||||
merge = "0.1.0"
|
||||
# generate python lib to be used in AI training
|
||||
pyo3 = { version = "0.23", features = ["extension-module", "abi3-py38"] }
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
transpose = "0.2.2"
|
||||
|
|
|
|||
10
store/pyproject.toml
Normal file
10
store/pyproject.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
[build-system]
|
||||
requires = ["maturin>=1.0,<2.0"]
|
||||
build-backend = "maturin"
|
||||
|
||||
[tool.maturin]
|
||||
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so)
|
||||
features = ["pyo3/extension-module"]
|
||||
# python-source = "python"
|
||||
# module-name = "trictrac.game"
|
||||
|
|
@ -16,3 +16,48 @@ pub use board::CheckerMove;
|
|||
|
||||
mod dice;
|
||||
pub use dice::{Dice, DiceRoller};
|
||||
|
||||
// python interface (for AI training..)
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyTuple;
|
||||
|
||||
#[pyclass]
|
||||
struct TricTrac {
|
||||
// Stocke l'état du jeu ici
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl TricTrac {
|
||||
#[new]
|
||||
fn new() -> Self {
|
||||
TricTrac {
|
||||
// Initialise l'état du jeu
|
||||
}
|
||||
}
|
||||
|
||||
fn get_available_moves(&self) -> Vec<(i32, i32)> {
|
||||
// Retourne la liste des coups disponibles (exemple)
|
||||
vec![(0, 5), (3, 8)]
|
||||
}
|
||||
|
||||
fn play_move(&mut self, from_pos: i32, to_pos: i32) -> bool {
|
||||
// Implémente la logique du jeu et renvoie `true` si le coup est valide
|
||||
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(())
|
||||
}
|
||||
|
||||
// #[pymodule]
|
||||
// fn trictrac(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
// m.add_class::<TricTrac>()?;
|
||||
// Ok(())
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue