Skip to content

Instantly share code, notes, and snippets.

@Bouhnosaure
Last active October 9, 2015 07:54
Show Gist options
  • Save Bouhnosaure/be553aacb1edfb920617 to your computer and use it in GitHub Desktop.
Save Bouhnosaure/be553aacb1edfb920617 to your computer and use it in GitHub Desktop.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VARIABLES GLOBALES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
breed [capteurs capteur]
breed [habitants habitant]
breed [batiments batiment]
breed [capteursTemperature capteurTemperature]
breed [capteursPresence capteurPresence]
breed [radiators rad]
globals [detection]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VARIABLES DES AGENTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
capteursTemperature-own [
temperature
]
capteursPresence-own [
but
xmin
ymin
xplus
yplus
]
habitants-own [
new-heading
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;INITIALISATION DE L'ARRIERE PLAN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
clear-all
reset-ticks
set default_temp 20
ask patches [
setup-world
]
setup-agents
detect-piece
ask habitants [capter]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TEMPERATURE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CREATION DES AGENTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-agents
create-habitants 1 [
set shape "person"
setxy xcor -5
setxy ycor 15
set size 3
set color black
set heading 90
]
create-capteursPresence 1 [
set shape "box"
setxy xcor 15
setxy ycor 25
set size 2
set color blue
set xmin 0
set ymin 0
set xplus 0
set yplus 0
]
create-capteursPresence 1 [
set shape "box"
setxy xcor 1
setxy ycor 25
set size 2
set color blue
set xmin 0
set ymin 0
set xplus 0
set yplus 0
]
create-capteursPresence 1 [
set shape "box"
setxy xcor -23
setxy ycor 7
set size 2
set color blue
set xmin 0
set ymin 0
set xplus 0
set yplus 0
]
create-capteursPresence 1 [
set shape "box"
setxy xcor 6
setxy ycor 6.5
set size 2
set color blue
set xmin 0
set ymin 0
set xplus 0
set yplus 0
]
create-capteursPresence 1 [
set shape "box"
setxy xcor 9
setxy ycor -13.5
set size 2
set color blue
set xmin 0
set ymin 0
set xplus 0
set yplus 0
]
create-capteursPresence 1 [
set shape "box"
setxy xcor 28.5
setxy ycor 13.5
set size 2
set color blue
set xmin 0
set ymin 0
set xplus 0
set yplus 0
]
create-radiators 1 [
set shape "container"
setxy xcor 6
setxy ycor -13.5
set size 2
set color blue
set label "1"
]
create-radiators 1 [
set shape "container"
setxy xcor -23
setxy ycor 5
set size 2
set color blue
set label "2"
]
create-radiators 1 [
set shape "container"
setxy xcor -2
setxy ycor 25
set size 2
set color blue
set label "3"
]
create-radiators 1 [
set shape "container"
setxy xcor 3
setxy ycor 6.5
set size 2
set color blue
set label "4"
]
create-radiators 1 [
set shape "container"
setxy xcor 18
setxy ycor 25
set size 2
set color blue
set label "5"
]
create-radiators 1 [
set shape "container"
setxy xcor 26
setxy ycor 13.5
set size 2
set color blue
set label "6"
]
create-capteursTemperature 1 [
set shape "square"
setxy xcor -23
setxy ycor 9
set size 2
set color white
set label-color black
set temperature min_temp + random 2
set label temperature
]
create-capteursTemperature 1 [
set shape "square"
setxy xcor 4
setxy ycor 25
set size 2
set color white
set label-color black
set temperature min_temp + random 2
set label temperature
]
create-capteursTemperature 1 [
set shape "square"
setxy xcor 9
setxy ycor 6.5
set size 2
set color white
set label-color black
set temperature min_temp + random 2
set label temperature
]
create-capteursTemperature 1 [
set shape "square"
setxy xcor 11.5
setxy ycor -13.5
set size 2
set color white
set label-color black
set temperature min_temp + random 2
set label temperature
]
create-capteursTemperature 1 [
set shape "square"
setxy xcor 20.5
setxy ycor 25
set size 2
set color white
set label-color black
set temperature min_temp + random 2
set label temperature
]
create-capteursTemperature 1 [
set shape "square"
setxy xcor 23.5
setxy ycor 13.5
set size 2
set color white
set label-color black
set temperature min_temp + random 2
set label temperature
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LANCEMENT DU SCENARIO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
capter
tick
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CREATION DU PLAN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-world
set pcolor white
;; REZ DE CHAUSSEE;;;;;;;;;;;;;;;;
if ( pycor = -15 ) and ( pxcor < 30 and pxcor > -25 ) [ set pcolor grey ] ;; mur du bas (exterieur)
if ( pxcor = -25 ) and ( pycor < 28 and pycor > -16 ) [ set pcolor grey ] ;; mur de gauche (exterieur)
if ( pxcor = 30 ) and ( pycor < 28 and pycor > -16 ) [ set pcolor grey ] ;; mur de droite (exterieur)
if ( pycor = 27 ) and ( pxcor < 30 and pxcor > -25 ) [ set pcolor grey ] ;; mur du haut (exterieur)
if ( pycor = 5 ) and ( pxcor < 13 and pxcor > -3 ) [ set pcolor grey ] ;; mur du haut (exterieur)
if ( pxcor = 13 ) and ( pycor < 28 and pycor > -16 ) [ set pcolor grey ] ;; mur de gauche (exterieur)
if ( pycor = 15 ) and ( pxcor < 30 and pxcor > -4 ) [ set pcolor grey ] ;; mur du 3eme droite horizontale (exterieur)
if ( pxcor = -3 ) and ( pycor < 6 and pycor > -16 ) [ set pcolor grey ] ;; mur de droite (exterieur)
if ( pxcor = 0 ) and ( pycor < 16 and pycor > 4 ) [ set pcolor grey ] ;; mur de droite (exterieur)
if ( pycor = -15 ) and ( pxcor < 28 and pxcor > 15 ) [ set pcolor blue ] ;; porte garage
if ( pxcor = 13 ) and ( pycor < 25 and pycor > 20 ) [ set pcolor blue ] ;; porte cuisine
if ( pxcor = 13 ) and ( pycor < 25 and pycor > 20 ) [ set pcolor blue ] ;; porte cuisine
if ( pxcor = -3 ) and ( pycor < 4 and pycor > -1 ) [ set pcolor blue ] ;; porte chambre
if ( pycor = 15 ) and ( pxcor < 20 and pxcor > 15 ) [ set pcolor blue ] ;; porte garage
if ( pxcor = 0 ) and ( pycor < 14 and pycor > 10 ) [ set pcolor blue ] ;; porte salle de bain (exterieur)
if ( pycor = -15 ) and ( pxcor < -8 and pxcor > -14 ) [ set pcolor blue ] ;; porte entrée (exterieur)
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MOUVEMENTS DE L'HUMAIN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to habitants-move-up
ask habitants [
set heading 0
habitants-move
capter
]
end
to habitants-move-right
ask habitants [
set heading 90
habitants-move
capter
]
end
to habitants-move-down
ask habitants[
set heading 180
habitants-move
capter
]
end
to habitants-move-left
ask habitants[
set heading 270
habitants-move
capter
]
end
;; turtle move if is possible
to habitants-move
if [pcolor] of patch-ahead 1 != grey[
forward 1
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DETECTION DE LA PIECE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to detect-piece
ask capteursPresence
[
let result true
let i 0
let colorPath white
while [colorPath != grey]
[
ask patch-at 0 i [
ifelse ( pcolor = grey )
[
set colorPath grey
]
[
set i i - 1
]
]
]
set ymin i
set i 0
set colorPath white
while [colorPath != grey]
[
ask patch-at 0 i [
ifelse ( pcolor = grey )
[
set colorPath grey
]
[
set i i + 1
]
]
]
set yplus i
set i 0
set colorPath white
while [colorPath != grey]
[
ask patch-at i 0 [
ifelse ( pcolor = grey )
[
set colorPath grey
]
[
set i i - 1
]
]
]
set xmin i
set i 0
set colorPath white
while [colorPath != grey]
[
ask patch-at i 0 [
ifelse ( pcolor = grey )
[
set colorPath grey
]
[
set i i + 1
]
]
]
set xplus i
set xmin xcor + xmin
set xplus xcor + xplus
set ymin ycor + ymin
set yplus ycor + yplus
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CAPTEUR EN ACTION ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to capter
ask habitants
[
ask capteursPresence
[
ifelse ([xcor] of myself < xplus and [xcor] of myself > xmin ) and ( [ycor] of myself < yplus and [ycor] of myself > ymin )
[
set color green
ask capteursTemperature in-radius 6[
if ticks mod 60 = 0 [
ifelse ( temperature < default_temp )[
set temperature temperature + 0.5
set label precision temperature 1
ask radiators in-radius 6[
set color red
output-print (word (word "radiateur n°" label) " - action : Je m'allume")
]
][
set temperature temperature - 0.1
set label precision temperature 1
ask radiators in-radius 6[
set color red
output-print (word (word "radiateur n°" label) " - action : Je m'eteinds")
]
]
]
]
]
[
set color blue
ask capteursTemperature in-radius 6[
if ticks mod 60 = 0 [
ifelse ( temperature < min_temp )[
set temperature temperature + 0.1
set label precision temperature 1
ask radiators in-radius 6[
set color red
output-print (word (word "radiateur n°" label) " - action Je m'allume: ")
]
][
set temperature temperature - 0.1
set label precision temperature 1
ask radiators in-radius 6[
set color blue
output-print (word (word "radiateur n°" label) " - action : Je m'eteinds")
]
]
ask radiators in-radius 6
[
output-print (word (word "radiateur n°" label) " - action : Je ne fais rien")
set color blue
]
]
]
]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VARIABLES DES AGENTS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to ouvrir-volet
output-print "capteur[Volets] je peux ouvrir les volets"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment