Javascript代写 | 1701ICT— Creative Coding

本次Javascript代写是用p5.js完成一个赛车游戏

1701ICT— Creative Coding

Question 1 (15 marks) – Super Speed Sprint Racer
In p5.play, sprites provide some additional functionality over normal images. Using p5.play,
create a simple top-down racing game similar to Super Sprint but simpler, with the following specifications:
 The program should read a track in from a file called ‘track.txt’. 0 should indicate
grass, 1 should indicate track and 2 should indicate start/finish line. You should
find/draw appropriate images to use as tiles to represent these components, and it
is recommended that you load them in as sprites. Each ‘tile’ should have dimensions
controlled by variables, and be positioned according to the input file. If the input file
is 10×10 numbers, you should draw this many tiles. The track is static, so this could
be drawn in the setup phase, but you will need access to this data for detecting the
car leaving the track (3 marks)
 The program should draw a car as a sprite on the start finish line, facing one of the
adjacent road tiles. You could draw or find a suitable image to use. The car size
should be controlled by a variable (but always smaller than the tile size) and be
placed in the middle of the road. (2 marks)
 If the car leaves the track and hits the grass, the game should reset to the start
position (simply move the car back to its initial position) (3 marks)
 Extra (3 marks): Add additional features to your mini-game – car physics, animation,
sound, gameplay mechanics, track features, or other.
For this question, we are not assessing your ability to write a full game (Milestone 2 covers
this), but are more interested in demonstrating your ability to use p5.play and other
features.
Question 2 (15 marks) – Travelling Salesperson
The travelling salesperson problem (TSP) is as follows; “Given a list of cities and the distances
between each pair of cities, what is the shortest possible route that visits each city exactly
once and returns to the origin city”. The problem was first formulated in 1930 and is one of
the most intensively studied problems in optimization. Even though the problem is
computationally difficult, a large number of heuristics and algorithms are known, so that
some instances with tens of thousands of cities can be solved completely and even problems
with millions of cities can be approximated within a small fraction of 1% optimal distance.
This question has 3 parts:
a) loadTSP(filename) (4 marks). Write this p5.js function that will read a TSP problem
from a .tsp file. For this assignment, we will only consider Euclidean distance
problems. The information you need to load in includes the problem name, total
number of cities, the id of each city, and the co-ordinates of those cities. You could
store the city information as 3 parallel arrays (ids, xcords, ycoords) or an array of
objects with an id, x and y value. You can find the TSPLIB documentation and the
dataset with Euclidean only problems on the course website. Your function should
take the name of a .tsp file to load.
Hint: Reading the TSPLIB.pdf file can be a little daunting. Have a look at some of the
actual .tsp files (berlin52.tsp, a280.tsp). It should make the problem seem a lot easier.
b) showLoadedTSP() (4 marks). Write this function that will visualise a loaded problem.
You will need to find a way to scale the loaded problem to fit correctly on the canvas.
You may choose what shapes/colours to use to visualise the problem. You should
make sure you display the problem name and number of cities somewhere on the
canvas.
c) showSolution(solutionFile) (4 marks). Write this function that will visualise a solution
to a loaded problem from a file. You may assume that this function will only be used
AFTER showLoadedTSP() has already been run. The first line of a .sol file contains the
problem file name (you should check this matches the loaded TSP). The second line
contains the tour length, and the rest of the file contains a list of ID’s (one on each
line) that represents the order that the cities should be connected to form the shortest
tour. You should display the solution tour distance on the canvas. Some sample .sol
files have been provided on the course website.