-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new environment: CollectGems (#37)
* add CollectGems environment * add gif for CollectGems environment * move Gem object definition to objects.jl
- Loading branch information
1 parent
cd69b41
commit b78a830
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,50 @@ | ||
export CollectGems | ||
|
||
mutable struct CollectGems <: AbstractGridWorld | ||
world::GridWorldBase{Tuple{Empty,Wall,Gem}} | ||
agent_pos::CartesianIndex{2} | ||
agent::Agent | ||
num_gem_init::Int | ||
num_gem_current::Int | ||
end | ||
|
||
function CollectGems(;n=8, agent_start_pos=CartesianIndex(2,2), agent_start_dir=RIGHT) | ||
objects = (EMPTY, WALL, GEM) | ||
w = GridWorldBase(objects, n, n) | ||
|
||
w[EMPTY, 2:n-1, 2:n-1] .= true | ||
w[WALL, [1,n], 1:n] .= true | ||
w[WALL, 1:n, [1,n]] .= true | ||
|
||
w[GEM, 1:n, 1:n] .= false | ||
num_gem_init = n - 1 | ||
num_gem_current = num_gem_init | ||
|
||
gem_placed = 0 | ||
while gem_placed < num_gem_init | ||
gem_pos = CartesianIndex(rand(2:n-1), rand(2:n-1)) | ||
if (gem_pos == agent_start_pos) || (w[GEM, gem_pos] == true) | ||
continue | ||
else | ||
w[GEM, gem_pos] = true | ||
w[EMPTY, gem_pos] = false | ||
gem_placed = gem_placed + 1 | ||
end | ||
end | ||
|
||
CollectGems(w, agent_start_pos, Agent(dir=agent_start_dir), num_gem_init, num_gem_current) | ||
end | ||
|
||
function (w::CollectGems)(::MoveForward) | ||
dir = get_dir(w.agent) | ||
dest = dir(w.agent_pos) | ||
if !w.world[WALL, dest] | ||
w.agent_pos = dest | ||
if w.world[GEM, dest] | ||
w.world[GEM, dest] = false | ||
w.world[EMPTY, dest] = true | ||
w.num_gem_current = w.num_gem_current - 1 | ||
end | ||
end | ||
w | ||
end |
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
b78a830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
b78a830
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/22734
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: