Spring 2017
Programming Assignment 1: Angry Birds: Part Deux (Smarter Pigs Edition)
Due: 11:55pm, Wed March 8, 2017
We recommend using python. Java or C++ are also fine choices. If you plan to use a language that is different from these choices, please contact the TA to make sure your language of choice supports standard features such as thread, synchronization, and network communication.
Make your choice carefully since it will impact how much code you will need to write and how much support we can provide if you run into issues.
Once a bird launches, the pig closest to the bird lauch pad will estimate the trajectory and landing coordinates of that bird. The landing coordinates are communicated to the entire group using P2P messages. Each pig knows its current position and will estimate if it is impacted by the bird landing, and if so, will take evasive action by moving itself to nearby location that is not impacted by the bird launch.
Birds can launch themselves at different speeds and P2P messages incur a fixed hop-by-hop delay to propagate from one pig to another. So the evasive strategy may not always succeed if the fast-moving bird lands on the target location before the P2P messages have propagated through the pig network and all impacted pigs have taken the necessary evasive action.
Assume that the number of pigs N is specified beforehand (N should be configurable in your system).
First construct a pig-to-pig network (also known in the non-pig world as a peer-to-peer network) such all N pig form a connected network. You can use either a structured or unstructured P2P topology to construct the network. No neighbor discovery is needed; assume that a list of all N peers and their addresses/ports are specified in a configuration file.
Once the network is formed, prior to each bird launch, assign a new position to each pig. You can use a simple grid of coordinates and place a pig at a location on the grid. While it is fine to choose random locations, you may want to also want the ability to configure specific locations for pigs solely for purposes of testing your code. Also randomly place a few stone columns next to a few pigs. Assume that if a bird lands on a pig, a pig may fall over onto a neighboring and/or topple a neighboring stone structure, if any, which may also topple onto neighboring pigs. For simplicity, assume that if a neighbor pig fall onto a pig, that pig is hurt but it itself does not impact other neighbors. If a stone column falls onto a pig, it can the pig will further roll over onto a neighbor. In other words, you are free to limit the impact of a bird landing onto a pig and its neighbors, or the neighbor's neighbors (for falling stone columns), but no further.
The speed of a bird and its trajectory can be chosen randomly each time. However, for testing purposes, you may also want the additional ability to configure the speed and trajectory (landing coordinates) of a bird.
Finally, the delay incurred by a P2P message at each hop should be configurable. If a delay of T (in milliseconds) is specified, each peer should add a delay of T time units before propagating any of the messages listed in the interface below to the next hop(s). Note that T can be set to zero, in which case peers do not add artificial delays to simulate real network propagation delays.
A related goal is to ensure you properly test you code. You can create specific scenarios and/or inputs to test your code and verify that it works as expected. Unit testing frameworks are fine to use here, but do keep in mind that this is a distributed application with peers running on different machines. So testing is more complex in this setting. For the purposes of the lab, you should write three tests of your choice either using a testing framework or using your own scripts/inputs to test the code. The tests and test output should be submitted along with your code.
We do not expect elaborate use of github or testing frameworks - rather we want you to become familiar with these tools and start using them for your lab work (and other programs you write).