Question: The rules: ( in matlab ) Your ship is a circle of radius 1 on a racetrack that spans from x = - 1 0

The rules: (in matlab)
Your ship is a circle of radius 1 on a racetrack that spans from x=-10 to x=10. The track starts at y=0,
and the finish line is at y=300. At random intervals in y the track has obstacles, which are horizontal
bars (that have no thickness in the y-direction) up to half the width of the track. You can see the
obstacles once they are within 25 units of your ship in the y direction. Your ship has four thrusters which
it can use to accelerate, one pointing in each of the four cardinal directions. Your ship has inertia and is
moving in an environment with no drag, so if no thrusters are fired your velocity will remain unchanged.
Each thruster has power 0.2, meaning that firing it will change your velocity in the chosen direction by
0.2 units. In each of the x direction and y direction, you have the choice to accelerate in the + direction,
accelerate in the - direction, or not to accelerate. You can fire both an x thruster and a y thruster in the
same turn.
You will write a function that takes a cell array of the track details as an input, and outputs two scalars
denoting whether you choose to fire each engine.
function [xthrust, ythrust]= Lastname_Firstname(input)
The input is a 15 cell array whose contents are as follows (in order):
A 12 array containing your x position and y position
A scalar representing your x velocity
A scalar representing your y velocity
An n3 array containing the details of the obstacles visible to you. The first column is the
distance in y between you and the obstacle, and the second and third columns are the x
coordinates of the left and right bounds of the obstacle. The number of rows will be equal to the
number of obstacles visible, which will vary depending on your y position and the randomly
generated track.
A 12 array containing your opponent's y position and a Boolean denoting whether they have
crashed or not (1 if they have crashed, 0 if they are still racing).
xthrust and ythrust should each be either -1,0, or 1(-1 to accelerate in the - direction, 1 to accelerate in
the + direction, 0 not to accelerate). If your function returns anything other than -1,0, or 1 for either
xthrust or ythrust, the value will default to 0.
Your function and your opponent's function will be called in a while loop. At each iteration the loop will
feed your function the current state of the race, and accelerate your ship by its outputs xthrust and
ythrust.
The two ships will simultaneously race along identical tracks, newly randomly generated every race. If at
any point a ship makes contact with an obstacle or with the wall of the track, it crashes and ceases to
move forward. If your ship is ever stationary (0 velocity in both x and y) for consecutive turns, it is
considered to have crashed. The ship that finishes the track first is the winner. If both ships crash, the
ship that made it farther along the track is the winner. In the rare case that both ships crash at the same
y position, the ship that got there first is the winner.
The fine details:
A few assorted notes on the game mechanics:
Change in velocity will be applied before computing the subsequent movement step. For
example, if your ship's x velocity is 0.4 at the beginning of an iteration, and your function returns
xthrust =1, your ship will move +0.6 units in x that turn (likewise +0.4 units if x thrust =0, and
+0.2 units if xthrust =-1).
The values given as x position and y position denote the center of your ship.
Your ships path during a given turn is taken into account when checking for a collision with an
obstacle, not just your position after a move.
 The rules: (in matlab) Your ship is a circle of radius

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!