Unit 3: Cloudrip Mountain (WIP)

Learning Outcome

Lesson Plan

Crag Tag

Objective

  • Introduce move() command
  • Reinforce the idea of return value as argument

Main Lesson

There are two kinds of moves. One moves until we are where we need to go; the other moves toward a given destination. In the following example:

moveXY (35, 40)

Hero.say (“nice view!”)

Your hero will say “nice view!” only once, after she has arrived her destination.

On the other hand, in the following code:

Your hero will say “nice view!” many times between her moves. Notice how the say() interrupt the flow of execution.

In fact, in the level Kithgard Enchanter, you can make your moveRight() and moveUp() commands using move().

Reflection Question: What does pender = hero.findNearest(hero.findFriends()) mean?

Slalom

Objective

  • Understand what is object literal and how is it constructed
  • Understand in what circumstances one cannot use moveXY()
  • Combine move() with conditional loops

Main Lesson

This level is not the first to introduce object literal, but it is the first to make it a learning objective.

An object literal is a comma-separated list of name-value pairs wrapped in curly braces. It encapsulates different data in one tidy package. This is close to defining an object, without the actionable methods.

studentA = {"name": "A", "age": 12, "grade": 5, "course completion": False }

It is important to point out to students that move() command takes an object as argument. And they have already seen this object in use many times: it is in fact the pos property of any object, be it hero, enemy, or item. We need to stress the exact syntax of how to write this object, as it will be used many times in the future.

Pay close attention to the following statement as it requires some explanation:

There are four x in these two lines, what does each of them mean?

Ogre Gorge Gouger

Objective

  • Introducing jumping: new methods jumpTo() and isReady("jump")

Tip

  1. To give your hero more time to do useful things try comment out the talk. It takes a lot of time (one sec) to say something!
  2. Try use jumping boots if possible.

Cloudrip Commander

Objective

  • Introduce new methods: summon and command

Main Lesson

This level adds two powerful methods to your weaponry: from now on you can summon soldiers and command them to fight for you. The landscape of battlefield has forever changed! Instead of the lone hero you have always been, now you have a whole army at your command!

Of course, summoning soldiers costs money, and each type of soldier costs differently. Remember that soldier is the cheapest to make.

Mountain Mercenaries

Objective

  • Command soldiers to attack!
  • Introduce the idea of battle strategy: collect coin, summon soldier, command soldier

Main Lesson

In the last level you only command your friends to move to a certain position. Now you will be able to command them to attack too!

Pay close attention to the part where you loop over your soldiers and command them.

Timber Guard

Objective

  • Introduce a new powerful loop command: for
  • Reinforce the pattern learned in the last level

Main Lesson

This level does a similar thing but much more efficiently thanks to the new for statement.

Pay close attention to how it is used:

for objectName in objectList:

The objectName doesn’t have to exist before: it is declared on the spot. Compared this to how it is done with the index approach:

while indexName < len(objectList):

objectName = objectList(indexName)

Obviously the for loop is much more compact and readable. In addition, we do not have to initiaze index variables.

Bane of Soldiers

Objective

  • Introduce the use of range in for loop

Main Lesson

The for loop can be used with index if needed. This level demonstrates that syntax.

Zoo Keeper

Objective

  • Introduce an abbreviated version of using range
  • Introduce a new property: team
  • Demonstrate the use of a list of objects as coordinates

Main Lesson

Instead of using for i in range (1, n) we can simply use for i in range(n). This is probably not a big deal, but it demonstrates the need for more compact statements in programming. Also, notice that here the use of for is different: the counting variable i, is not referred to in the loop. In this case we simply need to repeat the loop four times precisely.

Noble Sacrifice

Main Lesson

The main idea of this level is to make it clear that, if you use the for loop with two arguments: it starts with the startNumber and ends with endNumber -1. This is exactly what you need for the list index.

Hunting Party

Objective

  • To each its own enemy!

Main Lesson

Instead of attacking an enemy that is close to you, make your soldiers attack someone that is close to them. This way each soldier will have its own enemy and the battle is much more efficient!

Vital Powers

Objective

  • Get ready to function based battle strategy!

Main Lesson

There is nothing new in this level: you have seen it all. But it is time to get ready to this way of structuring your code. Write functions that collect coins, then summon soldiers, and then command soldiers, and finally do your own fight. This overall strategy is universal, what differs is how refined your functions are.

Zero Sum

Main Lesson

Zero Sum is a multiplayer level where you can fight again computer or other human players. This is the original meaning of codecombat. There is no official answer for this level. But the last level, Vital Powers, is already a pretty good guide on how you should structure your code.

A most simple solution can be like this:

