Monday, December 7, 2015

#Tuesday #Coding --- Coding is firstly about problem-solving, then about writing code --- Practicing Python coding by playing game


I came across this coding game “CodeCombat” last Friday, and just found it super addictive! So I tried to beat those levels when I was not developing my own game. It’s also very good for coding practicing (Python or JavaScript). I chose Python ‘cause I will be using Python in my own game.

For the first map “Kithgard Dungeon”, I finished nearly all FREE levels (dude_at_large is very mean, doesn’t want to play any paid levels! Those blue icons are paid levels. ). Now I’m exploring the second map “Backwoods Forest”.  And the latest level I finished is “Hold the Forest Pass”. Then I thought I may need to capture the coding screen for my own reference, also maybe I can upload onto my dev blog to share with people who are into Python. If you are a Python guru, definitely you can skip this. If you wanna try CodeCombat by yourself, highly recommend (I have no affiliation to this game company, simply a Python learner / lover)! After successfully beating each level, you will be able to access the leaderboards where you can watch someone coding in a super-fast way (Amazing)! Anyway, I will trace back all the levels I played and capture/upload the screenshot of each level onto this blog every Tuesday, as documentation --to build up my own coding library:-) !









Back to the “Hold the Forest Pass” which is today's coding content, at this level, we will be able to place the flag in the real time testing. This level is strategically fun. Coding correctly is one thing, but how to place the flag efficiently in real time is another thing, which needs practicing (at least for me)!

Our three, actually 4 goals on this level:
  • Defeat the ogres.
  • Your hero must survive.
  • Your horse must survive.
  • Optional goal: Lure ogres into an ambush.

Coding is as following:

loop:
       enemy  =  self.findNearestEnemy()
             flag  =  self.findFlag()

             if flag:     
                  self.pickUpFlag(flag)

             elif enemy:
                  distance  =  self.distanceTo(enemy)
                  if self.isReady(“cleave”) and distance < 10:
                       self.cleave(enemy)
                  else:
                        self.shield(enemy)

      In fact, I don’t think ‘’to lure ogres into an ambush’’ is an optional goal. I think it is a condition. If we are unable to lure those giant ogres into the left ambush (our white-hat allies), then we won’t defeat those giant ogres rushing into the right hand side, which is overwhelming. That is also a good example of game-balance design. Our hero’s single powerful skill ‘’cleave (target)’’ could only beat those little ogres, it doesn’t kill those giant ogres.  So here the best strategy is to divide those giant ogres by luring some giants to the left ambush, then let our allies (white hat allies ) attack them, and then another group of our allies at right-hand side will be able to defeat the giant ogres coming from right path…Weakening our enemy by dividing them. However, don’t spend too much time to lure the giant ogres otherwise our hero may lose the health! 

     In this case, our hero will be a ‘’sweet bat’’, and won’t die as a hero.

I do agree someone’s saying that ‘’programming is firstly about problem-solving, then about writing code”.  Syntax is a rigid stuff, yet problem-solving is flexible and creative.
     **************

      "The only war I want to see is in the game, the only enemy I want to have is in the game --- dude_at_large “

No comments:

Post a Comment