Q: Problems with NetLogo agents movimentation I'm actually developing a simulation to study social phenomena. 
My idea is a population of agents choosing the closer factory of them, walking forwards it and (when they reach it) go back to their initial position.
However, I'm having some trouble to program it. Some of the agents just pass by their initial position and reach the borders of my simulation, stopping there.
Here is my code:
breed [population person] ;create the population
breed [all-fac factory] ;create the factories

população-own [
  myneighbor ;defines which factory is closer
  myNND ;calculate the distance between the person and the closer factory
  home-x ;initial x position
  home-y ;initial y position
]

to setup
  clear-all
  reset-ticks
  create-population 83 ; creates the population with 83 people in it
  [
    setxy random-xcor random-ycor ; set people initial position randomly 
    set shape "person"
    set home-x xcor 
    set home-y ycor
  ]
  create-all-fac 9
  [
    ask all-fac [ set color white] 
    ask facture 83 [ setxy 0 0 ] ; defines the initial position of every factory
    ask facture 84 [ setxy 70 0] 
    ask facture 85 [ setxy -70 0 ]
    ask facture 86 [ setxy 70 70 ]
    ask facture 87 [ setxy 0 70 ]
    ask facture 88 [ setxy -70 70 ]
    ask facture 89 [ setxy 70 -70 ]
    ask facture 90 [ setxy 0 -70 ]
    ask facture 91 [ setxy -70 -70 ]
    set shape "house"
  ]
end

to go
    move
    tick
    choose-facture

end

to choose-facture
   ask population [
    set myneighbor min-one-of other fábricas [distance myself] ; choose my nearest neighbor based on distance
    set myNND distance myneighbor
  ]
end



to move
  ask population [
  if xcor = home-x and ycor = home-y [
      face myneighbor
      fd 1
    ]
   if any? all-fac in-radius 5 [
   facexy home-x home-y 
    fd 1 ] 
    fd 1
  ]
end 

If someone could help me with that I would be really thankful :) .

A: Arthur!
Your code was almost right!
I changed the names for consistency, to fix some typos.
I rearranged the commands in the go step so that they checked their positions before moving, not after.  Usually we put "tick" as the last statement in the go procedure.
I manually reset the view to have max-xcor and max-ycor 100, and shut off wrapping, so the factories were within the view, and made the patch size 3 instead of 13, so the view fit on my laptop small screen.
Finally,  I changed the test of whether someone was home to whether they were within a distance of 5 of home, not whether they were exactly at home -- just the same as the test you use for being at a factory.
With those changes, the code seems to do what you want it to -- the people walk to the factory and then back home, over and over.  No one gets stuck on the border of the view.
;; NOTE -- the view has been changed to shut off horizontal and vertical wrapping
;; and max-pxcor = max-pycor = 100
;; and patch-size = 3 pixels, not 13
;; so population and factory size have been increased.


breed [population person] ;create the population
breed [all-fac factory] ;create the factories

;;população-own [
  population-own [
  myneighbor ;defines which factory is closer
  myNND ;calculate the distance between the person and the closer factory
  home-x ;initial x position
  home-y ;initial y position
]

to setup
  clear-all
  reset-ticks
 create-population 83 ; creates the population with 83 people in it

  [
    setxy random-xcor random-ycor ; set people initial position randomly 
    set shape "person"
    set home-x xcor 
    set home-y ycor
    set size 5
  ]
  create-all-fac 9
  [
    ask all-fac [ set color white] 
    ask factory 83 [ setxy 0 0 ] ; defines the initial position of every factory
    ask factory 84 [ setxy 70 0] 
    ask factory 85 [ setxy -70 0 ]
    ask factory 86 [ setxy 70 70 ]
    ask factory 87 [ setxy 0 70 ]
    ask factory 88 [ setxy -70 70 ]
    ask factory 89 [ setxy 70 -70 ]
    ask factory 90 [ setxy 0 -70 ]
    ask factory 91 [ setxy -70 -70 ]
    set shape "house"
    set size 5
  ]
end

to go
    choose-factory  ;;  moved this command up from below tick
    move
    tick
   ;; choose-factory

end

to choose-factory
   ask population [
    set myneighbor min-one-of all-fac [distance myself] ; choose my nearest neighbor based on distance
    set myNND distance myneighbor
  ]
end



to move
  ask population [
 ;; if xcor = home-x and ycor = home-y [   ;;<<<<<<<<<<<<<<<<<<<< replaced this test
    if (distancexy home-x home-y) <= 5 [
      face myneighbor
      fd 1
    ]
   if any? all-fac in-radius 5 [
   facexy home-x home-y 
    fd 1 ] 
      fd 1
  ]
end 

One last suggestion.   The code you wrote is quite "brittle",  because if you change the number of people to some smaller number like 5,   for testing,  there will be no factory #83 to set anywhere and the code will crash.
You may want to have some slider to set the number of people and want your code to keep working for any number of people.   
Also, it take a lot of lines to position all the factories. What is a good way to do it that is short, but will not break if you change the number of people?
Here's some code that does that.   It makes a list of the factories when it creates them, so it then has a list of the who numbers of the 9 factories it just created.
Then, it finds those on the list and uses the numbers to position the factories.
It works. Here is the modified section of code:
 let factory-list []  ;; make an empty list
  create-all-fac 9
  [ 
    set shape "house"
    set color white
    set size 5
    set factory-list fput who factory-list  ; add this factory to the growing list
  ]  

  ;; OK, now we have a list of all 9 factories.
  ;; Confirm that by printing it

  print "here is the list of who-numbers of the new factories:"
  show factory-list

  ;; now we need to insert those numbers into the following commands:

    ask factory item 0 factory-list [ setxy 0 0 ] ; defines the initial position of every factory
    ask factory item 1 factory-list [ setxy 70 0] 
    ask factory item 2 factory-list [ setxy -70 0 ]
    ask factory item 3 factory-list [ setxy 70 70 ]
    ask factory item 4 factory-list [ setxy 0 70 ]
    ask factory item 5 factory-list [ setxy -70 70 ]
    ask factory item 6 factory-list [ setxy 70 -70 ]
    ask factory item 7 factory-list [ setxy 0 -70 ]
    ask factory item 8 factory-list [ setxy -70 -70 ]

