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

Update battle.jl #34

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions docs/examples/battle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
# their level.

# Now let's set up the battle field:
function battle(; fighters = 50, seed = 6547)
function create_battlefield(; fighters = 50, seed = 6547)
model = StandardABM(
Fighter,
GridSpace((100, 100, 10); periodic = false);
Expand Down Expand Up @@ -182,7 +182,7 @@ function captor_behavior!(agent, model)
## Prisoner runs away in the commotion
prisoner.shape = :utriangle
prisoner.capture_time = 0
walk!(prisoner, (rand(abmrng(model), -1:1, 2)..., 0), model)
walk!(prisoner, (rand(abmrng(model), -1:1, 2)..., 0), model, ifempty=false)
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
walk!(prisoner, (rand(abmrng(model), -1:1, 2)..., 0), model, ifempty=false)
walk!(prisoner, (rand(abmrng(model), -1:1, 2)..., 0), model; ifempty=false)

i believe it makes for a more readable code if keywords are separated by ; can you change this here and in subsequent calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this change in new commit

end
end

Expand All @@ -205,7 +205,7 @@ function endgame!(agent, model)
opponent.shape = :rect
showdown!(agent, opponent, model)
else
walk!(agent, (sign.(target .- origin)..., 0), model)
walk!(agent, (sign.(target .- origin)..., 0), model, ifempty=false)
end
end
end
Expand Down Expand Up @@ -260,15 +260,15 @@ function agent_step!(agent, model)
## Sneak up behind them
target = loc(closest_target(agent, occupied_ids, model))
agent.shape = :pentagon
walk!(agent, (sign.(target .- origin)..., 0), model)
walk!(agent, (sign.(target .- origin)..., 0), model, ifempty=false)
else
## Opponents that are greatly higher in rank that the current agent
strong_ids = collect(nearby_ids(agent, model, [(1, -5:5), (2, -5:5), (3, 2:4)]))
if !isempty(strong_ids)
## Run away from nearest
target = loc(closest_target(agent, strong_ids, model))
agent.shape = :utriangle
walk!(agent, (sign.(origin .- target)..., 0), model)
walk!(agent, (sign.(origin .- target)..., 0), model, ifempty=false)
else
## There are no distractions. Search for the closest worthy opponent
worthy_ids = collect(nearby_ids(agent, model, [(3, -1:1)]))
Expand All @@ -283,7 +283,7 @@ function agent_step!(agent, model)
else
## Move towards worthy opponent
agent.shape = :diamond
walk!(agent, (sign.(target .- origin)..., 0), model)
walk!(agent, (sign.(target .- origin)..., 0), model, ifempty=false)
end
else
## Find any weak targets in the vicinity
Expand All @@ -304,7 +304,7 @@ function agent_step!(agent, model)
else
## Chase down nearest (can move 2 steps at a time!)
agent.shape = :star4
walk!(agent, (2 .* sign.(target .- origin)..., 0), model)
walk!(agent, (2 .* sign.(target .- origin)..., 0), model, ifempty=false)
end
else
## Abandon honour. This is the end
Expand All @@ -317,7 +317,7 @@ function agent_step!(agent, model)
return
end

model = battle()
model = create_battlefield()

# ## Let the Battle Begin
# We need to write entirely custom plotting here, because we have a 3D space
Expand Down
Loading