✨🧪💩➕➖ workspace, vanth, varo: Add varo
crate and Root
struct, update dependencies
- Replaced `bitcode` crate with `bincode` in workspace dependencies. - Added new crate `varo` for random optimization with `Varo` trait, `Distribution`, and `optimize` function. - Defined `Root` world struct placeholder in `vanth` crate. - Created `reference.rs` test module in `vanth` with custom components and events. - Added TODOs in `varo` for RNG implementation and `optimize` function.
This commit is contained in:
parent
a1cc9b6e04
commit
5614cfe95f
7 changed files with 120 additions and 5 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -1373,7 +1373,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"rand_chacha",
|
"rand_chacha",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1383,7 +1383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ppv-lite86",
|
"ppv-lite86",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1395,6 +1395,12 @@ dependencies = [
|
||||||
"getrandom 0.2.16",
|
"getrandom 0.2.16",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.13"
|
version = "0.5.13"
|
||||||
|
@ -1417,7 +1423,7 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"pkcs1",
|
"pkcs1",
|
||||||
"pkcs8",
|
"pkcs8",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
"signature",
|
"signature",
|
||||||
"spki",
|
"spki",
|
||||||
"subtle",
|
"subtle",
|
||||||
|
@ -1548,7 +1554,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2071,6 +2077,20 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "varo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"blake3",
|
||||||
|
"digest",
|
||||||
|
"rand_core 0.9.3",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tempfile",
|
||||||
|
"vanth",
|
||||||
|
"vanth_derive",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vcpkg"
|
name = "vcpkg"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
|
|
|
@ -10,7 +10,7 @@ edition = "2024"
|
||||||
clap = { version = "4.5.42", features = ["derive"] }
|
clap = { version = "4.5.42", features = ["derive"] }
|
||||||
bevy_app = "0.16.1"
|
bevy_app = "0.16.1"
|
||||||
bevy_ecs = "0.16.1"
|
bevy_ecs = "0.16.1"
|
||||||
bitcode = "0.6.6"
|
bincode = "2.0.1"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
digest = "0.10.7"
|
digest = "0.10.7"
|
||||||
|
@ -21,3 +21,4 @@ proc-macro2 = "1.0"
|
||||||
sqlx = "0.8.6"
|
sqlx = "0.8.6"
|
||||||
rusqlite = { version = "0.32.1", features = ["bundled"] }
|
rusqlite = { version = "0.32.1", features = ["bundled"] }
|
||||||
tempfile = "3.12.0"
|
tempfile = "3.12.0"
|
||||||
|
rand_core = "0.9.3"
|
||||||
|
|
|
@ -180,3 +180,8 @@ impl Plugin for VanthPlugin {
|
||||||
// fn run_reference_tasks(tasks: Query<(&ReferenceGetTask<>)>) {
|
// fn run_reference_tasks(tasks: Query<(&ReferenceGetTask<>)>) {
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/// A world which Vanth entities live in. Lifetimes `'v` of [`Vanth<'v>`] types are tied to the lifetime of the `Root`.
|
||||||
|
pub struct Root {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -4,3 +4,4 @@ use vanth::{Component, Node, Reference};
|
||||||
mod derive;
|
mod derive;
|
||||||
mod fs;
|
mod fs;
|
||||||
mod store;
|
mod store;
|
||||||
|
mod reference;
|
||||||
|
|
20
crates/vanth/tests/integration/reference.rs
Normal file
20
crates/vanth/tests/integration/reference.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use bevy_ecs::{component::Component, entity::Entity, event::{Event, EventWriter}, system::Query};
|
||||||
|
|
||||||
|
#[derive(Event)]
|
||||||
|
struct LevelUpEvent<T> {
|
||||||
|
inner: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct FooTask {
|
||||||
|
field: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn player_level_up(
|
||||||
|
mut ev_levelup: EventWriter<LevelUpEvent<i32>>,
|
||||||
|
query: Query<(Entity, &FooTask)>,
|
||||||
|
) {
|
||||||
|
for (entity, xp) in query.iter() {
|
||||||
|
ev_levelup.write(LevelUpEvent::<i32> { inner: 5 });
|
||||||
|
}
|
||||||
|
}
|
19
crates/varo/Cargo.toml
Normal file
19
crates/varo/Cargo.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[package]
|
||||||
|
name = "varo"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
digest.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
blake3.workspace = true
|
||||||
|
vanth = { path = "../vanth" }
|
||||||
|
vanth_derive = { path = "../vanth_derive" }
|
||||||
|
rand_core.workspace = true
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = { workspace = true }
|
49
crates/varo/src/lib.rs
Normal file
49
crates/varo/src/lib.rs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
use rand_core::SeedableRng;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use vanth_derive::Vanth;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, Vanth)]
|
||||||
|
pub struct Rng {
|
||||||
|
// TODO: RNG
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Rng {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Varo {
|
||||||
|
/// Produce a random
|
||||||
|
fn next(digest: &mut Rng) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, Vanth)]
|
||||||
|
pub struct Distribution {
|
||||||
|
/// 0th element is the mean, 1st is the variance etc.
|
||||||
|
pub moments: Vec<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Distribution {
|
||||||
|
pub fn sample(digest: &mut Rng) -> f32 {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, Vanth)]
|
||||||
|
pub struct Score {
|
||||||
|
value: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, Vanth)]
|
||||||
|
pub struct OptimizationResult {
|
||||||
|
/// List of pairs of evaluation score and Rng used to generate the value.
|
||||||
|
values: Vec<(Rng, f32)>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn optimize<T: Varo>(evaluator: impl Fn(T) -> Score, rng: &mut Rng, rounds: u32) -> OptimizationResult {
|
||||||
|
// TODO:
|
||||||
|
// `for i in 0..rounds`: create a clone of `rng` and feed it `i`.
|
||||||
|
// Call T::next() and pass it to the evaluator.
|
||||||
|
// Return a sorted list, highest scores first.
|
||||||
|
|
||||||
|
todo!()
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue