Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 on a racetrack that spans from to The track starts at
and the finish line is at At random intervals in the track has obstacles, which are horizontal
bars that have no thickness in the ydirection up to half the width of the track. You can see the
obstacles once they are within 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 meaning that firing it will change your velocity in the chosen direction by
units. In each of the direction and direction, you have the choice to accelerate in the direction,
accelerate in the direction, or not to accelerate. You can fire both an 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 LastnameFirstnameinput
The input is a cell array whose contents are as follows in order:
A array containing your position and y position
A scalar representing your velocity
A scalar representing your y velocity
An array containing the details of the obstacles visible to you. The first column is the
distance in between you and the obstacle, and the second and third columns are the
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 array containing your opponent's y position and a Boolean denoting whether they have
crashed or not if they have crashed, if they are still racing
xthrust and ythrust should each be either or to accelerate in the direction, to accelerate in
the direction, not to accelerate If your function returns anything other than or for either
xthrust or ythrust, the value will default to
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 velocity in both and 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 velocity is at the beginning of an iteration, and your function returns
xthrust your ship will move units in that turn likewise units if thrust and
units if xthrust
The values given as 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started