Mountain Climber!

Posted bzpws65

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mountain Climber!相关的知识,希望对你有一定的参考价值。


Welcome to A2 - Mountain Climber!
Now that you\'ve acquainted yourself with Stacks, Queues, Lists and the like, it\'s time to explore more complex data structures, and use them to solve more complicated tasks!
Rather than spending 4 weeks in tranquility, painting to our heart\'s content, we\'ll be getting some exercise and climbing some mountains for the next 5 weeks! In particular, we\'d like to do some analysis and modelling of the mountain climbing we do, which you\'ll be helping us out with.
In this assignment, you\'ll work on the following features:
•    A Mountain Trail representation 
•    A plot view that shows the longest trails suitable for a given hiker
•    A trip organiser that keeps track of the relative ranking of trips
In doing this, you\'ll need to demonstrate knowledge on the following topics:
•    Linked Structures
•    Hash Tables and their various methods / approaches
•    Use of recursive sorting algorithms and recursive methods


Please Note: With the advent of A2 the ban on python inbuilts is mostly lifted with the exception of the sorted function and dict inbuilt type! Feel free to use list and all other python functionality to its full extent.

The only exception on this exception is that if you are essentially using a list as a stack then please use the provided LinkedStack instead.
Please make sure to read the next slide for some important information before diving into the rest of the assignment.
Please read all instructions carefully. It is useful to have a general understanding of the app and of trails before you begin; however, you do not need a deep understanding to complete most of the tasks.

To reiterate what is said in the next slide, you do not need to read through or change the contents of main.py, draw_trails.py, or utils.py. Each task will specify what files need to be edited.
The template git repository can be found here. Follow the instructions in the "Getting Started with Git" document to copy across the repository (KEEPING IT PRIVATE) and get coding.
Important Information, Tips and Tricks
Before you get working on the application, please read these tips & tricks to ensure you don\'t get lost, or lose any silly marks!

Group Work
This is the first assignment you\'ll be doing in groups. Remember to sign & submit the group contract[LINK] and fill out the weekly check-ups!

Common Mistakes
You are marked on correctness in Ed. It doesn\'t matter if your code passes locally, it needs to pass in Ed. Contact a TA if you are having trouble achieving parity. 

Be careful of the specific Python version used, and don\'t import any other third party modules excluding those already in requirements.txt.

Write clear and concise docstrings for methods you introduce / edit, and type-hint all methods / variables. 

If introducing new classes, consider using dataclasses to simplify this definition. 

Separate your code into small methods of at most 20 lines, and try to abstract logic if you find lots of duplicated work. 

Note: Almost all methods in the sample solution are 10 lines or less. (Please ignore the mess that is draw_trails.py or main.py : )

Initial Setup + Running Tests
To get up and running you want to do a few things:

Import the template repository - Follow the instructions in the Getting Started with Git page.

[Optional] Make a virtual environment for the project (Follow the instructions in the README file)

Install the required packages: python3 -m pip install -r requirements.txt

