Conway's Game of Life with rule switching

Conway's Game of Life with rule switching preview image

1 collaborator

Tags

cellular automata 

Tagged by Jaroslaw Miszczak about 1 year ago

game of life 

Tagged by Jaroslaw Miszczak about 1 year ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.3.0 • Viewed 188 times • Downloaded 15 times • Run 0 times
Download the 'Conway's Game of Life with rule switching' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

patches-own [
  next-pcolor ;; the next state is calculated using current pcolor
]

;; clear the board and create some life

to setup
  clear-all
  reset-ticks

  ;; make the world with custom size
  resize-world 0 (world-size - 1) 0 (world-size - 1)

  ;; heuristic scaling of the patch size
  set-patch-size floor ( 50 / (sqrt world-size) )

  ;; use next-pcolor to initialize pcolor
  ask patches [
    ifelse random 100 < init-life [
      set next-pcolor black
    ][
      set next-pcolor white
    ]
    set pcolor next-pcolor
  ]
end 

;;
;; main function
;;

to go

  ifelse synchronous [
    ask patches [
      simulate-life
    ]
    ask patches [
      update-state
    ]
  ][
    ask patches [
      simulate-life
      update-state
    ]
  ]

  tick
end 

;;
;; calculate the updating rule
;;

to  simulate-life
  ifelse deterministic [ ;; deterministic rule switching
    ifelse ticks mod deterministic-period = 0 [
      update-rule-modified
    ][ ;; ticks mod deterministic-period \= 0
      update-rule-std
    ]
  ][ ;; random rule switching
    ifelse random-float 1 > rule-switch-prob [
      update-rule-std
    ][
      update-rule-modified
    ]
  ]
end 

;;
;; standard update rule for the Game of Life
;;

to update-rule-std
  let x (count neighbors with [ pcolor = black] )

  ifelse pcolor = black [
    ifelse x < 2 or x >= 4 [ ;; x>=4 (weak inequality) - standard rule
      set next-pcolor white ;; ie. die
    ][
      set next-pcolor black ;; ie. stay alive
    ]
  ][ ;; pcolor = white
    if x >= 3 and x < 4 [ ;; modified rule if second-threshold != 4
          set next-pcolor black ;; ie. birth
    ]
  ]
end 

;;
;; update rule with the altered treshold for the overpopulation
;;

to update-rule-modified
  let x (count neighbors with [ pcolor = black] )

  ifelse pcolor = black [
    ifelse x < 2 or x >= second-threshold [ ;; modified rule if second-threshold != 4
      set next-pcolor white ;; ie. die
    ][
      set next-pcolor black ;; ie. stay alive
    ]
  ][ ;; pcolor = white
    if x >= 3 and x < second-threshold [ ;; modified rule if second-threshold != 4
          set next-pcolor black ;; ie. birth
    ]
  ]
end 

;;
;; update the state
;;

to update-state
  set pcolor next-pcolor
end 

;;
;; reporters
;;

;;
;; fraction of living cells
;;

to-report %living
  report 100 * ( count patches with [ pcolor = black] ) / ( count patches )
end 

There is only one version of this model, created almost 2 years ago by Jaroslaw Miszczak.

Attached files

File Type Description Last updated
Conway's Game of Life with rule switching.png preview Preview for 'Conway's Game of Life with rule switching' almost 2 years ago, by Jaroslaw Miszczak Download

This model does not have any ancestors.

This model does not have any descendants.