I have written a struct and I want to have a constructor method that supports both vector and tuple input for the argument barrierPositions
.
struct MapInfo
mapSize::Tuple{Int64, Int64}
flagPosition::Tuple{Int64, Int64}
barrierPositions::Vector{Tuple{Int64, Int64}}
function MapInfo(;mapSize::Tuple{Int64, Int64}, flagPosition::Tuple{Int64, Int64},
barrierPositions::Vector{Tuple{Int64, Int64}})
unique!(barrierPositions)
deleteat!(barrierPositions, findall(x->x==flagPosition, barrierPositions))
return new(mapSize, flagPosition, barrierPositions)
end
function MapInfo(;mapSize::Tuple{Int64, Int64}, flagPosition::Tuple{Int64, Int64},
barrierPositions::Tuple{Int64, Int64})
return MapInfo(mapSize=mapSize, flagPosition=flagPosition, barrierPositions=[barrierPositions])
end
end
But if I run the following command, it seems to overlook my first constructor method which should receive vectors for the argument barrierPositions
.
mapInfo = MapInfo(mapSize=(4,4), flagPosition=(3,3), barrierPositions=[(3,2), (2,3)])
ERROR: TypeError: in keyword argument barrierPositions, expected Tuple{Int64, Int64}, got a value of type Vector{Tuple{Int64, Int64}}
Stacktrace:
[1] top-level scope
@ e:\Master Thesis\lu_jizhou\Learning\DQN.jl:250
How can I do this?