Heroes vs Bug
Model was written in NetLogo 5.0.5
•
Viewed 261 times
•
Downloaded 27 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
breed [mobs mob] breed [heroes hero] globals[ generation startLife startSpeed startDef startAtk ] heroes-own[ max-life life attack defense target ] mobs-own[ max-life life attack defense ] to Start clear-all clear-output set generation 0 set startLife 100 set startDef 1 set startSpeed 1 set startAtk 1 set-default-shape mobs "bug" set-default-shape heroes "person" ask patches [ init ] reset-ticks end to init ;; patch procedure set pcolor green if not any? heroes [ invoke-heroes-no-parent ] if( random-float 1.0 < hero_spawn / 100 and count turtles-here = 0 ) [ invoke-heroes-no-parent ] initMobs end to invoke-heroes-no-parent sprout-heroes 1 [ set max-life startLife + random-float 2 * random-float life_variation set attack startAtk + random-float 2 * random-float attack_variation set defense startDef + random-float 2 * random-float defense_variation set target nobody set life max-life ] end to invoke-heroes [parent1 parent2] sprout-heroes 1 [ set max-life average [max-life] of parent1 [max-life] of parent2 + random-float life_variation set attack average [attack] of parent1 [attack] of parent2 + random-float attack_variation set defense average [defense] of parent1 [defense] of parent2 + random-float defense_variation set target nobody set life max-life ] end to invoke-mobs sprout-mobs 1 [ set max-life random-float [max-life] of max-one-of heroes [max-life] set attack random-float [attack] of max-one-of heroes [attack] set defense random-float [defense] of max-one-of heroes [defense] set life max-life ] end to go ask heroes [moveHeroes] ask mobs [moveMobs] ask heroes [isDead] ask mobs [isDead] if(count mobs = 0)[ reproduce set generation generation + 1 repopMobs ] if not any? heroes [ stop ] tick end to moveHeroes let attackers self ifelse(target != nobody and ([patch-here] of target = [patch-here] of self or [distance attackers] of target < 2))[ ifelse(random 100 < 50)[ ;; output-print (word "ATTACK: " target " attack " self) ask target [attackTarget attackers] attackTarget target ] [ ;; output-print (word "ATTACK: " self " attack " target) attackTarget target ask target [attackTarget attackers] ] ] [ let nearest-neighbor min-one-of mobs [ distance myself ] set target nearest-neighbor if(target != nobody)[ face target fd 0.5 ] ] end to moveMobs let me self let attacker heroes with [target = me] if( count attacker > 0) [ face one-of attacker fd 0.5 ] end to isDead if(life <= 0)[ die ] end to reproduce ask patches [ if ( random-float 1.0 <= hero_spawn / 100.0 and count turtles-here = 0)[ invoke-heroes one-of heroes one-of heroes ] ] end to repopMobs ask patches [initMobs] end to initMobs if( random-float 1.0 < mob_spawn / 100 and count turtles-here = 0 ) [ invoke-mobs ] end to attackTarget [targetAttack] let damage [attack] of self let defenseTarget (random-float 1.0 * [defense] of targetAttack) let variation damage - defenseTarget ;;output-print (word "DAMAGE: " self " deal " variation " to " targetAttack) if(variation > 0) [ ask targetAttack [set life (life - variation)] ] end to-report average [a b] report (a + b) / 2.0 end
There is only one version of this model, created over 10 years ago by Leo B.
This model does not have any ancestors.
This model does not have any descendants.