Reputation: 63
i am designing a program where an aircraft will travel between two points on my "airspace". However, in between those 2 points, i have 5 "checkpoints" where the aircraft will make a decision every time it passes each checkpoint. The code i have written for the checkpoints are as follows :
to setup-areas
ask patches [
ifelse pxcor >= 14
[ set nonedist? true ]
[ set nonedist? false ]
ifelse pxcor > 10.8 and pxcor < 14 and pycor <= -2.5 and pycor > -4.5
[ set twelvedist? true ]
[ set twelvedist? false ]
ifelse pxcor > 7.6 and pxcor <= 10.8 and pycor <= -4.5 and pycor >= -7.5
[ set ninedist? true ]
[ set ninedist? false ]
ifelse pxcor > 4.4 and pxcor <= 7.6 and pycor < -7.5 and pycor >= -8.5
[ set sixdist? true ]
[ set sixdist? false ]
ifelse pxcor > 1.2 and pxcor <= 4.4 and pycor < -10.5 and pycor >= -11.5
[ set threedist? true ]
[ set threedist? false ]
ifelse pxcor >= -2 and pxcor <= 1.2 and pycor < -12.5 and pycor >= -13
[ set onedist? true ]
[ set onedist? false ]
ifelse pxcor < -2 and pycor < -13.5
[ set zerodist? true ]
[ set zerodist? false ]
]
end
The aircraft doest seem to be following the areas it is in. Any help is greatly appreciated!
The code to get the aircraft to execute some action upon entering a specific zone is as follows:
to go
ask aircrafts
[
while [nonedist? = true] [ pre-twelve ]
while [twelvedist? = true] [ twelve-to-nine ]
]
tick
end
Upvotes: 0
Views: 43
Reputation: 17678
I don't have an answer but I do have a diagnostic suggestion.
First, change your setup-areas procedure to make things a bit more visible. The following will mark the patches where the aircraft should do something.
to setup-areas
ask patches [
ifelse pxcor >= 14
[ set nonedist? true set pcolor red]
[ set nonedist? false ]
ifelse pxcor > 10.8 and pxcor < 14 and pycor <= -2.5 and pycor > -4.5
[ set twelvedist? true set pcolor red]
[ set twelvedist? false ]
ifelse pxcor > 7.6 and pxcor <= 10.8 and pycor <= -4.5 and pycor >= -7.5
[ set ninedist? true set pcolor red]
[ set ninedist? false ]
ifelse pxcor > 4.4 and pxcor <= 7.6 and pycor < -7.5 and pycor >= -8.5
[ set sixdist? true set pcolor red]
[ set sixdist? false ]
ifelse pxcor > 1.2 and pxcor <= 4.4 and pycor < -10.5 and pycor >= -11.5
[ set threedist? true set pcolor red]
[ set threedist? false ]
ifelse pxcor >= -2 and pxcor <= 1.2 and pycor < -12.5 and pycor >= -13
[ set onedist? true set pcolor red]
[ set onedist? false ]
ifelse pxcor < -2 and pycor < -13.5
[ set zerodist? true set pcolor red]
[ set zerodist? false ]
]
end
Then change what they should be doing when they hit a checkpoint.
to go
ask aircrafts
[
if [nonedist? = true] [ set color blue ]
if [twelvedist? = true] [ set color blue ]
]
tick
end
This will let you see if the interaction occurs as you expect. Then change your go
code back and modify your action code so that, for example:
to pre-twelve
set color blue
type "My height is " print varname ; where varname is whatever is being changed
< then all the code you already have in the pre-twelve procedure>
end
The point is to work out which procedure isn't happening and from there, to work out why it's not happening. There is simply insufficient information in your question to have any chance of working out what's wrong.
Upvotes: 1