Harrowland - conceptual issues, multiple loops

First, I haven’t posted any code in this topic because I am trying to understand the conceptual issues.

Second, I am working on Harrowland. My assumptions are 1) the Simple CPU is set to be approximately equal to whatever character I use. 2) the Simple CPU is set to run a simple, not terribly efficient set of loops 3) the problem is designed to test for the ability to write a more efficient loop than the Simple CPU is using.

Third) I have come close to winning, but have not won.

Fourth) I think the solution is to sort the enemies to first ignore the yaks, second attack the throwers, third reduce the remaining sub-enemies and finally to attack the Hero.

I only know the type of “sand-yak” and “archer”. I don’t know the type of the other sub-enemies or the hero.

I am only using “loop” and “while”. I don’t know if I missed a lesson on “for” loops or if they are being reserved for later lessons. I think that the “for” loop would be helpful here, but I could be wrong.

The best solution that I can imagine, but I don’t know how to execute, is to sort the Hero and the sand-yaks out of “enemies = self.findEnemies()” and create a second array of the remaining sub-enemies. Once, I had cycled through the second array, I could attack the Hero.

I have tried to simulate that tactic with successive loops. I am not having very much luck. Assuming that the remarks above indicate that I understand the problem, I have some specific questions.

  1. What are the types of the enemies in the problem and how can I identify them myself?
  2. Should I be using “for” statements to solve the problem, and where do I find the information on them?
  3. Is it possible to implement nested “loop” statements efficiently?
  4. Is somebody willing to discuss how “while” loops end?

Thank you very much,
George34

enemyDef.type=["catapult","munchkin","scout","thrower","chieftain","witch","ogre",
	"warlock","fangrider","headhunter","brawler","shaman","skeleton","tower",
     "decaying-skeleton","decaying-shaman","burl","sand-yak","ice-yak","yeti","door"];

Test the enemy type like this:

if enemy.type is not "yak":

Enemy hero or your hero is different. There can be of many types “captain”, “knight” "librarian"
Instead we use their id:
The Human hero is always Hero Placeholder
The Ogre hero is always Hero Placeholder 1

if enemy.id is "Hero Placeholder 1":
  1. http://www.tutorialspoint.com/python/python_for_loop.htm

Basically there are two types of loops.

  1. if you want just to get an element from an array:
for soldier in soldiers:
    self.command(soldier,...
  1. If you want to do something for each value of i from 2 to N-1 (!!! stops before N)
for i in range(2,N):

A specific case is when you want to iterate over a list but you also want to know the exact position you are in the list.
len(my_list) says how long is your list

for i in range(len(soldiers)):
  self.command(soldiers[i],"defend",my_points[i]

Here we have two lists and we want the 3rd soldier to go to the 3rd point in my list of points.

If you use a loop you need to break out of it:

loop:
   #do stuff
   if something_happend:
        break;

Generally you can implement it with a while. Loop is codeCombat construction, in reallity is equivalent to while(true)

while (something_no_yet_happened)
   do stuff 

After your code is executed a test is performed to see if the something_no_yet_happened is true, If it is true you get out of the loop

enemies =self.findEnemies()
i=0
while (i < len(enemies)):
    enemy=enemies[i]   #start looking at the enemy on the position i  
    while(enemy.health>0):  #not dead yet
        self.attack(enemy)
   i++   #add 1 to i so in the next loop you'll look at the next enemy in list

In harrowland the enemy hero has the same equipment as your hero and it always attacks his nearest enemy.

You have to do better than this:

  1. attack a better target
  2. or use equipment with special properties: cleave, shield bash, ranger’s throws, wizard’s spells etc

Hoo ah!

Your answers are always very useful.

Thank you very much.

George34

It may be worth checking out my posters on this forum (post 2)

It has lost of example code and this (although I am missing some types):

Thank you Hinkle.

The documents and the posters are very helpful. I am doing this with my son (11), and I thought that I was going to have to generate some kind of guide for him. These are far, far better than anything I could hope to do with the time I have available. Thanks for making them available.

Thanks,
George34