Skip to content

Commit f5a27bf

Browse files
authored
revamp GridRoomsUndirected and GridRoomsDirected (#154)
* add GridRoomsUndirectedModule.GridRoomsUndirected * add GridRoomsDirectedModule.GridRoomsDirected * remove old GridRoomsUndirected & GridRoomsDirected * fix getting started in README * fix door placing in GridRoomsUndirected * forward show method for RLBaseGridWorld to inner env * change MIME("text/plain") to MIME"text/plain"() * forward play! methods for RLBaseGridWorld to inner env * rename RLBaseGridWorld to RLBaseEnv * update README
1 parent c585c20 commit f5a27bf

File tree

8 files changed

+352
-295
lines changed

8 files changed

+352
-295
lines changed

README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This package is inspired by [gym-minigrid](https://github.com/maximecb/gym-minig
1414
[List of Environments](#list-of-environments)
1515
1. [SingleRoomUndirected](#singleroomundirected)
1616
1. [SingleRoomDirected](#singleroomdirected)
17+
1. [GridRoomsUndirected](#gridroomsundirected)
18+
1. [GridRoomsDirected](#gridroomsdirected)
1719

1820
## Getting Started
1921

@@ -34,7 +36,7 @@ GW.Play.play!(env, file_name = "recording.txt")
3436

3537
# replay the recording inside the terminal at given frame rate
3638

37-
GW.Play.repay("recording.txt", frame_rate = 2)
39+
GW.Play.replay("recording.txt", frame_rate = 2)
3840

3941
# manually step through the recording
4042

@@ -44,16 +46,18 @@ GW.Play.replay("recording.txt", frame_rate = nothing)
4446

4547
import ReinforcementLearningBase as RLBase
4648

47-
RLBase.reset!(env)
48-
RLBase.state(env)
49-
RLBase.action_space(env)
50-
RLBase.reward(env)
51-
RLBase.is_terminated(env)
49+
rlbase_env = GW.RLBaseEnvModule.RLBaseEnv(env)
5250

53-
env(1) # move up
54-
env(2) # move down
55-
env(3) # move left
56-
env(4) # move right
51+
RLBase.reset!(rlbase_env)
52+
RLBase.state(rlbase_env)
53+
RLBase.action_space(rlbase_env)
54+
RLBase.reward(rlbase_env)
55+
RLBase.is_terminated(rlbase_env)
56+
57+
rlbase_env(1) # move up
58+
rlbase_env(2) # move down
59+
rlbase_env(3) # move left
60+
rlbase_env(4) # move right
5761
```
5862

5963
## Playing and Recording
@@ -75,3 +79,11 @@ Here is an example:
7579
1. ### SingleRoomDirected
7680

7781
<img src="https://user-images.githubusercontent.com/32610387/124130952-efed6d00-da9c-11eb-84fa-0caf856a2580.gif">
82+
83+
1. ### GridRoomsUndirected
84+
85+
<img src="https://user-images.githubusercontent.com/32610387/124348535-1d0a5e80-dc08-11eb-9cfb-7c5f40e9c5c9.gif">
86+
87+
1. ### GridRoomsDirected
88+
89+
<img src="https://user-images.githubusercontent.com/32610387/124348551-298eb700-dc08-11eb-835a-ee4b80a5b1b4.gif">

src/envs/envs.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ function place_room!(world::GridWorldBase, room::Room)
2929
world[WALL, top:bottom, right] .= true
3030
end
3131

32+
function sample_empty_position(rng, tile_map, max_tries = 1024)
33+
_, height, width = size(tile_map)
34+
position = CartesianIndex(rand(rng, 1:height), rand(rng, 1:width))
35+
36+
for i in 1:1000
37+
if any(@view tile_map[:, position])
38+
position = CartesianIndex(rand(rng, 1:height), rand(rng, 1:width))
39+
else
40+
return position
41+
end
42+
end
43+
44+
@warn "Returning non-empty position: $(position)"
45+
46+
return position
47+
end
48+
3249
function sample_two_positions_without_replacement(rng, region)
3350
position1 = rand(rng, region)
3451
position2 = rand(rng, region)
@@ -40,7 +57,6 @@ function sample_two_positions_without_replacement(rng, region)
4057
return position1, position2
4158
end
4259

43-
include("grid_rooms.jl")
4460
include("sequential_rooms.jl")
4561
include("maze.jl")
4662
include("go_to_target.jl")
@@ -54,3 +70,5 @@ include("transport.jl")
5470
include("collect_gems_undirected_multi_agent.jl")
5571
include("single_room_undirected.jl")
5672
include("single_room_directed.jl")
73+
include("grid_rooms_undirected.jl")
74+
include("grid_rooms_directed.jl")

src/envs/grid_rooms.jl

Lines changed: 0 additions & 257 deletions
This file was deleted.

0 commit comments

Comments
 (0)