Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 124ef3d

Browse files
authored
Merge pull request #190 from JuliaReinforcementLearning/auto-juliaformatter-pr
Automatic JuliaFormatter.jl run
2 parents 5665e1d + cef1840 commit 124ef3d

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

src/policies/agents/agent.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ functor(x::Agent) = (policy = x.policy,), y -> @set x.policy = y.policy
2424
(agent::Agent)(env) = agent.policy(env)
2525

2626
function check(agent::Agent, env::AbstractEnv)
27-
if ActionStyle(env) === FULL_ACTION_SET && !haskey(agent.trajectory, :legal_actions_mask)
27+
if ActionStyle(env) === FULL_ACTION_SET &&
28+
!haskey(agent.trajectory, :legal_actions_mask)
2829
@warn "The env[$(nameof(env))] is of FULL_ACTION_SET, but I can not find a trace named :legal_actions_mask in the trajectory"
2930
end
3031
check(agent.policy, env)

src/policies/q_based_policies/q_based_policy.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Flux.functor(x::QBasedPolicy) = (learner = x.learner,), y -> @set x.learner = y.
2020

2121
::QBasedPolicy)(env) = π(env, ActionStyle(env))
2222
::QBasedPolicy)(env, ::MinimalActionSet) = π.explorer.learner(env))
23-
::QBasedPolicy)(env, ::FullActionSet) = π.explorer.learner(env), legal_action_space_mask(env))
23+
::QBasedPolicy)(env, ::FullActionSet) =
24+
π.explorer.learner(env), legal_action_space_mask(env))
2425

2526
RLBase.prob(p::QBasedPolicy, env) = prob(p, env, ActionStyle(env))
26-
RLBase.prob(p::QBasedPolicy, env, ::MinimalActionSet) =
27-
prob(p.explorer, p.learner(env))
27+
RLBase.prob(p::QBasedPolicy, env, ::MinimalActionSet) = prob(p.explorer, p.learner(env))
2828
RLBase.prob(p::QBasedPolicy, env, ::FullActionSet) =
2929
prob(p.explorer, p.learner(env), legal_action_space_mask(env))
3030

@@ -36,7 +36,7 @@ RLBase.update!(p::QBasedPolicy, trajectory::AbstractTrajectory) =
3636
function check(p::QBasedPolicy, env::AbstractEnv)
3737
A = action_space(env)
3838
if (A isa AbstractVector && A == 1:length(A)) ||
39-
(A isa Tuple && A == Tuple(1:length(A)))
39+
(A isa Tuple && A == Tuple(1:length(A)))
4040
# this is expected
4141
else
4242
@warn "Applying a QBasedPolicy to an environment with a unknown action space. Maybe convert the environment with `discrete2standard_discrete` in ReinforcementLearningEnvironments.jl first or redesign the environment."

src/policies/random_policy.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,35 @@ end
2020

2121
Random.seed!(p::RandomPolicy, seed) = Random.seed!(p.rng, seed)
2222

23-
RandomPolicy(s=nothing; rng = Random.GLOBAL_RNG) = RandomPolicy(s, rng)
23+
RandomPolicy(s = nothing; rng = Random.GLOBAL_RNG) = RandomPolicy(s, rng)
2424

2525
(p::RandomPolicy{Nothing})(env) = rand(p.rng, legal_action_space(env))
2626
(p::RandomPolicy)(env) = rand(p.rng, p.action_space)
2727

2828
function RLBase.prob(p::RandomPolicy{<:Union{AbstractVector,Tuple}}, env::AbstractEnv)
2929
n = length(p.action_space)
30-
Categorical(fill(1/n, n); check_args=false)
30+
Categorical(fill(1 / n, n); check_args = false)
3131
end
3232

3333
RLBase.prob(p::RandomPolicy{Nothing}, env::AbstractEnv) = prob(p, env, ChanceStyle(env))
3434

35-
function RLBase.prob(p::RandomPolicy{Nothing}, env::AbstractEnv, ::RLBase.AbstractChanceStyle)
35+
function RLBase.prob(
36+
p::RandomPolicy{Nothing},
37+
env::AbstractEnv,
38+
::RLBase.AbstractChanceStyle,
39+
)
3640
mask = legal_action_space_mask(env)
3741
n = sum(mask)
3842
prob = zeros(length(mask))
3943
prob[mask] .= 1 / n
4044
prob
4145
end
4246

43-
function RLBase.prob(p::RandomPolicy{Nothing}, env::AbstractEnv, ::RLBase.ExplicitStochastic)
47+
function RLBase.prob(
48+
p::RandomPolicy{Nothing},
49+
env::AbstractEnv,
50+
::RLBase.ExplicitStochastic,
51+
)
4452
if current_player(env) == chance_player(env)
4553
prob(env, chance_player(env))
4654
else

src/policies/random_start_policy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ for f in (:prob, :priority)
2525
$f(p.random_policy, args...)
2626
end
2727
end
28-
end
28+
end

test/components/agents.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
@testset "Agent" begin
2-
end
1+
@testset "Agent" begin end

0 commit comments

Comments
 (0)