Test it is working by running python3 main.py  (This will raise NotImplemented errors if you haven\'t started on the assignment)

To run tests, call python run_tests.py. Note that you can restrict which tests are run using a second argument. For example, running python run_tests.py 1 will only run tests from the tests/test_trail/trail_TODO folder.

What files should I be editing?
Everything for the assignment can be solved in the following files:
mountain_manager.py
mountain_organiser.py
mountain.py
personality.py
trail.py

In particular, you do not need to read the following files:
main.py 
serialize.py
draw_trails.py
utils.py

Assumptions & Tidbits
dataclasses are used in some of the scaffold code. In short, they do a lot of the initialisation boilerplate for you by inspecting the type hinting for class variables. You can read more about it here.

This project also uses abstraction with the abc module. You can read more about it here.

What is the app?
NOTE
The adding/removing mountains / branches feature won\'t work until you have implement the first task slide "Trail creation & Edit methods"
The graph feature won\'t work until you have implemented nearly everything (More Trail Methods, Mountain Manager, Mountain Organiser, Double Key Table)

This app gives information about a certain mountain range, which has various interconnected mountains.

Each mountain has three associated pieces of information:

The name of the mountain (text)

The difficulty level of climbing this mountain (integer)

The length across the mountain (integer)

This can be visualised nicely by main.py:

Each mountain is represented by the person walking up a hill icon, and the interconnected lines represent connections between mountains.

Here the red numbers on the left of each mountain represent the difficulty level, and the blue numbers on the right of each mountain represent the length.

As part of this assignment we\'ll be asking many queries about this collection of mountains.

On the right sidebar of the screen you\'ll see a few different buttons: 


From top left to bottom right:
The plot icon shows a plot of mountains ranked by length as more difficulty levels are added. This is yet to be implemented, and is covered by Mountain Organiser and Manager.

The file icon allows you to save your current trail to a json file, which can be later loaded.

The final 4 icons are for selection modes, and once clicked change how you interact with the main view of the screen.
The pencil icon turns you into edit mode. Clicking on a mountain allows you to edit the difficulty, length, and name of the mountain.
The branch+ icon turns you into branch addition mode. Clicking on a straight horizontal line in the trail allows you to insert a branch.
The world+ icon turns you into mountain add mode. Clicking on a straight horizontal line in the trail allows you to insert a mountain.
The world- icon turns you into remove mode. Clicking on a branch or mountain in the trail allows you to remove that.

Finally, once you\'ve made some changes and used the save icon to save your changes to a json file, you can load them back up next time using a second argument to main.py. For example calling python main.py basic2.json gives: 

What is a trail?
Wiktionary defines a trail as: A route for travel over land, especially a narrow, unpaved pathway for use by hikers, horseback riders, etc. 

In this app a trail is a route both over and between mountains. 

Motivating the basic components of a trail
The basic trail
The most simple form of a trail is:

1. A line with no mountain on it; or
2. A line with a mountain on it. 
Combining Trails
We can combine two trails to form a larger trail:

1.In parallel (Branching paths); or
2.In series (One after the other). 
All possible trails can be generated by combining trails according to these rules.

Defining a Trail in Code
We can define a trail more formally using the following rules: 

The simplest trail we can have is a line with no mountain.

This is the trail object Trail(None).

Trail takes exactly one argument. It can take one of the following objects: None, TrailSeries, or TrailSplit. These are typed as TrailStore in the code. 

We can combine trails in sequence by having a mountain and a trail. 

This is the trail object TrailSeries(Mountain(name, difficulty, length), Trail(info)). 

TrailSeries takes exactly two arguments. 

The first argument must be a mountain, and this is the only way we can add a mountain to a trail. 

We can combine trails in parallel by having three trails: two which are in parallel, and the trail that follows. 

This is the trail object TrailSplit(Trail(info), Trail(info), Trail(info)). 

TrailSplit takes exactly three arguments. 

The first argument is the trail that splits upwards

The second argument is the trail that splits downwards

The third argument is the trail that follows once the previous two join together

Seeing it all in action
Note that every Trail object in code has a store, which contains one of the 3 objects above. So for example, we could model the below image with the following object:


trail = Trail(TrailSplit(
    Trail(TrailSplit(    # The top branch
        Trail(TrailSeries(
            Mountain("top-top", 5, 3),
            Trail(None),
        )),
        Trail(TrailSeries(
            Mountain("top-bot", 3, 5),
            Trail(None),
        )),
        Trail(TrailSeries(
            Mountain("top-middle", 4, 7),
            Trail(None),
        )),
    )),
    Trail(TrailSeries(   # The bottom branch
        Mountain("bottom-1", 2, 5),
        Trail(TrailSplit(
            Trail(None),
            Trail(TrailSeries(
                Mountain("bottom-2", 0, 0),
                Trail(None),
            )),
            Trail(None),
        )),
    )),
    Trail(TrailSeries(   # The following branch
        Mountain("final", 4, 4),
        Trail(None),
    )),
))

Which also looks like the following memory diagram (click the image to enlarge):

[TASK] Trail creation & Edit methods
It is highly recommend you fully read and understand the slide "What is a trail?" before continuing.

In this task, you\'ll be working on:

trail.py

The first task is to add a few helper methods to the Trail definitions in trail.py to support editing the Trails.

In trail.py, you\'ll find the following methods on a few different classes, already type hinted for you:

remove_branch

remove_mountain

add_mountain_before

add_empty_branch_before

add_mountain_after

add_empty_branch_after

These methods can be used to add and remove elements from the trail.

If this method is defined on the Trail class, you should return a new (or the old) Trail instance, which has completed the action specified.

If this method is defined on a TrailStore class, you should return a new (or the old) TrailStore instance, which has completed the action specified.

For example, suppose we have the following:

a, b, c, d = (Mountain(letter, 5, 5) for letter in "abcd")

empty = Trail(None)

series_b = TrailSeries(b, Trail(TrailSeries(d, Trail(None))))

split = TrailSplit(
    empty,
    Trail(series_b),
    Trail(TrailSeries(c, Trail(None)))
)

t = Trail(TrailSeries(
    a,
    Trail(split)
))

This is represented by the following diagram:


Calling series_b.add_empty_branch_after() returns the following object:

TrailSeries(
    mountain=b, 
    following=Trail(store=TrailSplit(
        path_top=Trail(store=None), 
        path_bottom=Trail(store=None), 
        path_follow=Trail(store=TrailSeries(
            mountain=d, 
            following=Trail(store=None)
        ))
    ))
)

While calling split.remove_branch should return the following object:
TrailSeries(
    mountain=c, 
    following=Trail(store=None)
)
And calling empty.add_empty_branch_before() should return the following object:
Trail(store=TrailSplit(
    path_top=Trail(store=None), 
    path_bottom=Trail(store=None), 
    path_follow=Trail(store=None)
))
Note - You don\'t have to touch the collect_all_mountains function or the length_k_paths function (yet

FunAug. 26/31 Mountain Water Slide!


 Highlights 

Mountain water slide

Glass walkway

Gorgeous views

Ancient town

Water activities


Are you ready for some fun;) We believe most of you have slid down from The Great Wall. But this mountain slide we are going is so much cooler in the hot summer days like this. It's a combination of mountain slide and rafting. Come check it out yourself;)

