Systèmes Complexes : Une introduction par la pratique

Le site web du livre

Atelier 2 : Automates cellulaires

Liens directs au sous-sections :

haut

2.2 Automates cellulaires à une dimension

patches-own [ 
  etat 
]

to setup 
   clear-all
   ask patches [
      set pcolor grey
   ] 
   ask patches with [pycor = max-pycor] [
      ifelse (random 2 = 0) [set etat 1] [set etat 0]
   ]
   colorier 
   reset-ticks  
end

to-report nouvel-etat-opinion [gauche centre droit]
   ifelse (droit = gauche) 
      [report gauche] [report centre] 
end

to-report nouvel-etat-routier [gauche centre droit]
     ifelse (gauche = 0) and (centre = 1) and (droit = 0)
     	[report 0] [ 
     ifelse (gauche = 1) and (centre = 0) and (droit = 0) 
     	[report 1] [
     ifelse (gauche = 1) and (centre = 0) and (droit = 1) 
     	[report 1] [
     ifelse (gauche = 1) and (centre = 1) and (droit = 0) 
     	[report 0] [
     	report centre]]]]
end

to go
  tick
  ; ask patches with [pycor = max-pycor - ticks and 
  ;	pxcor > min-pxcor and  pxcor < max-pxcor ]
  ask patches with [pycor = max-pycor - ticks ][
      let gauche 
      	[etat] of patch-at -1 1      
      let centre 
      	[etat] of patch-at 0 1 
      let droit  
      	[etat] of patch-at 1 1 
      set etat (nouvel-etat gauche centre droit)      
   ]
   ; ask patch  min-pxcor (max-pycor - ticks) [ set etat 1 ] 
   ; ask patch  max-pxcor (max-pycor - ticks) [ set etat 0 ] 

   colorier
   if (ticks >= max-pycor - min-pycor) [stop]
end

to colorier
   ask patches with [ pycor = max-pycor - ticks ] [
      ifelse (etat = 1) [set pcolor black] [set pcolor white]
   ]
end
	     

haut

2.3 Le jeu de la vie

patches-own [
	etat     
	nbVoisins
]

to setup 
   clear-all
   ask patches [
      ifelse (random 100 < densite) [set etat 1] [set etat 0] 
    ]
   colorier
   reset-ticks  
end 

to colorier 
   ask patches [
      ifelse (etat = 0) [set pcolor white] [set pcolor red]
   ]
end

to go
   ask patches [
     set nbVoisins count neighbors with [etat = 1]
   ]
   ask patches [
     ifelse etat = 0 
        [if nbVoisins = 3 [set etat 1 ]]
        [if nbVoisins < 2               
         or nbVoisins > 3               
              [set etat 0]]
   ]
   colorier
   tick
end

	     

haut

2.4 Jeux évolutionnaires spatiaux

patches-own [
  strategie 
  old-strategie 
  score 
  nb-voisins-1
]

to setup
  clear-all
  ask patches [
    ifelse random-float 1 < p_init 
      [set strategie 1] 
      [set strategie 2]
  ]
  colorier
  reset-ticks
end

to colorier
  ask patches [
    ifelse strategie = 1 
      [set pcolor white]
      [set pcolor black]
  ]
end

to go
   ask patches [
     set nb-voisins-1 count neighbors4 with [strategie = 1]]    
   ask patches [set old-strategie strategie]
   ask patches [set score new-score] 
   ask patches [set strategie new-strategie]
   colorier    
   tick
end

to-report new-score 
 ifelse strategie = 1
  [ report 
    ((a-1-1 * nb-voisins-1) + (a-2-1  * (4 - nb-voisins-1))) ]
  [ report 
    ((a-1-2 * nb-voisins-1) + (a-2-2  * (4 - nb-voisins-1))) ]
end

to-report new-strategie 
  let voisins-etendu (patch-set self neighbors4)
  let voisins-max (voisins-etendu with-max [score])    
  ifelse any? voisins-max with [ old-strategie = [old-strategie] of myself ] 
     [ report old-strategie ]
     [ report 3 - old-strategie ]   
end

	     

haut