Skip to main content
SciNet
  • Home
  • All Courses
  • Calendar
  • Certificates
  • SciNet
    Main Site Documentation my.SciNet
  • CCDB
  • More
Close
Toggle search input
English
English Français
You are currently using guest access
Log in
SciNet
Home All Courses Calendar Certificates SciNet Collapse Expand
Main Site Documentation my.SciNet
CCDB
Expand all Collapse all
  1. Dashboard
  2. PHY1610 - Winter 2024
  3. Assignment 2: Modularize 1D Game of Life

Assignment 2: Modularize 1D Game of Life

Completion requirements
Opened: Thursday, 25 January 2024, 12:00 AM
Due: Thursday, 1 February 2024, 11:59 PM

For assignment 2 of the 2024 Winter PHY1610 course, we will look at a one-dimensional variant of Conway's Game of Life, as conceived by Jonathan K. Millen and published in BYTE magazine in December, 1978.

This system is a linear set of cells that are either "alive" or "dead", and time progresses in discrete steps.

The state of each cell at the next time step depends on its present state and that of its neighbours, in the following way:

  • First, count the number of alive neighbours at most 2 cells away
  • An alive cell stays alive if that count is 2 or 4, else it dies
  • A dead cell becomes alive if that count is 2 or 3, else it stays dead.

Since the first two and the last two cells would not have enough neighbours to apply this rule, we will use cells on the other side as neighbours, i.e., we use 'periodic boundary conditions'.

The initial state of this system will be constructed with a given fraction of alive cells which are (nearly) equally spaced among dead cells.

You are given a code, gameof1d.cpp, that already computes the time evolution of this system, and for each time step, prints out a line with a representation of the state and fraction of alive cells.  It can take parameters from the command line to set the number of cells, the number of time steps, and the initial fraction of alive cells. 

For this assignment, start by studying the code, make sure you understand what's going on. Make sure you can compile and run it on the Teach cluster.

Your task is to reorganize ('refactor') this code to be modular.  The aim is to have separate functionalities be implemented in separate functions.

  • Extract the part of the code that first fills the cell array, put it in a separate initialization function that then gets called from the main function, so that the program still produce the same output (check the output!).
  • Make this into a module, i.e., take out that initialization function and put it in a separate .cpp file and create a corresponding header file to be included in the original file.
  • Create a Makefile that can build the application.
  • Next, repeat these steps to create a module for the part of the code that updates the cell array (and update the Makefile).
  • Next, repeat these steps to create a module for the output part of the code (and again update the Makefile).
  • Be sure to comment your code.

You should submit your work to the course website by midnight (ET) February 1st, 2024.  Your submission should consist of all source files, headerfiles, and the Makefile.  You may put them in a zip file or tar ball, in fact, that is the recommended way.

  • gameof1d.cpp gameof1d.cpp
    25 January 2024, 1:23 PM
Contact site support
You are currently using guest access (Log in)
Data retention summary


All content on this website is made available under the Creative Commons Attribution 4.0 International licence, with the exception of all videos which are released under the Creative Commons Attribution-NoDerivatives 4.0 International licence.
Powered by Moodle