Skip to content
Merged
Changes from 2 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
51 changes: 28 additions & 23 deletions src/LaserTag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,23 @@ export
LTState,
CMeas,
DMeas,
LaserTagVis,

MoveTowards,
LaserTagVis, MoveTowards,
MoveTowardsSampled,
OptimalMLSolver,
OptimalML,
BestExpectedSolver,
BestExpected,

DESPOTEmu,

gen_lasertag,
BestExpected, DESPOTEmu, gen_lasertag,
cpp_emu_lasertag,
tikz_pic,
n_clear_cells


const Coord = SVector{2, Int}
const CMeas = MVector{8, Float64}
const DMeas = MVector{8, Int}
const Coord = SVector{2,Int}
const CMeas = MVector{8,Float64}
const DMeas = MVector{8,Int}

const C_SAME_LOC = fill!(MVector{8, Float64}(undef), -1.0)
const D_SAME_LOC = fill!(MVector{8, Int64}(undef), -1)
const C_SAME_LOC = fill!(MVector{8,Float64}(undef), -1.0)
const D_SAME_LOC = fill!(MVector{8,Int64}(undef), -1)

@auto_hash_equals struct LTState # XXX auto_hash_equals isn't correct for terminal
robot::Coord
Expand Down Expand Up @@ -72,16 +66,16 @@ obs_type(om::ObsModel) = obs_type(typeof(om))

include("distance_cache.jl")

@with_kw struct LaserTagPOMDP{M<:ObsModel, O<:Union{CMeas, DMeas}} <: POMDP{LTState, Int, O}
tag_reward::Float64 = 10.0
step_cost::Float64 = 1.0
discount::Float64 = 0.95
floor::Floor = Floor(7, 11)
obstacles::Set{Coord} = Set{Coord}()
robot_init::Union{Coord, Nothing} = nothing
diag_actions::Bool = false
dcache::LTDistanceCache = LTDistanceCache(floor, obstacles)
obs_model::M = DESPOTEmu(floor, 2.5)
@with_kw struct LaserTagPOMDP{M<:ObsModel,O<:Union{CMeas,DMeas}} <: POMDP{LTState,Int,O}
tag_reward::Float64 = 10.0
step_cost::Float64 = 1.0
discount::Float64 = 0.95
floor::Floor = Floor(7, 11)
obstacles::Set{Coord} = Set{Coord}()
robot_init::Union{Coord,Nothing} = nothing
diag_actions::Bool = false
dcache::LTDistanceCache = LTDistanceCache(floor, obstacles)
obs_model::M = DESPOTEmu(floor, 2.5)
end

ltfloor(m::LaserTagPOMDP) = m.floor
Expand Down Expand Up @@ -143,6 +137,17 @@ function POMDPs.reward(p::LaserTagPOMDP, s::LTState, a::Int, sp::LTState)
end
end


# add a function to transform a LTState to a vector
function POMDPs.convert_s(T::Type{<:AbstractArray}, s::LTState, p::LaserTagPOMDP)
return convert(T, vcat(s.robot, s.opponent, s.terminal))
end

# transform a vector to a LTState
function POMDPs.convert_s(T::Type{LTState}, v::AbstractArray{Float64}, p::LaserTagPOMDP)
return LTState([v[1], v[2]], [v[3], v[4]], v[5])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return LTState([v[1], v[2]], [v[3], v[4]], v[5])
return LTState(Coord(v[1], v[2]), Coord(v[3], v[4]), v[5])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @zsunberg! Sorry, I totally forgot this change after Xmas... I updated and pushed it! Hope what did is correct.
Pls let me know if everything is ok.

end

POMDPs.isterminal(p::LaserTagPOMDP, s::LTState) = s.terminal
POMDPs.discount(p::LaserTagPOMDP) = p.discount

Expand Down