Answered step by step
Verified Expert Solution
Link Copied!

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 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago