change pcolor of neighbor

69 views
Skip to first unread message

rbsoc...@gmail.com

unread,
Jan 10, 2022, 2:17:58 PM1/10/22
to netlogo-users

I have two breeds, prts and bizs, with 2 prts visiting 10 bizs.  Two local variables, p_str and b_str, randomly assigned value of 0 or 1.  Code so far is:

 

to go

  if (host > maxwho) [stop]

    ask prts [move-to one-of [neighbors] of one-of bizs

    if p_str = 1 and b_str = 1 [set pcolor red]

    if p_str = 1 and b_str = 0 [set pcolor red]

    if p_str = 0 and p_str = 1 [set pcolor blue]

    if p_str = 0 and p_str = 0 [set pcolor yellow]

    ]

  set host (host + 1)

 display

end

 

Problem is pcolor on which prt is located changes color.  I want to change the color of patch on which the visited biz resides adjacent to the visiting prt on neighboring patch.  Solution?

Thanks, RB

Wade Schuette

unread,
Jan 10, 2022, 5:10:48 PM1/10/22
to rbsoc...@gmail.com, netlogo-users
So instead of what you're doing, in pseudocode

ask prts
   pick a biz
   ask that biz to change it's patch's color
   move to a neighbor of that biz

Wade

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/8f185cc6-3712-4f64-adb4-8cc6e2e2431bn%40googlegroups.com.

James Steiner

unread,
Jan 10, 2022, 6:31:59 PM1/10/22
to Wade Schuette, netlogo-users, rbsoc...@gmail.com
The key  is that instead of selecting and selecting and moving at the same time, in a way that does not preserve the identify or location of the biz, select the biz and store its identity in a variable. 

You could likewise store the target patch.

To reduce redundant code, store the new color in a variable, then ask the selected biz to use it.  

Like

Let the-biz one-of bizs ;; with [ …. ]
Let the-neighbor [ one-of neighbors ] of the-biz
Move-to the-neighbor
Let biz-color 0
If …. [ set biz-color … ] 
… all the if’s! 

Ask the-biz [  set pcolor biz-color ] 

BTW, in your code sample, I think you meant to be checking both p_str and b_str, but at some point your fingers rebelled and it’s all p_str. 

If you are really only looking at 2 values, 0, and 1,  for each of those two variables, you could do something like:

;; convert b_str and p_str to a number 0-3
Let bp_str-index b_str + p_str * 2
Set biz-color item bp_str-index
;;  0,0;   0,1;    1,0;   1,1
[  yellow blue red red ]
Ask the-biz [ set pcolor biz-color ]


~~ James
NetLogo fiend since 2003(?)

rbsoc...@gmail.com

unread,
Jan 11, 2022, 8:03:51 AM1/11/22
to netlogo-users
Thanks for both responses. (Like idea of finger rebellion. Correct in your assessment.)  If reading both suggestions correctly, they change color of biz first and then prt moves to it.  For substantive reasons, the visit needs to happen first and color change second.  The idea is members of two conflicting groups encounter each other.  Depending on their strategy (hence b- and p-str), there is a win/lose/draw outcome.  I want to signal the outcome with the color change of biz patch but maybe it could be done some other way.
RB

Wannes...@hotmail.be

unread,
Jan 11, 2022, 1:27:20 PM1/11/22
to netlogo-users
The first suggestion does indeed change the color before moving but the order here doesn't matter at all. It could just as well be the other way around. The second suggestion already moves before changing.

Your initial problem was that you never asked the prt to change the patchcolor of the biz. You just asked the prt to change patchcolor (hence their own patchcolor).
Both suggestions get around that by creating a creating a local variable that contains a single biz. They then move to the biz and ask that biz to change the color of the patch it stands on.
The local variable here is important to assure that the biz they move to and the biz whose patch color they change are the same biz

Wannes
Op dinsdag 11 januari 2022 om 14:03:51 UTC+1 schreef rbsoc...@gmail.com:

rbsoc...@gmail.com

unread,
Jan 11, 2022, 1:35:59 PM1/11/22
to netlogo-users
Thanks.  Will re-visit these solutions and implement.  RB

James Steiner

unread,
Jan 11, 2022, 4:20:48 PM1/11/22
to rbsoc...@gmail.com, netlogo-users

In my suggestion, setting biz color happens at the very last. 


Reply all
Reply to author
Forward
0 new messages