MP9
Game of Life Part 1
Due dates may be found on the schedule.

This MP is designed to help you think about different parts of the Game of Life (GoL) final project in isolation, hopefully making the project easier to do as a consequence. In particular, it focuses on aspects of the project that are unrelated to the systems, web, and infrastructure topics we’ve been discussing recently.

1 Initial Files

In your CS 340 directory, merge the initial starting files with the following commands:

git fetch release
git merge release/mp9 --allow-unrelated-histories -m "Merging initial files"

The starter code for this project consists only of a pytest file and the associated github actions support. You will need to create your own implementation file from scratch.

Put your implementation in a file you create inside the mp9/ directory named life_parts.py .

Two functions in life_parts will be tested; you are welcome to add as many other helper functions, classes, and so on as you find useful. The two are independent of one another; we list them here in alphabetical order.

2 life_alphabet(ascii_board)

Write a function named life_alphabet accepting a single string argument.

The argument string will consist of h rows of w characters, where each row is terminated by a newline '\n'. Each character will be either a space or a capital letter, where spaces represent empty cells and letters represent live cells in a GoL board. Assume all cells outside of this board’s bounds are empty.

Return a string in the same format representing the same board one time-step later. If a cell survives, it should use the same letter as it did in the argument string. If a cell is born, it should use the minimum letter (alphabetically earliest) of those that contributed to its birth.

Given the argument " \nABCD\n \n", which looks like

    
ABCD
    

the new board will be " AB \n BC \n AB \n", which looks like

 AB 
 BC 
 AB 

We recommend that you

However, this is just a recommendation: you may approach the problem however you wish.

3 life_ring(width, height, ticks, border)

Write a function named life_ring accepting four arguments:

  1. The width of a GoL board (a positive integer)
  2. The height of a GoL board (a positive integer)
  3. The number of time steps to simulate (a non-negative integer)
  4. The outer border of a GoL board (a string of 2×width + 2×height + 4 characters)

The outer border lists the contents of every cell adjacent to but outside of the width×height board, clock-wise from the top-left corner, with one character per cell. Three characters are used:

An example of what this border encoding looks like (using letters instead of space, octothorpe, and quotation mark) can be found on the project page.

Starting from an empty board, perform the specified number of time-steps of a GoL simulation. At the start of each time step, set every border cell listed as ' ' to empty and every border cell listed as '#' to live; do not change those listed as '"'.

Do not bound the simulation: simulate the state of cells that are outside the bounds of the board too. If you choose to use a set, like getting started, this happens automatically. If you choose to use a fixed-sized grid, padding the given width and height by the given time steps in each direction will ensure the results look the same as an unbounded grid would have looked.

Return a board in the same format as life_alphabet, but use # instead of letters for live cells.

Consider running life_ring(4, 4, 3, '###### ######""""')

The ring string means some cells (#) come alive ever tick, some are erased every tick ( ), and some are unchanged ("). We’ll draw the made-alive cells with a green background and the made-dead with a red background.

Tick 1 starts by setting the ring of cells as given in the string

and then simulating one time step

Tick 2 starts by setting the ring from the end of tick 1

and then simulating one time step

Tick 3 starts by setting the ring from the end of tick 2, including emptying the space cells but not the quote cells

and then simulating one time step

Finally, we return the contents of the board (not the area outside it) as a string: " \n### \n### \n \n" which looks like

    
### 
### 
    

We recommend that you

However, this is just a recommendation: you may approach the problem however you wish.

4 Testing your code

You can test your code using the provided tester file by running python3 -m pytest.

5 Submission

You must commit your code to GitHub on the usual deadline using the standard git commit+push commands:

git add -A
git commit -m "MP submission"
git push

5.1 Autograding

The initial grading is done via a manual GitHub Action. You MUST complete this step before the deadline to earn the autograding points for the MP:

We install pytest on the autograder. If you want to install more packages, you can call pip from inside your code as, e.g.

import subprocess
subprocess.run(['pip', 'install', 'numpy'])
import numpy as np

5.2 Points

All of this MPs points are based on github autograding.