Homework 10: Herds, flocks, and traffic jams ============================================ +------------------------------------------------------------------------------+ | **Due Date**: 11:59pm March 11, 2025 | | | | Homework should be submitted as a single Jupyter notebook to Dropbox | +------------------------------------------------------------------------------+ To do **in advance of this homework**: * Make sure you have run the code in Allen Downey's Chapter 10 notebook. Exercises --------- Complete the exercises corresponding to Exercise 10.1 -- 10.2 in Chapter 10 of Think Complexity (version 2): 1. In the traffic jam simulation, define a class, ``BetterDriver``, that inherits from ``Driver`` and overrides ``choose_acceleration``. See if you can define driving rules that do better than the basic implementation in ``Driver``. You might try to achieve higher average speed, or a lower number of collisions. 2. **(BONUS)** The code for my Jupyter port of Downey's Boid implementation is in ``Boids7nb.ipynb`` in the ``lab11`` directory of the course repository. If you attempt this exercise, make sure you read my notes at the beginning of the notebook pertaining to VPython. Run the notebook. It should create an animated display showing Boids, as white cones, circling a red sphere, which is the carrot. If you click and move the mouse, you can move the carrot and see how the Boids react. Read the code to see how the parameters control Boid behaviors. Experiment with different parameters. What happens if you “turn off” one of the behaviors by setting its weight to 0? To generate more bird-like behavior, Flake suggests adding a behavior to maintain a clear line of sight; in other words, if there is another bird directly ahead, the Boid should move away laterally. What effect do you expect this rule to have on the behavior of the flock? Implement it and see. Submission ---------- Please submit one or two Jupyter notebooks depending on whether or not you attempted the bonus. There is a placeholder in the ``chap10`` notebook for your work. You can simply append your work to the end of the ``Boids7nb`` notebook if you attempt that question.