This commit is contained in:
2025-11-06 10:21:29 -08:00
parent 5bd6331ad9
commit 48a45b5447
9 changed files with 115 additions and 75 deletions

View File

@@ -80,7 +80,6 @@ pub struct RhaiAgent<R: Rng + 'static> {
engine: Engine,
script: AST,
scope: Scope<'static>,
print_callback: Arc<dyn Fn(&str) + 'static>,
}
@@ -118,7 +117,6 @@ impl<R: Rng + 'static> RhaiAgent<R> {
// Do not use FULL, rand_* functions are not pure
engine.set_optimization_level(OptimizationLevel::Simple);
engine.disable_symbol("eval");
engine.set_max_expr_depths(100, 100);
engine.set_max_strings_interned(1024);
@@ -201,13 +199,11 @@ impl<R: Rng + 'static> RhaiAgent<R> {
};
let script = engine.compile(script)?;
let scope = Scope::new(); // Not used
Ok(Self {
rng,
engine,
script,
scope,
print_callback,
})
}
@@ -227,7 +223,7 @@ impl<R: Rng + 'static> Agent for RhaiAgent<R> {
fn step_min(&mut self, board: &Board) -> Result<PlayerAction, Self::ErrorType> {
let res = self.engine.call_fn_with_options::<PlayerAction>(
CallFnOptions::new().eval_ast(false),
&mut self.scope,
&mut Scope::new(),
&self.script,
"step_min",
(board.clone(),),
@@ -242,7 +238,7 @@ impl<R: Rng + 'static> Agent for RhaiAgent<R> {
fn step_max(&mut self, board: &Board) -> Result<PlayerAction, Self::ErrorType> {
let res = self.engine.call_fn_with_options::<PlayerAction>(
CallFnOptions::new().eval_ast(false),
&mut self.scope,
&mut Scope::new(),
&self.script,
"step_max",
(board.clone(),),