CS 124
Fall 2023

Midterm Project - Emergence

Preliminaries

In your work on this assignment, make sure to abide by the collaboration policies of the course.

Don’t forget to use docstrings and to take whatever other steps are needed to create readable code.

If you have questions while working on this assignment, please come to TA help hours or post them on Piazza.

due by 10 p.m. EDT on Saturday, October 28, 2023

Midterm Project: Emergence

80 points; pair-optional and group-of-three optional

You may complete this project with partners. See the rules for working with a partner on pair-optional problems for details about how this type of collaboration must be structured.

This project is required and cannot be dropped. It will be part of the Project portion of the final grade.

In this project you will write a computer simulation of a phenomenon known as Emergence. Emergence phenomena can be observed almost everywhere from philosophy, systems theory, science, and art. Emergence occurs when an entity is observed to have properties its parts do not have on their own. You can read more about this here: http://en.wikipedia.org/wiki/Emergence.

The objective of this part is for you to write a program that simulates the emergence behavior in a two-dimensional dot grid. As part of the scientific investigation process, you must observe our example data and come up with a hypothesis about the observations, and then test your hypothesis in your code to check if you get the same results.

The data for you to observe is within the project PDF file: CS120-EmergenceProject.pdf

GUI Visualizer

To start, download the starter code emergence.py and make sure you can run it.

The starter python file contains Emergence class and visualizer code to display the dot grid. The initializer of this class defines the gridcolors property which represents dot grid as a two-dimensional list. Internally, a dot grid is represented by a two-dimensional data list of 0 and 1 values. Display-wise, it is a 2D dot grid on the canvas with the color of each dot depending on the value in the corresponding element of the data array. The figures below show an example dot grid including its internal data values and corresponding graphics display, with blue for 0 and red for 1.

dot_grid.png dot_colors.png

You will need to modify the starter code to draw two-dimensional array of dots on the canvas satisfying the following requirements.

  1. dots are nicely spaced on the grid.
  2. the dot grid is centered on the canvas.
  3. The ratio of the grid width and height over the canvas width and height is defined in the constant TOTALGRIDRATIO, which is 0.8.
  4. The __init__ method takes two arguments one for the grid size (i.e. the number of dots in each dimension, should be between 2 and 10; the default value is 10), and the other for the grid type (0 for an example grid and the other for a random grid).

The Emergence class contains starter code for the computeGridLayout() and drawGrid() methods. The computeGridLayout() method computes the coordinates of the dots as follows:

  1. Computes the width and height of the grid and canvas.
  2. Computes the x and y coordinates of the top left corner of the grid.

The drawGrid() method is to actually draw the grid dots on the canvas. This method should use a nested for loop to draw one dot for each array element, at a proper position with the proper color.

You will need to complete these two methods.

If you have trouble running the GUI Visualizer code on your computer, we will provide a text-based version on Piazza.

Simulating Emergence

Your task on this part of the project is to complete the updateEmergenceGrid method that simulates the emergence behavior in a two-dimensional dot grid. As illustrated in the slides, at each subsequent step, each dot checks its neighbor’s colors and determines what its own color will be. The challenge that you are facing in the first part of the final project is that we don’t tell you the color update rules, chiefly.

You need to use the scientific investigation process to try to discover the rules

You need to write code to update the grid with your emergence rules and redraw the grid if at least one dot in the grid has a new color. Thus your main task is to identify and implement grid color update rules. Develop your algorithms before programming and consider using helper methods provided for you on the starter code.

For the example grid, if your hypothetical rules for updating grid colors produce the same intermediate and final grids as given in the slides, congratulations! You have discovered correct update rules. Otherwise, make (more) observations of your grids and the example given in the slides, revise your update rules and implement these new rules. Keep your code for old rules in your program so that we can see your progress and efforts in developing the rules.

The autograder will check that your grid update rules match our rules for the example grid.

Project Report - Jupyter Notebook

20 points; pair-optional or group-of-three-optional

For your project report, create a Jupyter Notebook file to discuss your project, the hypothesis, and your results.

Create a new Jupyter Notebook file, save it using the the name emergence-report.ipynb

Requirements:

  • Describe the Emergence phenomena based on your readings of it from the web. Explain several examples where it observed in various fields.

  • Include at least 2 images of emergence phenomena.

  • Describe your initial hypotheses and the test(s) you conducted to check it, even if incorrect.

  • Based on your observations, describe any adjustments you made to your simulation code.

  • Describe the final rules that describe the data provided to you.

  • Format your entire Notebook so that it’s beautiful and the flow from start to the end makes sense.

Important guidelines

  • You must format your Jupyter Notebook nicely. Some of the points will be awarded for clean and neat style.

  • Please Run All Cells before submitting your notebook file on Gradescope.

  • This submission will be manually graded, so you may use a certain amount of creativity as long as the required elements are easily found.

  • See below for directions on saving a PDF version of the notebook.

Saving a PDF version of your Jupyter Notebook

When you upload your .ipynb file to Gradescope, images and plots are sometimes not be included. We need you to also submit a PDF version of your notebook. You can try to “print to PDF” directly from the web browser. Some people report good results this way, while others report better results with the alternative way below:

Alternative way to generate a PDF from Jupyter Notebook:

  1. Run All from the Cell menu.
  2. Go to the File menu, and select File -> Download As... -> HTML (.html)
  3. This will download a file with the same name as the notebook, except ending in .html
  4. Find this HTML file and open it with your web browser.
  5. Verify that the web browser displays the notebook with graphics correctly.
  6. Use the web browser’s print function.
  7. In the print menu, select Save as PDF as the destination rather than an actual printer. This will appear in different places for different web browsers.
  8. Save the resulting PDF file in a location where you can find it for uploading.
  9. Open the PDF file and verify that it looks correct.

Submitting Your Work

You should use Gradescope to submit the following files:

  • your emergence.py file containing your coding solutions.
  • your emergence-report.ipynb file containing your project report in .ipynb format
  • your emergence-report.pdf file containing your project report in .pdf format

Group Submission Instructions

  • Only one partner should upload a solution. It must have all partner names in the code comments and in the report. Once uploaded, use Gradescope to “tag” the student partners as a group participant.

Warnings

  • Make sure to use these exact file names, or Gradescope will not accept your files. If Gradescope reports that a file does not have the correct name, you should rename the file using the name listed in the assignment or on the Gradescope upload page.

  • If you make any last-minute changes to one of your Python files (e.g., adding additional comments), you should run the file in VS Code after you make the changes to ensure that it still runs correctly. Even seemingly minor changes can cause your code to become unrunnable.

  • If you submit an unrunnable file, Gradescope will accept your file, but it will not be able to auto-grade it. If time permits, you are strongly encouraged to fix your file and resubmit. Otherwise, your code will fail most if not all of our tests.