Battle of the Chesapeake

Battle of the Chesapeake preview image

1 collaborator

Default-person Wade Berger (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.4 • Viewed 366 times • Downloaded 19 times • Run 0 times
Download the 'Battle of the Chesapeake' 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

Globals [
  two-navies         ;; a way to count all ships on both sides of the battle
  ran-ship           ;; picks a random ship to show in the monitor
  ran-enemyship      ;; picks a random enemy ship to show in the monitor
]

breed [ ships a-ship ]
breed [ enemyships a-enemyship ]
breed [ admirals a-admiral ]
breed [ smokeclouds a-smokecloud ]

turtles-own [
  morale            ;; this is the desire to fight of each soldier
  damage            ;; this is a simulation of bullets. It is not visualized to keep from distracting the model user
  target            ;; this variable is used to aim at enemy ships
]

patches-own [
  crowded-seas
]

; ======================== Setup ====================

to setup
  clear-all
  reset-ticks
  make-battlefield               ;; this puts the ships into rows and places the admirals at the back of the columns
  make-ran-ships
end 

;; In the following proceedures, ships are given an initial xy cor based in columns,
;; given a initial color to denote their side of the battle,
;; and given an initial morale. This morale value is equal for all ships on each side if that switch is turned on.
;; These setup instructions are the same for the admirals

to make-battlefield
  set-default-shape turtles "boat top"
  set two-navies turtles with [ breed = "Ships" or breed = "enemyships" ]
  make-Ships
  make-admirals
  make-enemyships
  ask patches [
    set pcolor 89
    set crowded-seas patches in-radius 3
  ]
end 

to make-Ships
  create-Ships Navy-Size [
    setxy (random -10 - 3) (random 16 + random -16)
    set size 3
    set heading 90
    set color blue
    ifelse Start_Morale_Equal? [ set morale Starting_Desire_to_Fight_Ships - random 30 ]
      [ set morale (random 50) + 10 ]
  ]
end 

to make-admirals
  create-admirals Num-Admirals [
    setxy -15 (random 10 + random -10)
    set heading 90
    set size 4
    set color blue
    ifelse Start_Morale_Equal? [ set morale Starting_Desire_to_Fight_Ships - random 30 ]
      [ set morale (random 50) + 10 ]
  ]
end 

to make-enemyships
  create-enemyships Enemy-Navy-Size [
    setxy (random 10 + 3) (random 16 + random -16) ;could use (world-height * who / militia_size) ??
    set size 3
    set heading 270
    set color red
    ifelse Start_Morale_Equal? [ set morale Starting_Desire_to_Fight_Ships - random 30 ]
      [ set morale (random 50) + 10 ]
  ]
end 

to make-ran-ships
  set ran-ship random navy-size
  set ran-enemyship random enemy-navy-size
end 


;======================== Go ========================

to go
  visualize-morale   ;; this changes the shading of each soldier to show the user the morale spread
  fight-ships    ;; this is the set of commands that tell ships how much damage to take from battle
  give-commands      ;; this set of commands is how the admirals "instruct" their fleet
  declare-winner     ;; this displays a message to a user when a side of the battle has won
  generate-smoke     ;; creates smoke from cannon fire on the battle field that ships avoid and increases confusion
  tick
end 

; ====================== Code =======================

;; this scales the colors based on the morale of each soldier. This doesn't happen on the first tick,
;; and it rechecks every .25 seconds
;; darker shades = low morale
;; lighter shades = high morale

to visualize-morale
  every .25 [
    ifelse ticks <= 1 [stop] [
      ask enemyships [ set color scale-color red morale -50 150]
      ask Ships [ set color scale-color blue morale -50 150 ]
      ask admirals [ set color scale-color blue morale -50 150 ]
    ]
  ]
end 

;; this is how admirals instruct their fleet. The instructions are seen as positive to morale.
;; admiral_skill tells how often orders go out.
;; admiral_influences effects how far the cone directs the message of positive morale, in the naval battle this goes out in 360 degrees
;; morale is capped at 100 because the color-scaling gets washed out

to give-commands
  float
  every (20 / admiral-skill) [
    ask admirals [
      ask Ships in-cone (Admiral-influence * 2.5 ) 360 [
        set morale (morale + (training_level / 2))
        if morale > 100 [ set morale 99 ]

      ]
    ]
  ]
end 

;; this displays a message to the user when one of the armies has no ships left, admirals are not counted

to declare-winner
  if (count Ships <= 0) or (count enemyships <= 0) [
    ifelse count Ships < count enemyships [ user-message (word "the British have won this battle with " count ships " Colonist ship(s) surrendering") ]
    [ user-message (word "the Colonists have won this battle with " count enemyships " British ship(s) surrendering")]
  ]
end 

to generate-smoke
  every 4 [
    create-smokeclouds random 2
    ask smokeclouds [
      setxy random-xcor random-ycor
      set shape "cloud"
      set color grey
      set size 5
      if count smokeclouds >= 10 [ die ]
    ]
  ]
end 



;==================================== Soldier Rules =================================

to fight-ships
  float
  take-damage
  desert
end 

to float
  every .5 [
    ask enemyships [
      ifelse any? other turtles in-cone 5 20 [ rt 90 fd 1 ] [ rt -20 fd 2 ]
      if any? other turtles in-cone .5 360 [ set damage damage + .5]
      if any? other enemyships in-cone 2 360 [set morale morale + 10]
    ]
    ask ships [
      ifelse any? other turtles in-cone 5 20 [ rt 90 fd 1 ] [ rt -20 fd 2 ]
      if any? other turtles in-cone .5 360 [ set damage damage + .5]
    ]
    ask admirals [
      ifelse any? other turtles in-cone 5 20 [ rt 90 fd 1 ] [ rt -20 fd 2 ]
      if any? other turtles in-cone .5 360 [ set damage damage + .5]
    ]
  ]
end 

;; take-damage simulates ships getting wounded in battle.

to take-damage
  ;; prevents damage before battle is set up completely
  ;; continues every 2 seconds
  if ticks >= 4 [
    ; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx collision damage ask patch-here if turtles-on = 2
    every 2 [
      ask enemyships [
        ;; this makes the damage random based on distance from enemy (bullets were highly innacurate)
        set damage (random 10 )
        ;; if damage is high, it effects the soldier's morale
        if damage >= 5 [set morale (morale - 10) ]
        ;; if damage is really high, the soldier may die, also this effects the morale of other ships nearby
        if damage >= 7 [
          let die-chance random 100
          if die-chance >= 70 [ die ]
          damage-other-enemy ]
        if morale >= 90 [morale-up-other-enemy ]
      ]
      ;; this is the same code as above but for ships
      ask Ships [
        set damage ( random 10)
        if damage >= 5 [set morale (morale - 10) ]
        if damage >= 7 [
          let die-chance random 100
          if die-chance >= 70 [ die ]
          damage-other-militia ]
        if morale >= 90 [ morale-up-other-militia ]
      ]
      ask admirals [
        set damage ( random 10)
        if damage >= 5 [set morale (morale - 10) ]
        if damage >= 7 [
          let die-chance random 100
          if die-chance >= 70 [ die ]
          damage-other-militia ]
        if morale >= 90 [ morale-up-other-militia ]
      ]
    ]
  ]
end 

to damage-other-enemy
;; this lowers morale when you see your neighbor get damage
  ask enemyships in-cone (training_level / 2) 360  [ set morale morale - 1]
;; also we want the damage to be recognized by the other side,
;; so this next code increases moral when damage is delt
  ask Ships in-cone 10 360 [
    set morale (morale + .5)
    if morale > 100 [ set morale 99 ]
  ]
end 

to morale-up-other-enemy
;; this allows ships to ride your momentum and get some morale from your success
  ask enemyships in-cone (training_level / 2) 360 [
    set morale (morale + (training_level / 4 ))
;; this next line makes sure morale never goes over 100
    if morale > 100 [ set morale 99 ]
  ]
end 

to damage-other-militia
;; this code is the Milita version of damage-other-enemy
  ask Ships in-cone ( training_level / 2 ) 360 [ set morale morale - 1]
  ask enemyships in-cone 10 360 [
    set morale (morale + .5)
    if morale > 100 [ set morale 99 ]
  ]
end 

to morale-up-other-militia
;; this code is the Milita version of morale-up-other-enemy
  ask Ships in-cone (training_level / 2 ) 360 [
    set morale (morale + (training_level / 4 ))
    if morale > 100 [ set morale 99 ]
  ]
end 


;; desert causes ships with very low morale to leave the battlefield

to desert
  if ticks >= 10 [
    ask enemyships [
      if morale <= 1 [ die ]
    ]
    ask Ships [
      if morale <= 1 [ die ]
    ]
  ]
end 

There is only one version of this model, created over 5 years ago by Wade Berger.

Attached files

File Type Description Last updated
Battle of the Chesapeake.png preview Preview for 'Battle of the Chesapeake' over 5 years ago, by Wade Berger Download

This model does not have any ancestors.

This model does not have any descendants.