SHARE
TWEET

Untitled

a guest Jun 9th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. to move
  3.   ; select customers that need to move: those who did not decide to balk and are still not at the checkout counter
  4.   ; they might have just arrived, or are already in queue (if the queue moves, they need to move)
  5.   ask customers with [(status = "arrived") or (status = "atqueue")] [
  6.     ; face left
  7.     ask customers with [turned = 0] [set heading 90]
  8.  
  9.     ask customers with [queue_nr = 0 and turned = 0] [
  10.       if [pcolor] of patch-ahead (140 - c0_x) = black [
  11.         set heading 0
  12.         set turned 1
  13.       ]
  14.     ]
  15.     ask customers with [queue_nr = 1 and turned = 0] [
  16.       if [pcolor] of patch-ahead (140 - c1_x) = black [
  17.         set heading 0
  18.         set turned 1
  19.       ]
  20.     ]
  21.     ask customers with [queue_nr = 2 and turned = 0] [
  22.       if [pcolor] of patch-ahead (140 - c2_x) = black [
  23.         set heading 0
  24.         set turned 1
  25.       ]
  26.     ]
  27.  
  28.    ; there's someone in front of me? in at leash 25px distance?
  29.   let i 1
  30.   let min_dist 25
  31.   let num_ahead 0
  32.   while [i < min_dist] [
  33.       if (any? turtles-on patch-ahead i) [ set num_ahead num_ahead + 1 ]
  34.       set i i + 1
  35.   ]
  36.  
  37.   ; if there's someone in front of me, i'm at the queue
  38.   if (num_ahead > 0) and (status = "arrived") [
  39.      set status "atqueue"
  40.      ; mark the time I entered the queue
  41.      set entered_queue ticks
  42.   ]
  43.  
  44.   ; if i'm still not at the checkout counter and there's no one in front of me, keep walking!
  45.    if (num_ahead = 0) [
  46.      ifelse Scenario = "two-counters" [
  47.        if (queue_nr = 1) and (distancexy c1_x c1_y > 5) [ fd 1 ]
  48.        if (queue_nr = 2) and (distancexy c2_x c2_y > 5) [ fd 1 ]
  49.      ]
  50.      [
  51.        if (distancexy c0_x c0_y > 5) [ fd 1 ]
  52.      ]
  53.    ]
  54.  ]
  55.  
  56.  ; customers that know the app go straight to "waiting area", because they've already pre ordered
  57.   if scenario = "app" [
  58.     ask customers with [app_info = 1 and (status = "arrived" or status = "atqueue")] [
  59.       set status "ordered_w_app"
  60.       set color turquoise
  61.       let target one-of patches with [(pcolor = white) and (not any? turtles-here)]
  62.       face target
  63.       while [patch-here != target] [
  64.         forward 1
  65.       ]
  66.       ; for how long will I wait?
  67.       set wt times "waiting_time"
  68.       set ref_wt ticks
  69.       set death_time ref_wt + wt
  70.       set entered_waiting ticks
  71.       ; app user contacts someone at the queue to tell about the app
  72.       if (any? customers with [status = "atqueue" and not any? link-neighbors]) [
  73.         create-link-with one-of customers with [status = "atqueue" and not any? link-neighbors] [
  74.           set visited 0
  75.         ]
  76.       ]
  77.     ]
  78.  
  79.     ; with a 50% chance, customer accepts suggestion and pre-order through through  app
  80.     ; color turns green and he goes straight to waiting area
  81.     ask links with [visited = 0] [
  82.       set wt times "waiting_time"
  83.       set visited 1
  84.       let my_nodes both-ends
  85.       let new_user one-of my_nodes with [ color != turquoise ]
  86.       ifelse random 100 < 50 [
  87.         ask new_user [
  88.           set app_info 1
  89.           set color turquoise
  90.           set app_adopters app_adopters + 1
  91.         ]
  92.       ] [ die ]
  93.  
  94.     ]
  95.   ]
  96. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top