CS代写game代写Introduction to Computer and Programming
VG101 — Introduction to Computer and Programming
Manuel — UM-JI (Fall 2018)
• Include simple comments in the code
• If applicable, split the code over several functions
• Extensively test your code and impove it
• Write a single README ﬁle per assignment
• Zip all the ﬁles and upload the archive on Canvas
1 Project setup
At a cross road cars are either moving if the light is green or waiting if it is red. A road is composed of two lanes, for cars going in opposite directions while the light is located on the right hand side of the cars, before the cross. Moving cars are all going at a same constant speed of one unit every second.
A snapshot of the scenario at a time t is shown on Figure 1. On the picture three cars are going from top to bottom but are waiting as the traﬃc light is red. In the meantime ﬁve cars going from right to left are crossing, while two other cars are coming from the opposite direction. The two last cars can be seen coming from the bottom but have not yet arrived at the cross road.
Requirement for the above scenario:
• The user inputs n, the total number of cars, w the width of the road, and p the proba- bility that a cars does not stop at the red light;
• The number of cars on each line is randomly decided with respect to n;
• The color cycle of a traﬃc light is green for g s, orange for o s, and red for r s; The user sets the value of the variables g , o, and r ;
• Lights in the diagonal of the cross road have a same color;
• Each time a light changes from green to orange the cars before the light stop and the ones which have already passed it ﬁnish crossing; e.g. on Fig. 1 if the green light be-
comes orange then the two cars in the middle of the cross should ﬁnish crossing the road;
• Cars should appear at the beginning of the road with respect to where they come from; e.g. a car coming from the right should start from the right most edge of the ﬁgure;
• Every second all the non-waiting cars move by one unit;
The goal is to animate the displacement of the cars with respect to the traﬃc lights. The choice of the user will impact the risk for a car crash to happen. The animation stops as soon a crash occurs and the player loses. If all the cars have gone through without any problem the player wins.
Ex. 1 — Cross road traﬃc game
1. Write a simple function that initialises all the parameters, i.e. prompts the user for the number of cars, the time for each light color, randomly generates how many cars go in each direction, etc..
2. Write a function that draws the cross road.
3. Write a clear and precise algorithm describing the motion of the cars as well as the change of color of the traﬃc lights. Justify your choices. The algorithm should describe the whole animation of the cross road.
4. Write several functions to plot the cars and animates the whole scenario of the game.
Each of the following questions is optional and will bring a bonus on the project grade if properly solved.
5. Design more realistic cars of various sizes.
6. Allow the cars to randomly turn left or right.
7. Allow cars to adjust their speed within a range speciﬁed by the user. They can in turn use this information to prevent a crash.
8. Allow the player to choose a diﬃculty level and automatically adjust all the parameters accordingly,
e.g. number of cars, width of the road, right and left turns allowed, etc..
9. Add more lanes to the road.
Note: other adjustments are welcome and encouraged, however ﬁrst discuss them with the teaching team to check their validity and suitability for the project.
Ex. 2 — Registration plates
Each car features a registration plate composed one letter followed by a mix of ﬁve letters and digits,
e.g. B 34HB0. We want to generate a random plate for each of the car and return the plates of all the cars which do not stop at the cross road.
1. Random permutations.
a) Write a recursive algorithm that takes as input a set of elements and an integer l , and returns all their permutations of length l .
b) Adjust the previous algorithm to return a random subset of all the permutations containing
Hint: generating all the permutations and selecting n of them afterwards in not a good idea.
2. Implement the generation of the registration plates in MATLAB, and assign a unique plate to each car.
3. At the end of the game display the plate of all the cars that did not stop at the traﬃc light.
In order to smoothen the progress and provide hints on how to get organised when working on the project we deﬁned three milestones. For each milestone students must submit their current code with all the usual relevant ﬁles attached as well as with a short Changelog ﬁle that describes the progress done on the project. Expected implementation for each milestone:
1. Crossroad and traﬃc light: October 2nd;
2. Car related functions (e.g. input, direction, drawing, output, plate, etc.): October 7th;
3. Whole animation: October 14th;
This section lists all the Frequently Asked Questions (FAQ).
1. I do not understand a question. What should I do?
Use a monolingual dictionary to ensure you fully understand all the words appearing in the question. Then discuss with other students to know how they understand it. Only discuss the question, not its solution. If several opinions appear to be valid determine which ones is the best and most reasonable. Document your choices in the README ﬁle. Alternatively contact the teaching team through project 1 discussion on Piazza. To ensure everybody beneﬁts from the question and its answer no question will be answered if not asked on the project discussion;
2. What is w the width of the road?
The width of the road is how large the road is. It can be expressed in pixels or in term of time unit,
e.g. a width of 4 time units means that a car needs 4 time units to cross the cross road. Ensure the user knows what unit is used when he is prompted for w .
3. The optional question requirements do not match the original scenario. What should I do?
The optional requirement overwrites the original one. For instance in the original scenario the speed is uniform while in ex. 1 question 7 a car can change its speed. In that case the speed can be freely adjusted.
4. Can I skip base questions and do optional ones instead?
No, a submission that does not implement the basic questions will not receive any bonus.
5. Can I make use of the Automated Driving System Toolbox?
The project must be completed with the help of any “advanced toolbox”. Completing two versions, with and without, can bring bonus.
6. I have not read the ci.pdf ﬁle, can it impact my grade?
Yes, much information on the code quality appears in this ﬁle. No applying some of the rules can bring large deductions on the project grade.
7. I cannot meet a milestone, how bad is it?
Deductions will be applied if functions from previous milestones are not fully working in the ﬁnal submission. Besides, no answer will be provided to questions on a previous milestone.