【Fun】Aug. 26/31 Mountain Water Slide!

【Fun】Aug. 26/31 Mountain Water Slide!

【Fun】Aug. 26/31 Mountain Water Slide!

【Fun】Aug. 26/31 Mountain Water Slide!

【Fun】Aug. 26/31 Mountain Water Slide!

Meet up info

Meet up time: Two teams

First team: 26th August 8:00-8:10(10mins to meet up)

Second team: 31th August (Friday) 8:00-8:10(10mins to meet up)

Meet up location: B exit of fengqi road subway station (Next to ZheJiang Grand Hotel)

【Fun】Aug. 26/31 Mountain Water Slide!


Itinerary

8:10 Head out, games and get to know each other on the way

11:40 Arrival and have lunch(prepare your own food or split at local restaurant)

13:00 Start hiking up to the mountain top for water slide, walk pass glass walkway with amazing views. Slide down the mountain on water slide, it's gonna be so much fun and exciting;) There will be more fun water activities waiting for us at the foot of the mountain. We would also visit a ancient village if time allows us.

17:30 Head back to hangzhou, arrive Hz around 9pm

Delays are possible due to holiday traffic and teammates with different hiking experiences.

Above is the general plan, it might change due to some unexpected reasons, please inquiry your hiking team captain, who will be in contact with you one day before the trip.


Tips

Outfit: Lunch, backup clothes, sun block/glasses etc.


Detail of charges

 Charges:290RMB/person 

 VIP:275RMB/person 

Share this post on your moments with your own comments→Get a deduction of 10RMB.

Cost include:

1. Round trip bus

2. Attraction&attraction bus tickets

3. Mountain water slide ticket

4. First-aid box

5. Team captain allowance

6. Planning and organization

Cost do not include:

1. Meals

2. Things not listed in cost include


 At least 16 people to make this trip happen 

Others

If lack number of people or Majeure reasons occur we have the rights to cancel or postpone trips.

If weather is really bad and represents a risk for people safety during hiking, we will cancel the trip up to one/two day(s) in advance.

If trip take place, you will be added to a group chat 5pm the latest.

Refund

(Within working hour: 9:00 - 22:00)

7 days in advance -- full refund

5 days in advance -- refund 50%

3 days in advance -- not refundable

Disclaimer

All forms of outdoor recreation (including hiking) have a higher level of risk than most ordinary activities. By participating in Etravelclub trips, you acknowledge and accept the responsibility for making your own determinations as to the suitability of the activity and for their own safety, conduct and well-being and agree to participate solely at your own risk.

Etravelclub, its organizer and team captains will not be held responsible for any loss or injury which you may sustain as a result of your participation in any of these activities. 

Anyone who is attending these activities agrees to above terms.

Registration steps

1
Fill in Sign up form

Long press this ☟☟☟ QR code → extract it → fill in the sign up form

【Fun】Aug. 26/31 Mountain Water Slide!


2
Payment

①Transfer money to Alipay → 18058781795(Etravelclub)

Transfer money to Wechatetravel666 or 18058781795(Etravel)

Transfer money to bank account →  ICBC 6217231202002789177 卢永龙

Write down names+event when making payment,e.g"Nick/Tom/Jane+Kayaking" 


3
Confirm Message


If trip take place, we will add everyone in a wechat group chat one/two day(s) before the trip. (5pm the latest)


Fill in sign up form → Payment → Trip notice(Wechat group) → Trip → Trip comments

Add us on wechat to solve your doubts

Etravelclub wechat

etravel666 or 18058781795

Or long press below QR Code to add us

【Fun】Aug. 26/31 Mountain Water Slide!


以上是关于Mountain Climber!的主要内容,如果未能解决你的问题,请参考以下文章

845. Longest Mountain in Array

852. Peak Index in a Mountain Array

leetcode_1095. Find in Mountain Array_[Binary Search]

FunAug. 26/31 Mountain Water Slide!

FunJul. 6/7 Mountain Water Slide!

fzu 2109 Mountain Number 数位DP