Finding treasures in a hexagonal map and the minimal distance between one point to another (Main code implementation on map.c)
The tresure map is made out of hexagonal tiles:
![hexagon](https://private-user-images.githubusercontent.com/56858161/252020458-b9155344-54b3-4062-9a96-44f5fd25f84b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0MzEzNzAsIm5iZiI6MTcyNDQzMTA3MCwicGF0aCI6Ii81Njg1ODE2MS8yNTIwMjA0NTgtYjkxNTUzNDQtNTRiMy00MDYyLTlhOTYtNDRmNWZkMjVmODRiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIzVDE2Mzc1MFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM3MDc4YjZmZjQyMzNiNmRjODMxYjgxYzhkZjFmY2FhZTFiMmUzZjBkN2ZhMDkwZjY0NDY0ZjM0YTY1NTA1ZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2iTbfO0XIi215ZUpFuT3LaiQwFFNeRl-89e7BMqXvgs)
The points in a 7 × 4 array correspond to the points shown above. The same behaviour of odd and even columns in a different order generalises to an m × n m × n map.
Create function *getAdjacentPoints() which returns all the adjacent points around an inputted point, sorted by first then second coordinate. If the inputted point is not on the map, the point is considered to have no adjacent points.
Create function mapValue() that returns the total value of all the treasure found in a map. Each tile is assigned a value:
- If the value of the point is negative, it represents the depth of the ocean floor in metres.
- If the value of the point is 0, it represents land without treasure.
- If the value of the point is 100, it represents an airport.
- If the value of the point is positive but not 100, it represents the value of that specific treasure.
The value of an island is given by multiple of the value of all treasures on that island (E.g. f(x) = x1 * x2 * x3, therefore the value of the map is the sum of the value of all islands.
Used BFS to explore all tiles.
Create function minTime() which finds the minimum amount of time from a start point to the end point. The amount of time it takes to move to an adjacent point is determined by the current point you are on:
- It takes 5 minutes to move from a land point to an adjacent point.
- It takes 2 + ceil(depth^2 / 1000) time to move from a point in sea.
- It takes max(15, (x1 -x2)^2 - 85) minutes to fly from one airport to any other airport. Where x1 and x2 are the x coordinates of the airports.
- It takes 5 minutes to move from an airport or treasure to an adjacent point (treat like land).
Used Dijkstra's Algorithm to find the shortest path
Part E is an extention of part D but execpt the locations of all airports are known beforehand. This allows Part D's algorithm to find the minimum distance faster in average case.
(Altered description written by William Sutherland, 2023)