-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
350 additions
and
214 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use super::*; | ||
use crate::prelude::*; | ||
use beet::prelude::*; | ||
use bevy::prelude::*; | ||
use std::time::Duration; | ||
|
||
pub fn frozen_lake_run(mut commands: Commands) { | ||
let map = FrozenLakeMap::default_four_by_four(); | ||
let grid_to_world = | ||
GridToWorld::from_frozen_lake_map(&map, FROZEN_LAKE_SCENE_SCALE); | ||
|
||
// agent | ||
let agent_grid_pos = map.agent_position(); | ||
let agent_pos = grid_to_world.world_pos(*agent_grid_pos); | ||
let object_scale = Vec3::splat(grid_to_world.cell_width * 0.5); | ||
|
||
commands | ||
.spawn(( | ||
Name::new("Inference Agent"), | ||
BundlePlaceholder::Scene(frozen_lake_assets::CHARACTER.into()), | ||
Transform::from_translation(agent_pos).with_scale(object_scale), | ||
grid_to_world.clone(), | ||
agent_grid_pos, | ||
GridDirection::sample(), | ||
)) | ||
.with_children(|parent| { | ||
let agent = parent.parent_entity(); | ||
|
||
parent | ||
.spawn(( | ||
Name::new("Inference Behavior"), | ||
// Running, | ||
InsertOnTrigger::<AppReady,Running>::default(), | ||
SequenceSelector, | ||
Repeat::default(), | ||
)) | ||
.with_children(|parent| { | ||
parent.spawn(( | ||
Name::new("Get next action"), | ||
TargetAgent(agent), | ||
AssetLoadBlockAppReady, | ||
AssetPlaceholder::<FrozenLakeQTable>::new( | ||
"ml/frozen_lake_qtable.ron", | ||
), | ||
ReadQPolicy::<FrozenLakeQTable>::default(), | ||
)); | ||
parent.spawn(( | ||
Name::new("Perform action"), | ||
TranslateGrid::new(Duration::from_secs(1)), | ||
TargetAgent(agent), | ||
RunTimer::default(), | ||
)); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::prelude::*; | ||
use beet::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
|
||
pub const FROZEN_LAKE_SCENE_SCALE: f32 = 1.; | ||
|
||
|
||
pub fn frozen_lake_scene(mut commands: Commands) { | ||
commands.spawn(( | ||
CameraDistance::new(FROZEN_LAKE_SCENE_SCALE * 0.7), | ||
BundlePlaceholder::Camera3d, | ||
)); | ||
|
||
let map = FrozenLakeMap::default_four_by_four(); | ||
let grid_to_world = | ||
GridToWorld::from_frozen_lake_map(&map, FROZEN_LAKE_SCENE_SCALE); | ||
|
||
let tile_scale = Vec3::splat(grid_to_world.cell_width); | ||
for x in 0..map.num_cols() { | ||
for y in 0..map.num_rows() { | ||
let mut pos = grid_to_world.world_pos(UVec2::new(x, y)); | ||
pos.y -= grid_to_world.cell_width; | ||
commands.spawn(( | ||
Transform::from_translation(pos).with_scale(tile_scale), | ||
BundlePlaceholder::Scene(frozen_lake_assets::TILE.into()), | ||
)); | ||
} | ||
} | ||
|
||
let object_scale = Vec3::splat(grid_to_world.cell_width * 0.5); | ||
|
||
for (index, cell) in map.cells().iter().enumerate() { | ||
let grid_pos = map.index_to_position(index); | ||
let mut pos = grid_to_world.world_pos(grid_pos); | ||
match cell { | ||
FrozenLakeCell::Hole => { | ||
pos.y += grid_to_world.cell_width * 0.25; // this asset is a bit too low | ||
commands.spawn(( | ||
Transform::from_translation(pos).with_scale(object_scale), | ||
BundlePlaceholder::Scene(frozen_lake_assets::HAZARD.into()), | ||
)); | ||
} | ||
FrozenLakeCell::Goal => { | ||
commands.spawn(( | ||
BundlePlaceholder::Scene(frozen_lake_assets::GOAL.into()), | ||
Transform::from_translation(pos).with_scale(object_scale), | ||
)); | ||
} | ||
FrozenLakeCell::Ice => { /* already spawned on the grid */ } | ||
FrozenLakeCell::Agent => { /*spawns on episode */ } | ||
} | ||
{} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use beet::prelude::*; | ||
use bevy::prelude::*; | ||
use super::*; | ||
|
||
pub fn frozen_lake_train(mut commands: Commands) { | ||
|
||
let map = FrozenLakeMap::default_four_by_four(); | ||
let params = FrozenLakeEpParams { | ||
learn_params: default(), | ||
grid_to_world: GridToWorld::from_frozen_lake_map(&map, FROZEN_LAKE_SCENE_SCALE), | ||
map, | ||
}; | ||
commands.spawn((RlSession::new(params), FrozenLakeQTable::default())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.