Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for actions #40

Merged
merged 3 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/abstract_grid_world.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export get_agent_view, AbstractGridWorld
export get_actions
abstract type AbstractGridWorld end

function get_agent_view end
Expand All @@ -21,12 +22,14 @@ function get_agent_view(w::AbstractGridWorld, agent_view_size=(7,7))
get_agent_view!(v, w)
end

function (w::AbstractGridWorld)(dir::Union{TurnRight, TurnLeft})
function (w::AbstractGridWorld)(action::Union{TurnRight, TurnLeft})
a = get_agent(w)
set_dir!(a, dir(get_dir(a)))
set_dir!(a, action(get_dir(a)))
w
end

get_actions(w::AbstractGridWorld) = (MOVE_FORWARD, TURN_LEFT, TURN_RIGHT)

get_agent_view_inds(w::AbstractGridWorld, s=(7,7)) = get_agent_view_inds(get_agent_pos(w).I, s, get_agent_dir(w))

get_agent_view!(v::BitArray{3}, w::AbstractGridWorld) = get_agent_view!(v, convert(GridWorldBase, w), get_agent_pos(w), get_agent_dir(w))
Expand Down
10 changes: 6 additions & 4 deletions src/actions.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
export MoveForward, TurnLeft, TurnRight
export AbstractGridWorldAction, MoveForward, TurnLeft, TurnRight
export MOVE_FORWARD, TURN_LEFT, TURN_RIGHT

#####
# Actions
#####

struct MoveForward end
abstract type AbstractGridWorldAction end

struct MoveForward <: AbstractGridWorldAction end
const MOVE_FORWARD = MoveForward()

struct TurnRight end
struct TurnRight <: AbstractGridWorldAction end
const TURN_RIGHT = TurnRight()

struct TurnLeft end
struct TurnLeft <: AbstractGridWorldAction end
const TURN_LEFT = TurnLeft()

(x::TurnRight)(::Left) = UP
Expand Down