Lexington Land Battle
Model was written in NetLogo 6.0.4
•
Viewed 204 times
•
Downloaded 20 times
•
Run 0 times
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-armies ;; a way to count all soldiers on both sides of the battle ] breed [ Csoldiers a-Csoldier ] breed [ Britsoldiers a-Bsoldier ] breed [ Ccommanders a-Ccommander ] breed [ Britcommanders a-Bcommander ] 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 origin ;; this variable is used to calculate distances the soldiers are from enemies ] ; ======================== Setup ==================== to setup clear-all reset-ticks make-battlefield ;; this puts the soldiers into rows and places the commanders at the back of the columns set-distance-from-front ;; this establishes the origin for each soldier end ;; In the following proceedures, soldiers 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 soldiers on each side if that switch is turned on. ;; These setup instructions are the same for the commanders to make-battlefield set-default-shape Csoldiers "person" set-default-shape Britsoldiers "person" set-default-shape Britcommanders "chess knight" set-default-shape Ccommanders "chess knight" set two-armies turtles with [ breed = "Csoldiers" or breed = "Britsoldiers" ] make-Csoldiers make-Ccommanders make-Britsoldiers make-Britcommanders end to make-Csoldiers create-Csoldiers militia_size [ setxy (random -10 - 3) (random 16 + random -16) set heading 90 set color blue ifelse Start_Morale_Equal? [ set morale Starting_Desire_to_Fight_militia - random 30 ] [ set morale (random 50) + 10 ] ] end to make-Ccommanders create-Ccommanders Num_Militia_Commanders [ setxy -15 (random 10 + random -10) set heading 90 set size 2 set color blue ] end to make-Britsoldiers create-Britsoldiers British_Army_Size [ setxy (random 10 + 3) (random 16 + random -16) ;could use (world-height * who / militia_size) ?? set heading 270 set color red ifelse Start_Morale_Equal? [ set morale Starting_Desire_to_Fight_militia - random 30 ] [ set morale (random 50) + 10 ] ] end to make-Britcommanders create-Britcommanders Num_British_Commanders [ set shape "chess knight" setxy 15 (random 10 + random -10) ; if any? turtles touching, move +1 on y axis set size 2 set heading 270 set color red ] end to set-distance-from-front ask turtles [ set origin [ xcor ] of self ] end ;======================== Go ======================== to go visualize-morale ;; this changes the shading of each soldier to show the user the morale spread fight-soldiers ;; this is the set of commands that tell soldiers how much damage to take from battle give-commands ;; this set of commands is how the Commanders "instruct" their troops declare-winner ;; this displays a message to a user when a side of the battle has won 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 Britsoldiers [ set color scale-color red morale -50 150] ask Csoldiers [ set color scale-color blue morale -50 150 ] ] ] end ;; this is how commanders instruct their soldiers. The instructions are seen as positive to morale. ;; Commander_skill tells how often orders go out. ;; Commander_influences effects how far the cone directs the message of positive morale ;; morale is capped at 100 because the color-scaling gets washed out to give-commands every (20 / commander_skill) [ ask Britcommanders [ ask Britsoldiers in-cone (commander_influence * 1.5) 180 [ set morale (morale + (training_level / 2)) if morale > 100 [ set morale 99 ] ] ] ask Ccommanders [ ask Csoldiers in-cone (commander_influence * 1.5 ) 180 [ 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 soldiers left, commanders are not counted to declare-winner if (count Csoldiers <= 0) or (count Britsoldiers <= 0) [ ifelse count Csoldiers < count Britsoldiers [ user-message (word "the British have won this battle with " count Britsoldiers " left") ] [ user-message (word "the Colonists have won this battle with " count Csoldiers " left")] ] end ;==================================== Soldier Rules ================================= to fight-soldiers take-damage desert end ;; take-damage simulates soldiers getting wounded in battle. to take-damage ;; prevents damage before battle is set up completely ;; continues every 2 seconds if ticks >= 4 [ every 2 [ ask Britsoldiers [ ;; this makes the damage random based on distance from enemy (bullets were highly innacurate) set damage (random 50 / abs origin ) ;; 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 soldiers nearby if damage >= 7 [ let die-chance random 100 if die-chance >= 70 [ die ] damage-other-brit ] if morale >= 90 [morale-up-other-brit ] ] ;; this is the same code as above but for Milita soldiers ask Csoldiers [ set damage ( random 50 / abs origin ) 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-brit ;; this lowers morale when you see your neighbor get damage ask Britsoldiers 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 Csoldiers in-cone 10 360 [ set morale (morale + .5) if morale > 100 [ set morale 99 ] ] end to morale-up-other-brit ;; this allows soldiers to ride your momentum and get some morale from your success ask Britsoldiers 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-brit ask Csoldiers in-cone ( training_level / 2 ) 360 [ set morale morale - 1] ask Britsoldiers 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-brit ask Csoldiers in-cone (training_level / 2 ) 360 [ set morale (morale + (training_level / 4 )) if morale > 100 [ set morale 99 ] ] end ;; desert causes soldiers with very low morale to leave the battlefield to desert if ticks >= 10 [ ask Britsoldiers [ if morale <= 1 [ die ] ] ask Csoldiers [ if morale <= 1 [ die ] ] ] end
There is only one version of this model, created almost 6 years ago by Wade Berger.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Lexington Land Battle.png | preview | Preview for 'Lexington Land Battle' | almost 6 years ago, by Wade Berger | Download |
This model does not have any ancestors.
This model does not have any descendants.