Conway’s Game of Life

Conway’s Game of Life preview image

1 collaborator

Tags

cellular automaton 

Tagged by Jaroslaw Miszczak 6 months ago

game of life 

Tagged by Jaroslaw Miszczak 6 months ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.1 • Viewed 79 times • Downloaded 3 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 5 months ago Simplified update Download this version
Jaroslaw Miszczak 6 months 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' 6 months ago, by Jaroslaw Miszczak Download

This model does not have any ancestors.

This model does not have any descendants.