Conway’s Game of Life

Conway’s Game of Life preview image

1 collaborator

Tags

cellular automaton 

Tagged by Jaroslaw Miszczak almost 3 years ago

game of life 

Tagged by Jaroslaw Miszczak almost 3 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.1 • Viewed 270 times • Downloaded 15 times • Run 0 times
Download the 'Conway’s Game of Life' 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)
  set-patch-size floor ( 50 / (sqrt world-size) )

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

;;
;; main function
;;

to go
  ifelse synchronous [
    ask patches [
      simulate-life
    ]
    ask patches [
      update-color
    ]
  ][
    ask patches [
      simulate-life
      update-color
    ]
  ]

  tick
end 

;;
;; calculate the updating rule
;; and save it the next state
;;

to  simulate-life
  let x (count neighbors with [ pcolor = green] )

  ;; set plabel x ;; [debug]

  ifelse pcolor = green [
    ifelse x < 2 or x >= 4 [ ;; x>=4 (weak inequality) - standard rule
      set next-pcolor white ;; ie. die
    ][
      set next-pcolor green ;; ie. stay alive
    ]
  ][ ;; pcolor = white
    if x = 3 [
      set next-pcolor green ;; ie. live
    ]
  ]
end 

;;
;; update the state
;;

to update-color
  set pcolor next-pcolor
end 

There are 2 versions of this model.

Uploaded by When Description Download
Jaroslaw Miszczak almost 3 years ago Simplified update Download this version
Jaroslaw Miszczak almost 3 years ago Initial upload Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.