CS案例之Python实现算法:Shortest Path use Dijkstr
当前位置:以往案例 > >CS案例之Python实现算法:Shortest Path use Dijkstr
2018-07-23

Shortest Path

Description

In this project, you will use Dijkstra's algorithm to solve a shortest path problem in the context of a 2D game. In this game, an avatar moves inside a building that has walls, doorways, and other obstacles. provides Python code to read in a building map and convert it into a data structure containing line segments. The starter code also has displays the environment and the path returned by your function.

You are to complete the getShortestPath(environment) function in main.py. This function should return a list of Point2 objects, corresponding to the shortest path from the starting point to the ending point. That is, the element [0] should be the starting point and [-1] should be the ending point. The other points in the path should represent a sequence of avatar movements is consistent with the configuration of walls (i.e., can't walk thru a wall).

Environment Data Structure

An environment is used to store the position of the walls and obstacles. The data members of this class:

width, height – the outer dimensions of the structure.
doorWidth – the width of all doors.
start, end – Point2 objects denoting the starting position of the avatar and its desired ending position.
shooterPos – Point2 object denoting the position of the shooter.
boundaryWalls – List of 4 LineSegments corresponding to the outer walls of the building
boundaryWallsPonts – List of 4 Point2 objects corresponding to the corners of the building
interiorWalls – List of LineSegments, each corresponding to a planar surface of the wall. Walls have thickness; each wall component will have 4 LineSegments.
interiorWallsPonts – List of Point2 objects, each corresponding to a corner a wall component. Each wall will have 4 Point2s.
doorPoints – List of Point2 objects. each corresponding to the center of a doorway.
obstacleWalls –  List of LineSegments, each corresponding to a surface of an obstacle.
obstaclesWallsPoints – List of Point2 objects, each corresponding to a corner of an obstacle.

Notes

· The Points of walls and obstacles have been moved slightly into the interior of the room. This will ensure that the avatar is not directly on a wall.

· The avatar can move only to the points defined in the room (i.e., corners of obstacles and walls).

· The building will be rectangular in shape.

· The interior walls will start and end at the intersection of other walls.

· Doorways are all the same width and will not be at the end of a wall.

· Obstacles will be convex and not overlap.

· Shooter cannot shoot or see through a wall.

Scoring

· (75) Provide the shortest path using only obstacles. That is, the avatar can move through walls.

· (13) Provide the shortest path using both walls and obstacles.

· (5) Provide path that provides the shooter with the least opportunity to shoot, while factoring in walls and obstacles. In this problem, the distance traveled is not considered. Instead, the algorithm should minimize the distance traveled where the avatar is in danger of being shot.

· (7) Report. Write a report that explicitly lists what aspects of your program work and what does not. Provide a paragraph that describes what you had to do to get Dijkstra's to work in this application.



在线提交订单