This solution only adds two things to the pre-given:

  1. a simple coin collection routine that consists of two lines.
  2. a simple fighting routine for the hero that also consists of two lines. Note that the condition is set so that the hero will only fight when there is less than two friend soldiers left. Otherwise the hero should engage in coin collecting.

Several ways to improve the algorithm include:

  1. Use abilities of your sorcerer hero.
  2. Summon peasants to collect the coin (you need to have that summon type).
  3. Summon archers and other units to help the fight.
  4. Devise a better fighting strategy (defense position, prioritized targets, etc.)
  5. Devise a better coin collecting algorithm that maximize your earning.
  6. Devise a better summon strategy that builds a balanced army.

The Two Flowers

Main Lesson

Reinforce the same structure.

Notice that in the answer given, a variable named peasant is defined but never used.

The Geometry of Flowers

Objective

  • Introduce the ring of flowers and its according methods: toggleFlowers() and setFlowerColor()
  • Use mathematical functions to draw common shapes

Main Lesson

Drawing shapes is an intuitive class for beginner programmers. Many visual programming environments such as hour of code uses this extensively. In other learning languages, such as Logo, this is the first and last thing you do. In CodeCombat we are introduced to the object.method world of avatar commands from the very start but we have not done this basic training in drawing shapes.

There is not much to say about squares; but drawing circle requires the use of mathematical functions such as sin and cos. Notice how this function is provided: they are methods associated with this Math object.

Hunters and Prey

Objective

  • Write more refined army tactics

Main Lesson

So far you have been commanding your troops in an undifferentiated fashion. But each unit has its own strength and weakness. The archer, for example, is weak in health but has range attack. So it makes sense to keep a distance with your enemy.

Ask students what are the strategies described in the following code:

What else can you think of? How should the archer behave to maximize its power?

Now what does the soldier do in the following code:

The soldiers need to go before archers so as to attract the attention of enemies and absorb the damage.

P.S. This level uses a global variable: archerPos. Point this out to students and maybe explain what does the scope of variable mean.

Library Tactician

Objective

  • More army tactics: prioritized target
  • Introducing defending formation technique

Main Lesson

This level continues our tactics training by introducing a differentiation of your targets. Some targets are better eliminated first. This level asks to attack the strongest enemy first. You don’t have to do that in every level: normally we would want to attack enemies with the lowest health first.

Another thing this level introduces is to form a defense line and adhere to it. Instead of attacking a particular enemy, your archers could be holding their position. They would attack anyone that come into their attack range, but they would not move away from their defending positions.

The function findStrongestTarget() is a good refresh of technique we learned towards the end of the Desert.

Flawless Pairs

Objective

  • Introducing double index: using one iteration inside another

Main Lesson

This level implements a classic algorithm in computer science: given a list, how do you find the two items that are equal? The solution is the following double index:

  1. Iterate from 0 to the second to last item. This iteration is indicated by i.
  2. Iterate from the item next to i, to the last item of the list.
  3. If the items indicated by i and j are equal, then we have a match. Return
  4. proceed with j.
  5. proceed with i.
  6. If we are here then no match has been found. Return None.

Reindeer Wakeup

Objective

  • Updating a list

Main Lesson

We have been accessing information from a list a lot. But this is the first time we are updating what is in the list. The technique is simple. But it could be very useful to serve as status lights of things we want to keep track.

Canon Landing Force

Objective

  • Introducing two dimensional array.

Main Lesson

The 2D array is just like the 1D version: we quote row first and then column.

Power Points

Objective

  • Use double index loop to iterate through a 2D array

Main Lesson

The key point in this level is to understand how to set up the loop. len(powerMap) returns the number of rows of the array. We can use len(powerMap[i]) to find out the length of the items in any particular row. This means that the number of items in each row may be different.

Perimeter Defense

Objective

  • Introducing step value for for loop

Main Lesson

The only significant lesson is this level is the following syntax: for x in range(start, end, step)

Steelclaw Gap

Objective

  • Introduce the modulo operator: a % b returns the remainder of a divided by b
  • Demonstrate a classic summon-by-type strategy
  • Demonstrate how to send soldiers evenly to different defend positions

Main Lesson

The summon strategy demonstrated here will be used elsewhere. It is a perfect strategy to build an army with the right proportion of different units.

The summonTypes list can be conveniently changed to make adjustments when in need.

The defendPoints list is another useful technique. Many levels call for multiple defending points and we need to send our units to these points evenly. Here a simple technique is demonstrated, similar to the summon technique. You simply divide your army by the number of defend points, and then send each of them to the point indicated by the remainder. This would work regardless of how many units you have and doesn’t matter if some of them are dead.