Some useful tips for CodeCombat players, mainly taken from the official forum
- Finding units stats
- Finding enemy hero in CodeCombat multiplayer
- Getting list of a certain type of enemies
All stats can be find here
Enemy hero id can be "Hero Placeholder"
or "Hero Placeholder 1"
.
Examples for finding enemy hero (best to just add these to the top of the code, outside the main loop, and forget):
In Python:
enemyHero = [e for e in self.findEnemies() if e.id in ["Hero Placeholder", "Hero Placeholder 1"]][0]
In JavaScript:
var enemyHero = this.findEnemies().filter(function (e) {
return e.id === 'Hero Placeholder' || e.id === 'Hero Placeholder 1';
})[0];
In mirror matches (Zero Sum, Ace of Coders) it's easier to just do
In Python:
enemyHero = self.findByType(self.type)[0] or self.findByType('knight')[0]
In JavaScript:
var enemyHero = this.findByType(this.type)[0] || this.findByType('knight')[0];
as both players have the same hero type (or Tharin if their game session is bugged out).
If you have good enough glasses to use findByType()
method, which allows you to find a unit by type, then for "archer"
type in Python it will be:
enemyArchers = self.findByType("archer")
But on the level Clash of Clones the enemy has the same type of units as you, so you would first need to find your enemies, and then identify the different types. Fortunately findByType()
method also accepts a second argument to filter the enemies from, so in Python it will be:
enemyArchers = self.findByType("archer", self.findEnemies())
If you don't have the findByType()
method, you can do it this way in Python:
enemies = self.findEnemies()
enemyArchers = []
for enemy in enemies:
if enemy.type == "archer":
# append it to the list
enemyArchers.append(enemy)
Or much shorter with Python's list comprehension:
enemyArchers = [enemy for enemy in self.findEnemies() if enemy.type == "archer"]