Skip to content

Instantly share code, notes, and snippets.

@a1ip
Last active August 18, 2018 19:37
Show Gist options
  • Select an option

  • Save a1ip/2a89de59f88d8325d67d to your computer and use it in GitHub Desktop.

Select an option

Save a1ip/2a89de59f88d8325d67d to your computer and use it in GitHub Desktop.
CodeCombat Player-Created Levels solutions http://codecombat.com/play-old

EXTRA EXTRAPOLATION

Predict your target's position for deadly aim. - by Sootn

Difficulty: ★★


Code for chooseAction() spell is here:

shellAirTime = 3.4 # in seconds
ogre = @getNearestEnemy()
@attackXY ogre.pos.x + ogre.velocity.x * shellAirTime, ogre.pos.y + ogre.velocity.y * shellAirTime if ogre

The Right Route

Strike at the weak point in an array of enemies. - by Aftermath

Difficulty: ★


Code for chooseAction() spell is here:

enemies = @getEnemies() # Returns an array with all enemies.
enemy = enemies[2]
# Array elements start counting from 0, you can specify an entry using this syntax.

# Check the guide if you're unsure how this evaluates!
if enemies.length is 3
  @say "I'm coming to get you " + enemy.id + "!"

  @setTarget(enemy)
  if @distanceTo(enemy) > @attackRange
    @setAction "move"
  else @setAction "attack"
else
  @say "All clear."
  @moveXY 38, 35 # Sword location

SWORD LOOP

Kill the ogres and save the peasants with for-loops. - by Prabh Simran Singh Baweja

Difficulty: ★★


Code for plan() spell is here:

# Kill all the ogres.
@moveDown()

# Now you don't have to write it 5 times. Amazing! Isn't it?
# Edit the code here.

for i in [1..5]
  @moveRight()
  @attackNearbyEnemy()

@moveRight()
@moveRight()
@moveUp()
@moveDown()
@moveDown()
@attackNearbyEnemy()
@moveUp()
@moveUp()

for i in [1..3]
  @moveRight()
  @moveRight()
  @moveUp()
  @moveDown()
  @moveDown()
  @attackNearbyEnemy()
  @moveUp()

# Kill the other ogres.
# Take care of your health also.
# Use a for-loop and you'll kill them all in just a few more lines.

COIN MANIA

Learn while-loops to grab coins and potions. - by Prabh Simran Singh Baweja

Difficulty: ★★


Code for plan() spell is here:

# Each coin has a gold value associated with it, but we don't know how much.
#In such cases, we use while loop.
# Let's say I want to collect gold with total value 20.
# Here we use while loop, as we don't know how long the loop will run.
@moveRight()  while @gold < 40

# Now collect coins worth 40.
# If you want to kill the ogre, be careful as you will need atleast 70 health.
# Note: Mushrooms will decrease your health, which might even kill you.
# Write the while loop smartly.
# Your code here.
@moveUp()
@moveUp()
@moveLeft()
@moveLeft()
@attackNearbyEnemy()

#@moveRight()  while @health < 80
#while(@distance({x: 69, y: 33})>20)
#@moveLeft()  while @distance(@getNearestEnemy()) > 23

FIND THE SPY

Identify the spies hidden among your soldiers - by Nathan Gossett

Difficulty: ★★


Code for chooseAction() spell is here:

soldiers = @getCombatants()

#Just killing the first soldier doesn't seem like a winning strategy...
#Click the "Guide" button if you need a hint on telling who is on what team

for soldier in soldiers
  if soldier and soldier.team is "ogres"
    @setTarget soldier
    if @distanceTo(soldier) > @attackRange
      @setAction "move"
    else
      @setAction "attack"

HARVEST TIME

Collect a hundred mushrooms in just five lines of code - by Nathan Gossett

Difficulty: ★★


Code for plan() spell is here:

#This line of code will get the 
#peasant to the first mushroom
#This line of code will get the 
#peasant to the first mushroom
#@moveXY @xmin, @ymin

#These mushrooms have x coordinates 
#between xmin and xmax
#These mushrooms have y coordinates 
#between ymin and ymax
#Try using loops to harvest all of the 
#mushrooms without having to type very 
#many lines of code. 
#It can be done in less than 5 lines!

#Try to have the @moveXY() function show up 
#as few times as possible in your code
for x in [@xmin..@xmax] by 10
  for y in [@ymin..@ymax] by @ymax-@ymin
    @moveXY x, y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment