Skip to main content

Environment

Trait Environment 

Source
pub trait Environment: Send + Sync {
    // Required methods
    fn step(&self, worker_id: WorkerId, action: &Action) -> WorkResult;
    fn reset(&self);
    fn name(&self) -> &str;
}
Expand description

アクション実行環境トレイト

すべてのアクション実行はこのトレイトを通じて行われる。 DefaultEnvironment(Bash/Read等)やカスタム環境(Maze等)を 同じインターフェースで扱える。

§設計原則

  • step() がすべてのアクションを処理する唯一のメソッド
  • WorkResult::Done で終了を通知
  • 観察(Look等)も Action として step() 経由で実行

§内部可変性

step メソッドは &self を受け取るため、内部状態を変更する必要がある 環境(MazeEnvironment など)は MutexRwLock を使用すること。

Required Methods§

Source

fn step(&self, worker_id: WorkerId, action: &Action) -> WorkResult

アクション実行

すべてのアクション(移動、観察、待機等)をこのメソッドで処理する。

§Arguments
  • worker_id - 実行する Worker の ID
  • action - 実行するアクション
§Returns

WorkResult - 実行結果を直接返す

  • WorkResult::Acted - 通常のアクション結果
  • WorkResult::Done - タスク完了
  • WorkResult::env_success() / WorkResult::env_failure() 等のヘルパーを使用
§Example
// 移動アクション
let action = Action::new("Move").with_arg("target", "north");
let result = env.step(worker_id, &action);

// 観察アクション
let action = Action::new("Look");
let result = env.step(worker_id, &action);
// ActionResult.output に JSON データ
Source

fn reset(&self)

環境をリセット

評価システムが複数回実行する際に使用。

Source

fn name(&self) -> &str

環境名

Implementors§