首页 >
> 详细

HW 3- The Odds of Successfully Navigating an

Asteroid Field are Approximately 3,720 to 1!

ENGR 3H

Due 11:59 PM, Wednesday, May 2

1 Never Tell Me the Odds (50 Points)

This week, we are going to use recursion to find a safe path through a treacherous asteroid field! Download from Gauchospace the files mf.png, asteroids.mat, and animate system.m.

The file asteroids.mat contains (in order) the x- and y- coordinates for

the centers of a series of circles and the radii for these circles. These circles will

represent our asteroids. Our ship, the Millennium Falcon, may not look like

much, but she’s got it where it counts–but more importantly for our purposes,

she’ll be represented by a circle as well, with radius .5 and initially at the

coordinates (10, 0).

At each time step, the Millennium Falcon moves 1 space in the y-direction.

It can move either 1 space left, 1 space right, or maintain the same x-coordinate.

So, for example, on the first turn, the Falcon can go from (10, 0) to (9, 1), (10, 1)

or (11, 1). For this assignment, we also require that our ship’s x-coordinate stay

between 0 and 20, that is, 0 ≤ xMF ≤ 20.

If the Falcon overlaps with an asteroid, it crashes. We want to avoid that!

Two circles overlap if the distance between their centers is less than the sum of

their radii. The distance between centers is given by the Pythagorean theorem:

d = q(xMF F xAst)2 + (yMF F yAst)2. (1)

1.1 Making the Kessel Run in 12 Parsecs (30 Points)

To find our way through the asteroid field, we’re going to write a recursive

function called find path.m. The function should take as an input the current

position, the maximum depth of the tree, and the array of asteroid coordinates.

It should return an array of coordinates for the ship’s trajectory and the ycoordinate reached by the ship (for example, if it crashes at y = 9, it should

return 8; if it makes it to the end, it should return the value of the maximum

depth). The function should recursively find the a path that avoids asteroids

up to the maximum depth. The process for this function should look as follows:

1

1. Check if, at the current coordinates, the ship has hit an asteroid. If it has,

return the current coordinates and a value of yMF F 1.

2. If the ship has not crashed, check if the maximum depth has been reached.

If it has, return the current coordinates and a value of yMF .

3. If neither of the first two conditions are met, find the path that results

from moving left in the next step, moving right, and moving in neither

direction. The function should return the value of whichever path had

the greatest value (calculated recursively) and an array of the current

coordinates followed by the coordinates of each step in the highest-value

path.

Remember: if we are at one of the boundaries (0 or 20), our options are

limited and we cannot go left or right, respectively.

1.2 It’ll Take a Few Moments to Get the Coordinates from

the Navicomputer (15 Points)

We want to get our ship to make it safely to y = 20. Write a script that

implements your recursive function to find the best path, with a maximum depth

of 20. Then, use that path to animate the system using animate system.m,

which takes as inputs the coordinates at each time step for the Falcon and the

array of asteroid coordinates. Your script should be self-contained–the matrix

containing the asteroid coordinates should be loaded within the script. Also,

create a global counter variable in the script, initialized to zero. Run the script

using run and time, and note how many times your recursive function is called.

How does it compare to the maximum number of times it could be called given

the maximum depth? Please note that this will take a little bit of time–on my

laptop, it took just over 6 minutes. I recommend trying a smaller maximum

depth first to verify everything is working as intended.

Hopefully you got through the asteroid field, but there’s no way we’d have

six minutes to calculate the correct coordinates! Let’s modify our script now:

at each time step, we compute the next 10 steps with the best value, rather

than the full 20. That means we’re going to compute the next 10 steps 20 times

instead of the full 20 steps once.

As before, calculate the maximum number of possible paths and compare

to the number of times your function was actually called according to run and

time. As you can see, we significantly reduced the number of time it took to

calculate the route. Be warned, we can’t guarantee we find success with fewer

paths considered!

1.3 The Weekly Challenge- I’ve Made a Lot of Special

Modifications, Myself (5 Points)

The goal of this week’s weekly challenge is to successfully reach a distance of

50 units starting from a different starting point with the fewest evaluations of

2

your recursive function. You essentially have two variables you can adjust:

1. The depth find path.m goes to;

2. How many steps the ship moves before calculating a new best path.

Your script should be written with these two variables able to be readily rede-

fined (that is, they should be declared at the beginning of the script, and any

time they’re required later on, these variables are referenced). For the weekly

challenge, submit your values for these two variables; the person who makes it

to the end in the fewest calculations (or, if no one makes it, the person who

made it the farthest in the fewest) wins!

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp2

- Ecse 427作业代写、代做systems课程作业、C++程序语言作业调试 2020-09-25
- 代做program课程作业、代写matlab实验作业、Matlab编程语言作 2020-09-25
- 代写program留学生作业、Sql程序设计作业调试、代写data课程作业、 2020-09-25
- Comp3506作业代写、代做java实验作业、Java编程语言作业调试、代 2020-09-25
- Game Menu Shell作业代做、System课程作业代写、C#编程语 2020-09-25
- Cp1 1902作业代做、代做c/C++程序语言作业、代写java，Pyth 2020-09-25
- 代写sit215留学生作业、Artificial作业代写、Python程序语 2020-09-24
- Sit202课程作业代做、代写computer Networks作业、Web 2020-09-24
- 代写kit308/408作业、代做programming作业、C/C++程序 2020-09-24
- Comp3506作业代做、代写java编程语言作业、代做programmin 2020-09-24
- 代写data留学生作业、代写program作业、Python程序语言作业调试 2020-09-23
- Data Programming作业代写、Python编程语言作业调试、代写 2020-09-23
- Comp1600作业代做、代写java编程作业、代做c/C++，Python 2020-09-23
- Ict365课程作业代做、代写c++程序设计作业、代做c/C++实验作业调试 2020-09-23
- 代写program留学生作业、Python，Java，C++程序语言作业调试 2020-09-23
- Cs 2510课程作业代做、代写systems留学生作业、Python编程设 2020-09-22
- B-Tree作业代做、代做java课程设计作业、Java程序语言作业调试、代 2020-09-22
- 代做cop3503作业、代写c++程序语言作业、代做c++课程设计作业、代做 2020-09-22
- 代写159.336留学生作业、代做python编程设计作业、代写java，C 2020-09-22
- Software课程作业代写、C++程序语言作业调试代做、代做data留学生 2020-09-22