Jump to content

Game of Life: Difference between revisions

From SELESwiki
No edit summary
Line 39: Line 39:


===GameOfLife.scn File===
===GameOfLife.scn File===
<pre>
/* This file contains a landscape event definition for Conway's Game of Life */
LSEVENT: GameOfLife


DEFINITIONS
/* This file contains a landscape event definition for Conway's Game of Life */
  LAYER: CellState, PrevCellState
LSEVENT: GameOfLife
  GLOBAL VARIABLE: pInitial
ENDDEF


INITIALSTATE
DEFINITIONS
  INITIALSTATE = 1
    LAYER: CellState, PrevCellState
  CellState = IF UNIFORM(0,1) < pInitial THEN 1 ELSE 0
    GLOBAL VARIABLE: pInitial
ENDIS
ENDDEF
INITIALSTATE
    INITIALSTATE = 1
    CellState = IF UNIFORM(0,1) < pInitial THEN 1 ELSE 0
ENDIS
RETURNTIME
    RETURNTIME = 1
    PrevCellState = CellState
ENDRT
TRANSITIONS
  TRANSITIONS = TRUE


RETURNTIME
  numNeighbs = 0
   RETURNTIME = 1
   OVER REGION CENTRED(1,1.5, EUCLIDEAN)
  PrevCellState = CellState
      DECISION PrevCellState EQ 1
ENDRT
      numNeighbs = numNeighbs + 1
  ENDFN


 
  CellState = IF (CellState EQ 0) AND (numNeighbs EQ 3) THEN 1
TRANSITIONS
  TRANSITIONS = TRUE
 
  numNeighbs = 0
  OVER REGION CENTRED(1,1.5, EUCLIDEAN)
    DECISION PrevCellState EQ 1
    numNeighbs = numNeighbs + 1
  ENDFN
 
  CellState = IF (CellState EQ 0) AND (numNeighbs EQ 3) THEN 1
               ELSE IF (CellState EQ 1) AND (2 <= numNeighbs <= 3) THEN 1
               ELSE IF (CellState EQ 1) AND (2 <= numNeighbs <= 3) THEN 1
               ELSE 0
               ELSE 0
ENDTR
ENDTR
</pre>
 
Comments: more here...
Comments: more here...

Revision as of 19:08, 8 November 2006

Summary

Summary here...

Download Model

Download the .scn, .sel and .lse files by clicking on the following link: File:GameOfLife.zip

Model Code Explanation

In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.

GameOfLife.scn File

Scenario Information           // This statement in the .scn file begins each and every SELES model
GameOfLife.sel                 // This line tells SELES to go and find the correct .sel model file
SimPriority Low Priority       // This line priorizes the modelling process versus other tasks your computer has going. 

Comments: More information on SimPriority can be found in Scenario Reference under Simulation Control.

GameOfLife.sel File

Seles Model
Model Size: 200, 200
Time Units: na Step 1
Landscape Events:
 GameOfLife.lse
Variable-Output View Maps:
 CellState
 PrevCellState
Output Model Bounds:
 CellState: 1
 PrevCellState: 1
Global Variables:
 pInitial = 0.05
Output Frequency: 1

Comments: more here...

GameOfLife.scn File

/* This file contains a landscape event definition for Conway's Game of Life */
LSEVENT: GameOfLife
DEFINITIONS
   LAYER: CellState, PrevCellState
   GLOBAL VARIABLE: pInitial
ENDDEF

INITIALSTATE
   INITIALSTATE = 1
   CellState = IF UNIFORM(0,1) < pInitial THEN 1 ELSE 0
ENDIS

RETURNTIME
   RETURNTIME = 1
   PrevCellState = CellState
ENDRT


TRANSITIONS
  TRANSITIONS = TRUE
  numNeighbs = 0
  OVER REGION CENTRED(1,1.5, EUCLIDEAN)
     DECISION PrevCellState EQ 1
     numNeighbs = numNeighbs + 1
  ENDFN
  CellState = IF (CellState EQ 0) AND (numNeighbs EQ 3) THEN 1
             ELSE IF (CellState EQ 1) AND (2 <= numNeighbs <= 3) THEN 1
             ELSE 0
ENDTR

Comments: more here...