Skip to content

Commit

Permalink
revamp GridRoomsUndirected and GridRoomsDirected (#154)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Sid-Bhatia-0 authored Jul 3, 2021
1 parent c585c20 commit f5a27bf
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 295 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This package is inspired by [gym-minigrid](https://github.com/maximecb/gym-minig
[List of Environments](#list-of-environments)
1. [SingleRoomUndirected](#singleroomundirected)
1. [SingleRoomDirected](#singleroomdirected)
1. [GridRoomsUndirected](#gridroomsundirected)
1. [GridRoomsDirected](#gridroomsdirected)

## Getting Started

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

# replay the recording inside the terminal at given frame rate

GW.Play.repay("recording.txt", frame_rate = 2)
GW.Play.replay("recording.txt", frame_rate = 2)

# manually step through the recording

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

import ReinforcementLearningBase as RLBase

RLBase.reset!(env)
RLBase.state(env)
RLBase.action_space(env)
RLBase.reward(env)
RLBase.is_terminated(env)
rlbase_env = GW.RLBaseEnvModule.RLBaseEnv(env)

env(1) # move up
env(2) # move down
env(3) # move left
env(4) # move right
RLBase.reset!(rlbase_env)
RLBase.state(rlbase_env)
RLBase.action_space(rlbase_env)
RLBase.reward(rlbase_env)
RLBase.is_terminated(rlbase_env)

rlbase_env(1) # move up
rlbase_env(2) # move down
rlbase_env(3) # move left
rlbase_env(4) # move right
```

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

<img src="https://user-images.githubusercontent.com/32610387/124130952-efed6d00-da9c-11eb-84fa-0caf856a2580.gif">

1. ### GridRoomsUndirected

<img src="https://user-images.githubusercontent.com/32610387/124348535-1d0a5e80-dc08-11eb-9cfb-7c5f40e9c5c9.gif">

1. ### GridRoomsDirected

<img src="https://user-images.githubusercontent.com/32610387/124348551-298eb700-dc08-11eb-835a-ee4b80a5b1b4.gif">
20 changes: 19 additions & 1 deletion src/envs/envs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ function place_room!(world::GridWorldBase, room::Room)
world[WALL, top:bottom, right] .= true
end

function sample_empty_position(rng, tile_map, max_tries = 1024)
_, height, width = size(tile_map)
position = CartesianIndex(rand(rng, 1:height), rand(rng, 1:width))

for i in 1:1000
if any(@view tile_map[:, position])
position = CartesianIndex(rand(rng, 1:height), rand(rng, 1:width))
else
return position
end
end

@warn "Returning non-empty position: $(position)"

return position
end

function sample_two_positions_without_replacement(rng, region)
position1 = rand(rng, region)
position2 = rand(rng, region)
Expand All @@ -40,7 +57,6 @@ function sample_two_positions_without_replacement(rng, region)
return position1, position2
end

include("grid_rooms.jl")
include("sequential_rooms.jl")
include("maze.jl")
include("go_to_target.jl")
Expand All @@ -54,3 +70,5 @@ include("transport.jl")
include("collect_gems_undirected_multi_agent.jl")
include("single_room_undirected.jl")
include("single_room_directed.jl")
include("grid_rooms_undirected.jl")
include("grid_rooms_directed.jl")
257 changes: 0 additions & 257 deletions src/envs/grid_rooms.jl

This file was deleted.

Loading

0 comments on commit f5a27bf

Please sign in to comment.