Psuedocode for The Game Of Life.
Copyright C. A. Broadribb 1994.

The rules:
Cells touching each other vertically, horizontally or diagonally
are counted as neighbours.
Cells with less than two neighbours will die from loneliness.
Cells with four or more neighbours will die from overcrowding.
Cells with two or three neighbours will remain alive.
New cells will be born if they have exactly three neighbours.
All deaths take place at the same time.

Pseudocode:
Declare a 20 x 20 array of characters called Cells
Declare an integer Quit
Declare a character variable Choice
Quit = 0
Readcells (Cells)
Displaycells (Cells)
        WHILE Quit = 0
                Userinput (Choice)
                IF Choice = 'd' THEN
                        Changecells (Cells)
                        Displaycells (Cells)
                ELSE
                        IF Choice = 'w' THEN
                                Writecells (Cells)
                        ELSE
                                IF Choice = 'q' THEN
                                        Quit = 1
                                ENDIF
                        ENDIF
                ENDIF
        ENDWHILE
END



Iscellalive (Cells, Column, Row):
        IF Cells (Column, Row) = '*' THEN
                return 1
        ELSE
                return 0
        ENDIF
END



Readcells (Cells):
        Declare integer variables Column, Row
        Open file
        DO Column = 1 to 20
                DO Row = 1 to 20
                        READ Cells (Column, Row)
                ENDDO
                Start reading from a new line
        ENDDO
        Close file
END



Displaycells (Cells):
        Declare integer variables Column, Row
        DO Column = 1 to 20
                DO Row = 1 to 20
                        WRITE Cells (Column, Row)
                ENDDO
                Start writing on a new line
        ENDDO
END



Writecells (Cells):
        Declare integer variables Column, Row
        Open file
        DO Column = 1 to 20
                DO Row = 1 to 20
                        WRITE Cells (Column, Row)
                ENDDO
                Start writing on a new line
        ENDDO
        Close file
END



Changecells (Cells):
        Declare a 20 x 20 array of characters called Newcells
        Declare integer variables Column, Row, Alive, Neighbours
        Initialise Newcells to blank spaces
        DO Column = 1 to 20
                DO Row = 1 to 20
                        Alive = Iscellalive (Cells, Column, Row)
                        Neighbours = Countneighbours (Cells, Column, Row)
                        IF Alive = 1 THEN
                                IF Neighbours = 2 or Neighbours = 3 THEN
                                        Newcells (Column, Row) = '*'
                                ENDIF
                        ELSE
                                IF Neighbours = 3 THEN
                                        Newcells (Column, Row) = '*'
                                ENDIF
                        ENDIF
                ENDDO
        ENDDO
        Swapimage (Cells, Newcells)
END



Countneighbours (Cells, Column, Row):
        Declare integer variables Xpos, Ypos, Neighbours
        Neighbours = 0
        Ypos = Row
        Xpos = Getposition (Column + 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Xpos = Getposition (Column - 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Xpos = Column
        Ypos = Getposition (Row + 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Ypos = Getposition (Row - 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Xpos = Getposition (Column + 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Ypos = Getposition (Row + 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Xpos = Getposition (Column - 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Ypos = Getposition (Row - 1)
        Neighbours = Neighbours + Iscellalive (Cells, Xpos, Ypos)
        Return the value Neighbours
END



Getposition (Position):
        IF Position > 20 THEN
                Return 1
        ELSE
                IF Position < 1 THEN
                        Return 20
                ELSE
                        Return the value Position
                ENDIF
        ENDIF
END



Swapimage (Cells, Newcells):
        Declare integer variables Column, Row
        DO Column = 1 to 20
                DO Row = 1 to 20
                        Cells (Column, Row) = Newcells (Column, Row)
                ENDDO
        ENDDO
END



Userinput (Choice)
        Write 'Enter d to display the next iteration, w to write the current  
        pattern to a file or q to quit the program'
        REPEAT
                READ Choice
        UNTIL Choice = 'd' OR Choice = 'w' OR Choice = 'q'
END

