Bar Moth

No preview image

1 collaborator

Default-person John Shull (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0 • Viewed 309 times • Downloaded 24 times • Run 0 times
Download the 'Bar Moth' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [ males BP_male]
breed [ females BP_female]
breed [ BAR bar_staff ]
breed [ Tablefour four_top ]
breed [ TableEight eight_top  ]
breed [ barstools barstool]
breed [ customers customer]



globals
[
 MensRoom
 WomensRoom
 DanceFloorCor
 CurrentBarValue
 AVGBarValue
 Crowd
 BestGuy
 BestGirl
 NetworkB
 NetworkG
 AVGDrinkCount
]

patches-own
[
 obstacle
 openspace
 BarCounter
 DrinkPoints
 Swarm
]

customers-own
[
  power
  path
  BarCoordinates
  powerrank
  placeinlist
  gender
  bladderrate
  drinkcount
  stuck
  drinkconsume
  drinkhand
  bathroom
  rate
  dance
  danceCor
  single
  seat
  looks
  crush
  numfollowingme
 
]


Bar-own
[
  DrinkMakingRate  
  CurrentDrinks
]

to Floor_Plan
  clear-all
  
  set-patch-size 15
  resize-world 0 60 0 60
  ask patches [set pcolor black]
 
  ifelse( file-exists? "bar_floor_plan.txt")
  [
    file-open "bar_floor_plan.txt"
    while [not file-at-end?]
    [
      let next-x file-read
      let next-y file-read
      let next-color file-read
      ask patch next-x next-y [set pcolor next-color]
    ]
    user-message "Bar Floor Plan Loaded Correctly!"
    file-close
  ]
  [ user-message "**ERROR** Cannot find the file: bar_floor_plan.txt in the current directory"]

  set WomensRoom patch 48 44
  set MensRoom patch 52 44
  ask patches with [pcolor = 9.9]
  [
    set obstacle 1
  ]
  ask patches with [pcolor = 6]  
  [
    set obstacle 1
  ]
  ask patches with [pcolor = 35]
  [
    set Barcounter 1
    set drinkpoints 30
  ]
  set avgbarvalue 0 
  set AVGDrinkCount 0
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to default
  Floor_Plan
  ifelse( file-exists? "dance_floor.txt")
  [
    file-open "dance_floor.txt"
    while [not file-at-end?]
    [
      let next-x file-read
      let next-y file-read
      let next-color file-read
      ask patch next-x next-y [set pcolor next-color]
    ]
    user-message "Dance Floor Loaded Correctly!"
    file-close
  ]
  [ user-message "**ERROR** Cannot find the file: dance_floor.txt in the current directory"]
  setupTablesDefault
  Setup-people
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to SetupTablesDefault
  set-default-shape Tablefour "square"
  set-default-shape barstools "dot"
  create-Tablefour 10 
  ask Tablefour [
    set size 2.5
    set color 45
    setxy 45 10
  ]
  set-default-shape TableEight "square"
  create-TableEight 4 
  ask TableEight [
    set size 4
    set color 26
    setxy 48 10
  ]
 ask four_top 1 [
   setxy 17 37]
 ask four_top 2 [
   setxy 17 42
 ]
 ask four_top 3 [
   setxy 17 47
 ]
 ask four_top 0 [
   setxy 11 47
 ]
 ask four_top 4 [
   setxy 11 42
 ]
 ask four_top 5 [
   setxy 11 37
 ]
 ask four_top 6 [
   setxy 27 37
 ]
 ask four_top 7 [
   setxy 27 31
 ]
 ask four_top 8 [
   setxy 27 26
 ]
 ask four_top 9[
   setxy 27 21
 ]
 ask eight_top 10 [
   setxy 38 15
 ]
 ask eight_top 11 [
   setxy 38 21
 ]
 ask eight_top 12 [
   setxy 38 27
 ]
 ask eight_top 13 [
   setxy 38 33
 ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to SetupTables
  set-default-shape Tablefour "square"
  set-default-shape barstools "dot"
  create-Tablefour Num_Four_Top_Tables 
  ask Tablefour [
    set size 2.5
    set color 45
    setxy 45 10
  ]
  set-default-shape TableEight "square"
  create-TableEight Num_Eight_Top_Tables 
  ask TableEight [
    set size 4
    set color 26
    setxy 48 10
  ]
  if (Num_Four_Top_Tables > 1)
  [
    let i 0
    let y4t 10
    while [i < Num_Four_Top_Tables]
    [
      ask four_top i [
        setxy 45 y4t]
      set i i + 1
      set y4t y4t + 2.5
    ]
  ]
  if (Num_Eight_Top_Tables > 1)
  [
    let i count Tablefour
    let y4t 10
    while [i < Num_Four_Top_Tables + Num_Eight_Top_Tables]
    [
      ask eight_top i [
        setxy 48 y4t]
      set i i + 1
      set y4t y4t + 3.5
    ]
  ]
  let tag1 0
  let tag2 0
  
  ask four_top (Num_Four_Top_Tables - 1) [                       
    set tag1 ycor + 2]
  ask eight_top (Num_Four_Top_Tables + Num_Eight_Top_Tables - 1) [
    set tag2 ycor + 2]
  
  ask patch (46) (tag1) [
    set plabel-color black
    set plabel "4-Tops"
  ]
  
  ask patch (48) (tag2) [
    set plabel-color black
    set plabel "8-Tops"
  ]
  ask patch 49 40 [
    set plabel-color black
    set plabel "TABLES CHOICES"
  ] 
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to MoveTables
  
  if mouse-down? [
    let pickup4 min-one-of Tablefour [distancexy mouse-xcor mouse-ycor]
    let pickup8 min-one-of TableEight [distancexy mouse-xcor mouse-ycor]
    let pick4 [distancexy mouse-xcor mouse-ycor] of pickup4
    let pick8 [distancexy mouse-xcor mouse-ycor] of pickup8
    while [mouse-down?] [
      ifelse (pick4 < pick8)
          [
            ask pickup4 [ 
              setxy (round mouse-xcor) (round mouse-ycor)
            ]
          ][ask pickup8 [setxy (round mouse-xcor) (round mouse-ycor)]]
      display
    ]
  ]
end 
    
;;///////////////////////////////////////////////////////////////////////////////////////////////

to Erasedance
    ask patches with [pcolor = 114]
    [
      set pcolor black
    ]     
    set dancefloorcor nobody
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Dancefloor
  if (mouse-down?)
    [
      let TX round mouse-xcor
      let TY round mouse-ycor
      ask patch TX TY [
        if (pcolor = black)
        [
          set pcolor 114]
        ]
    ]  
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Setup-people  
  reset-ticks
  GenerateBarStools
  set dancefloorcor one-of patches with [pcolor = 114]
    ask patches with [pcolor = black]
  [
    if (not any? turtles-here)
    [set openspace 1
    ]
  ]
  set-default-shape customers "person"
  set-default-shape BAR "person service"
  set-default-shape TableEight "square"
  
  ask n-of Patrons (patches with [pcolor = black and pycor < 25 ])
  [
    if not any? turtles-here
    [
      sprout-customers 1 [
        set path (list (patch (6 + random 36) 52) (patch (7 + random 35) 52) (patch (8 + random 34) 52) (patch 40 52) (patch (10 + random 32) 52))
        set power (list (1 + random 20) (1 + random 20) (1 + random 20) (1 + random 20) (1 + random 20) )
        set powerrank (list 0 0 0 0 0)
        calculateRanking
        
        set heading random 360
        set color blue
        set size 2
        set drinkcount 0
        set gender 1
        set bathroom MensRoom
        set drinkconsume .99
        set bladderrate .4
        set rate 3.1 + random-float .5
        set dance 0
        set dancecor dancefloorcor
        set single 1
        set looks (30 + random 71)
        set crush nobody
      ]
    ]
  ]
  ask n-of (round (( PercentageFemale / 100) * Patrons)) customers [
    set  gender 0
    set color pink
    set rate 2.1 + random-float .5
    set bathroom WomensRoom
    set dance 1
  ]
ask n-of (0.57 * patrons) customers [
  set single 0
]
  ask n-of Number_staff (patches with [pcolor = 6])
    [
      sprout-BAR 1 [set heading random 360
    set color white
    set size 2
    set drinkmakingrate (skills * (1 + random-float 1))
    set CurrentDrinks 0
      ]
    ]  
  set bestguy nobody
  set bestgirl nobody
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to GenerateBarStools

 ask Tablefour [
   if ((xcor < 42) and (xcor > 5 ) and (ycor > 10) and (ycor < 60))
   [
     let i 0
     ask patch-here[
       set pcolor 9.9 
       set obstacle 1 ]
     ask neighbors4[
       set pcolor 9.9
       set obstacle 1]
     while [i < 4 ]
     [
      hatch-barstools 1 [
        set size 2
        set color 8
        set heading (i * 90)
        forward 1.75
      ]    
       set i i + 1
     ]
   ]
 ]
 ask Tableeight [
   if ((xcor < 42) and (xcor > 5 ) and (ycor > 10) and (ycor < 60))
     [   
       let i 0
       ask neighbors [
         set pcolor 9.9
         set obstacle 1]
       while [i < 4 ]
         [
           hatch-barstools 1 [
             set size 2
             set color 8
             set heading (i * 90)
             forward 2
             right 90
             forward 0.5
             left 180 
             hatch-barstools 1 [
               forward 1
             ]
           ]
         set i i + 1
         ]
     ]
 ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to GO
  DoCalculations
  ask customers [
    routine
    set numfollowingme count customers with [crush = myself]
  ]
  
  ask Bar [
    staff-routine
  ]

  if (any? patches with [swarm > 1])
    [ 
      diffuse swarm 0.75
      RecolorCrowd
    ]
  tick
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to DoCalculations
  if (bestguy != nobody)
  [
    set networkB (sum [numfollowingme] of customers with [crush = bestguy]) + (count customers with [crush = bestguy])
    set networkG (sum [numfollowingme] of customers with [crush = bestgirl]) + (count customers with [crush = bestgirl])
  ]
  set CurrentBarValue sum [drinkpoints] of patches with [pcolor = 35]
  set AvgBarValue mean [drinkpoints] of patches with [pcolor = 35]
  set Crowd max-one-of patches [count customers in-radius 10]
  set AvgDrinkCount mean [drinkcount] of customers
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to MarkBestLooking
  set BestGuy max-one-of (customers with [gender = 1]) [looks]
  ask bestguy [
    set shape "Markedmale"
    set size 2
  ]
  set Bestgirl max-one-of (customers with [gender = 0]) [looks]
  ask bestgirl [
    set shape "markedfemale"
    set size 2
  ]
end 
;;///////////////////////////////////////////////////////////////////////////////////////////////

to Routine
  Intoxicated
  ifelse (bladderrate > 20)
    [
      face bathroom
      checkobstacle
      BathRoomFunction
    ]
    [
      ifelse (drinkhand < 1.5)
      [ 
        usememory
        face BarCoordinates
        checkobstacle
        BarCounterFunction (BarCoordinates)
      ]
      [
        ifelse (single = 0)
        [
          FindBarstool
        ]
        [
          ifelse (single = 1) and (drinkcount < Drinks_till_dance)
          [
            finddate
            ConsumeDrink
            checkobstacle
          ]
          [
            if (gender = 1) and (crush != nobody)
            [
              set dance 1
            ]
            
            ifelse (dance = 1) and (drinkcount >= Drinks_till_Dance)
            [
              ifelse any? patches with [pcolor = 114]
                [
                  face dancecor
                  checkobstacle
                  danceaway
                  ConsumeDrink
                ]
                [set dance  0]
                ]
                [ConsumeDrink
                checkobstacle
                ]
            ]
          ]
        ]
      ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Intoxicated
  if (gender = 1) and (drinkcount > max_drinks_male)
  [
    hatch 1 [
      set crush nobody
      set drinkcount 0
      set rate 3.1 + random-float .5
      set dance 0
      set dancecor dancefloorcor
      set single random 2
      set looks (30 + random 71)
      set bladderrate .4
      set numfollowingme 0
      set shape "person"
    ]
      
    ask self [die] 
  ]
  if (gender = 0) and (drinkcount > max_drinks_male)
  [
    hatch 1 [
      set crush nobody
      set drinkcount 0
      set rate 2.1 + random-float .5
      set dance 1
      set dancecor dancefloorcor
      set single random 2
      set looks (30 + random 71)
      set bladderrate .4
      set numfollowingme 0
      set shape "person"
      ]
    ask self [die]
    ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Checkobstacle 
    ifelse ([obstacle] of patch-ahead 1 != 1) and (not any? customers-on patch-ahead 1)
    [
        walkabout
        set stuck 0 
    ]
    [ 
      ifelse (stuck > 2)
      [
        while [[obstacle] of patch-ahead 1 = 1]
        [
          right random-float 90
        ]
        walkabout
        while [[obstacle] of patch-ahead 1 = 1]
        [
          left random-float 180
          set stuck 0
        ]
        walkabout
      ]
      [
        left random-float 90 
        set stuck stuck + 1
        checkobstacle
      ]
    ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Danceaway
  if (patch-here = dancecor)
  [
    right random-float 360
    checkobstacle
    forward random-float 1
    back random-float 1
    left random-float 360
    checkobstacle
    forward random-float 1
    back random-float 1
    if (gender = 0)
    [
      set color scale-color pink drinkhand 20 0 
    ]
    if (gender = 1)
    [
      set color scale-color blue drinkhand 20 0
    ]
    set dancecor one-of patches with [pcolor = 114]
  ]
end 

;;////////////////////////////////////////////////////////////////////////////////////////////////

to FindBarstool
  ifelse (any? barstools-here) 
  [
    ConsumeDrink
  ][
  checkobstacle
  if(any? barstools in-cone 4 160)
  [
    set Seat min-one-of barstools [distance myself]
    face Seat
    ConsumeDrink
    checkobstacle
  ]
  ]  
end 

;;////////////////////////////////////////////////////////////////////////////////////////////////

to FindDate
 
  
  if (gender = 0)
  [
    if (crush = nobody) and (any? customers in-radius Look_Vision with [gender = 1])
    [
      let potentiallist customers in-radius Look_Vision with [gender = 1]
      let tempA max-one-of potentiallist [looks]
      let theirlooks 0
      ask tempA [
        set theirlooks looks
      ]
      if (theirlooks >= looks ); and (theirlooks <= (looks + drinkcount * 3 ))
      [
        set crush tempA 
      ]
    ]
  ]
  
  if (gender = 1)
  [
    if (crush = nobody) and (any? customers in-radius Look_Vision with [gender = 0])
    [
      let potentiallist customers in-radius Look_Vision with [gender = 0]
      let tempA max-one-of potentiallist [looks]
      let theirlooks 0
      ask tempA [
        set theirlooks looks
      ]
      if (theirlooks > looks); and (theirlooks < (looks + drinkcount * 3))
      [
        set crush tempA  
      ]
    ]
  ]
  if (crush != nobody)
  [
    face crush
    if (any? customers in-radius 5 = crush)
    [
      right random-float 90
    ] 
  ]
end 

;;////////////////////////////////////////////////////////////////////////////////////////////////

to Walkabout
forward random-float 1
end 

;;////////////////////////////////////////////////////////////////////////////////////////////////

to ConsumeDrink
  let waste drinkhand
  set drinkhand (drinkhand * drinkconsume) 
  set waste ((waste - drinkhand) / rate)
  set bladderrate bladderrate + waste  
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to WhereIsCrowd
  ask crowd [
    set swarm 10]
  diffuse swarm 0.75
  RecolorCrowd
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to RecolorCrowd
  ask patches with [swarm > 0]
   [
     if (openspace = 1)
     [
       set pcolor scale-color red swarm 0 10
     ]
   ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to BathRoomFunction
  if (patch-here = bathroom) 
  [
    set bladderrate (bladderrate / (1 + random 20))
  ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to BarCounterFunction [Coordinates]
  let BC 0

  if (patch-here = Coordinates) 
  [

    ask patch-here
      [
        ifelse (drinkpoints > 25)
        [
          
          set drinkpoints 0
          set BC 25
        ][
       
        set BC drinkpoints
        set drinkpoints 0
        ]
      ]
    set drinkhand drinkhand + BC
    set drinkcount drinkcount + (BC / 25)
    ifelse (BC < 25)
      [
        let pvalue (random 21) + 5
        let pathvalue patch (10 + random 10) (52) 
        let ranvalue (random-float 1) * pvalue
        let PowNew rebuildlist(power)
        let PatNew rebuildlist(path)
        let RanNew rebuildlist(powerrank)
        set PowNew lput pvalue PowNew
        set PatNew lput pathvalue PatNew
        set RanNew lput ranvalue RanNew       
        set power PowNew
        set path PatNew
        set powerrank RanNew
        calculateranking
      ][ set power lput [BC] of patch-here power
      set power but-first power
      set path lput patch-here path
      set path but-first path
      calculateRanking
      ]
     
  ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to CalculateRanking
  let n 0
  let large patch-here
  let x1 0
  let y1 0
  let mydist 0
  let distrank (list 0 0 0 0 0)
  while [n < 5]
  [
    set large item n path
    ask large [ 
      set x1 pxcor
      set y1 pycor
    ]
    set mydist distancexy x1 y1  
    set mydist (1.00 / (mydist + .1))
    set distrank lput mydist distrank
    set distrank but-first distrank
    set n n + 1
  ]
  set powerrank (map + (distrank)(power))
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to-report Rebuildlist [finlist]
  let T1 sublist finlist 0 placeinlist
  let T2 sublist finlist (placeinlist + 1) 5  
  let R 5 - (length T1) - 1
  let i 0
  while [i < R]
  [
    set T1 lput (item i T2) T1 
    set i i + 1
  ]    
  report T1
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to UseMemory
  let n 0
  let current 0
  let large 0
  let pos1 0
  while [n < 5]
  [
    set large item n powerrank
    if ( large > current)
    [
      set pos1 n
      set current large
    ]
    set n n + 1
  ]
  ifelse (current > 0)
  [ 
    set BarCoordinates item pos1 path
    set placeinlist pos1
  ][checkobstacle]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Staff-routine
  ifelse (currentdrinks < 5)
  [
    set color blue
    makedrinks
  ][
    set color white
    placedrinks
  ]
end 

;;///////////////////////////////////////////////////////////////////////////////////////////////

to Makedrinks
  if (drinkmakingrate > 1)
  [
    ifelse (drinkmakingrate > 2)
    [
      ifelse (drinkmakingrate > 4)
      [
        ifelse (drinkmakingrate > 6)
        [
          ifelse (drinkmakingrate > 8)
          [
            ifelse (drinkmakingrate > 10)
            [
              ifelse (drinkmakingrate > 12)
              [
                ifelse (drinkmakingrate > 14)
                [
                  ifelse (drinkmakingrate > 16)
                  [
                    ifelse (drinkmakingrate > 18)
                    [
                      set currentdrinks currentdrinks + (40 + random 11)
                    ][set currentdrinks currentdrinks + (30 + random 11)]
                  ][set currentdrinks currentdrinks + (25 + random 6)]
                ][set currentdrinks currentdrinks + (20 + random 6)]
              ][set currentdrinks currentdrinks + (15 + random 6)]
            ][set currentdrinks currentdrinks + (10 + random 6)]
          ][set currentdrinks currentdrinks + (6 + random 5)]
        ][set currentdrinks currentdrinks + (4 + random 3)]
      ][set currentdrinks currentdrinks + (1 + random 4)]
    ][set currentdrinks currentdrinks + (1 + random 2)]
  ]
end 

;;////////////////////////////////////////////////////////////////////////////////////////////////

to Placedrinks
  let DrinkPlace nobody
  let oldp patch-here
  ifelse ([pcolor] of patch-ahead 1 = 6) and (not any? turtles-on patch-ahead 1)
    [
      forward 1
      if(any? patches in-cone 3 160 with [pcolor = 35])
      [
        let Pdrinks currentdrinks
        ask patches in-cone 3 160
          [
            if (barcounter = 1)
            [
              set DrinkPlace min-one-of patches [distance myself]
            ]
          ] 
        ask DrinkPlace [
          if (any? customers in-radius 5) and (drinkpoints < 50)
            [          
              set drinkpoints drinkpoints + Pdrinks
              set Pdrinks 0
            ]
        ]
        set currentdrinks Pdrinks
      ]
      left random-float 360
    ]
    [ 
      ifelse ([pcolor] of patch-ahead 1 = 9.9)
      [
        right random-float 180
      ][
      ]
    ]
  let newp patch-here
  if (oldp = newp)
    [
      let space1 patch-here
      ask neighbors with [pcolor = 6][
        set space1 min-one-of patches [distance myself]
      ]
      face space1
      forward 1
    ]
end 

There is only one version of this model, created over 10 years ago by John Shull.

Attached files

File Type Description Last updated
Bar_floor_plan.txt data Text File for coordinates related to the 'Default' settings over 10 years ago, by John Shull Download
dance_floor.txt data Text file for coordinates related to the 'Default' settings over 10 years ago, by John Shull Download

This model does not have any ancestors.

This model does not have any descendants.