Skip to content

Commit e82b291

Browse files
author
Kristian Saarela
committed
syntax fixes in example code; examples now use block comments for easier use
1 parent 2273a34 commit e82b291

File tree

2 files changed

+96
-80
lines changed

2 files changed

+96
-80
lines changed

hero.js

Lines changed: 95 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
33
The only function that is required in this file is the "move" function
44
@@ -9,8 +9,8 @@
99
1010
The "move" function must return "North", "South", "East", "West", or "Stay"
1111
(Anything else will be interpreted by the game as "Stay")
12-
13-
The "move" function should accept two arguments that the website will be passing in:
12+
13+
The "move" function should accept two arguments that the website will be passing in:
1414
- a "gameData" object which holds all information about the current state
1515
of the battle
1616
@@ -31,7 +31,7 @@
3131
// Aggressor
3232
var move = function(gameData, helpers) {
3333
// Here, we ask if your hero's health is below 30
34-
if (gameData.activeHero().health <= 30){
34+
if (gameData.activeHero.health <= 30){
3535
// If it is, head towards the nearest health well
3636
return helpers.findNearestHealthWell(gameData);
3737
} else {
@@ -40,72 +40,84 @@ var move = function(gameData, helpers) {
4040
}
4141
};
4242
*/
43+
4344
/*
4445
// Health Nut
4546
var move = function(gameData, helpers) {
4647
// Here, we ask if your hero's health is below 75
47-
if (gameData.activeHero().health <= 75){
48+
if (gameData.activeHero.health <= 75){
4849
// If it is, head towards the nearest health well
4950
return helpers.findNearestHealthWell(gameData);
5051
} else {
5152
// Otherwise, go mine some diamonds!!!
52-
return helpers.findNearestDiamondMine(gameData);
53+
return helpers.findNearestNonTeamDiamondMine(gameData);
5354
}
5455
};
5556
*/
57+
5658
// Balanced
5759

5860
//TL;DR: If you are new, just uncomment the 'move' function that you think sounds like fun!
5961
// (and comment out all the other move functions)
6062

63+
/*
64+
// The "Northerner"
65+
// This hero will walk North. Always.
66+
var move = function(gameData, helpers) {
67+
var myHero = gameData.activeHero;
68+
return 'North';
69+
};
70+
*/
71+
72+
/*
73+
// The "Blind Man"
74+
// This hero will walk in a random direction each turn.
75+
var move = function(gameData, helpers) {
76+
var myHero = gameData.activeHero;
77+
var choices = ['North', 'South', 'East', 'West'];
78+
return choices[Math.floor(Math.random()*4)];
79+
};
80+
*/
81+
82+
/*
83+
// The "Priest"
84+
// This hero will heal nearby friendly champions.
85+
var move = function(gameData, helpers) {
86+
var myHero = gameData.activeHero;
87+
if (myHero.health < 60) {
88+
return helpers.findNearestHealthWell(gameData);
89+
} else {
90+
return helpers.findNearestTeamMember(gameData);
91+
}
92+
};
93+
*/
94+
95+
/*
96+
// The "Unwise Assassin"
97+
// This hero will attempt to kill the closest enemy hero. No matter what.
98+
var move = function(gameData, helpers) {
99+
var myHero = gameData.activeHero;
100+
if (myHero.health < 30) {
101+
return helpers.findNearestHealthWell(gameData);
102+
} else {
103+
return helpers.findNearestEnemy(gameData);
104+
}
105+
};
106+
*/
107+
108+
/*
109+
// The "Careful Assassin"
110+
// This hero will attempt to kill the closest weaker enemy hero.
111+
var move = function(gameData, helpers) {
112+
var myHero = gameData.activeHero;
113+
if (myHero.health < 50) {
114+
return helpers.findNearestHealthWell(gameData);
115+
} else {
116+
return helpers.findNearestWeakerEnemy(gameData);
117+
}
118+
};
119+
*/
61120

62-
// // The "Northerner"
63-
// // This hero will walk North. Always.
64-
// var move = function(gameData, helpers) {
65-
// var myHero = gameData.activeHero;
66-
// return 'North';
67-
// };
68-
69-
// // The "Blind Man"
70-
// // This hero will walk in a random direction each turn.
71-
// var move = function(gameData, helpers) {
72-
// var myHero = gameData.activeHero;
73-
// var choices = ['North', 'South', 'East', 'West'];
74-
// return choices[Math.floor(Math.random()*4)];
75-
// };
76-
77-
// // The "Priest"
78-
// // This hero will heal nearby friendly champions.
79-
// var move = function(gameData, helpers) {
80-
// var myHero = gameData.activeHero;
81-
// if (myHero.health < 60) {
82-
// return helpers.findNearestHealthWell(gameData);
83-
// } else {
84-
// return helpers.findNearestTeamMember(gameData);
85-
// }
86-
// };
87-
88-
// // The "Unwise Assassin"
89-
// // This hero will attempt to kill the closest enemy hero. No matter what.
90-
// var move = function(gameData, helpers) {
91-
// var myHero = gameData.activeHero;
92-
// if (myHero.health < 30) {
93-
// return helpers.findNearestHealthWell(gameData);
94-
// } else {
95-
// return helpers.findNearestEnemy(gameData);
96-
// }
97-
// };
98-
99-
// // The "Careful Assassin"
100-
// // This hero will attempt to kill the closest weaker enemy hero.
101-
// var move = function(gameData, helpers) {
102-
// var myHero = gameData.activeHero;
103-
// if (myHero.health < 50) {
104-
// return helpers.findNearestHealthWell(gameData);
105-
// } else {
106-
// return helpers.findNearestWeakerEnemy(gameData);
107-
// }
108-
// };
109121

110122
// The "Safe Diamond Miner"
111123
// This hero will attempt to capture enemy diamond mines.
@@ -120,7 +132,7 @@ var move = function(gameData, helpers) {
120132
});
121133
var distanceToHealthWell = healthWellStats.distance;
122134
var directionToHealthWell = healthWellStats.direction;
123-
135+
124136

125137
if (myHero.health < 40) {
126138
//Heal no matter what if low health
@@ -135,38 +147,42 @@ var move = function(gameData, helpers) {
135147
};
136148

137149

138-
// // The "Selfish Diamond Miner"
139-
// // This hero will attempt to capture diamond mines (even those owned by teammates).
140-
// var move = function(gameData, helpers) {
141-
// var myHero = gameData.activeHero;
150+
/*
151+
// The "Selfish Diamond Miner"
152+
// This hero will attempt to capture diamond mines (even those owned by teammates).
153+
var move = function(gameData, helpers) {
154+
var myHero = gameData.activeHero;
142155
143156
//Get stats on the nearest health well
144-
// var healthWellStats = helpers.findNearestObjectDirectionAndDistance(gameData.board, myHero, function(boardTile) {
145-
// if (boardTile.type === 'HealthWell') {
146-
// return true;
147-
// }
148-
// });
157+
var healthWellStats = helpers.findNearestObjectDirectionAndDistance(gameData.board, myHero, function(boardTile) {
158+
if (boardTile.type === 'HealthWell') {
159+
return true;
160+
}
161+
});
149162
150-
// var distanceToHealthWell = healthWellStats.distance;
151-
// var directionToHealthWell = healthWellStats.direction;
163+
var distanceToHealthWell = healthWellStats.distance;
164+
var directionToHealthWell = healthWellStats.direction;
152165
153-
// if (myHero.health < 40) {
166+
if (myHero.health < 40) {
154167
//Heal no matter what if low health
155-
// return directionToHealthWell;
156-
// } else if (myHero.health < 100 && distanceToHealthWell === 1) {
168+
return directionToHealthWell;
169+
} else if (myHero.health < 100 && distanceToHealthWell === 1) {
157170
//Heal if you aren't full health and are close to a health well already
158-
// return directionToHealthWell;
159-
// } else {
171+
return directionToHealthWell;
172+
} else {
160173
//If healthy, go capture a diamond mine!
161-
// return helpers.findNearestUnownedDiamondMine(gameData);
162-
// }
163-
// };
164-
165-
// // The "Coward"
166-
// // This hero will try really hard not to die.
167-
// var move = function(gameData, helpers) {
168-
// return helpers.findNearestHealthWell(gameData);
169-
// }
174+
return helpers.findNearestUnownedDiamondMine(gameData);
175+
}
176+
};
177+
*/
178+
179+
/*
180+
// The "Coward"
181+
// This hero will try really hard not to die.
182+
var move = function(gameData, helpers) {
183+
return helpers.findNearestHealthWell(gameData);
184+
};
185+
*/
170186

171187
// Export the move function here
172188
module.exports = move;

test_your_hero_code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If you'd like to test your hero code locally,
44
run this code using node (must have node installed).
55
66
Please note that you DO NOT need to do this to enter javascript
7-
battle, it is simply an easy way to test whether your new hero
7+
battle, it is simply an easy way to test whether your new hero
88
code will work in the javascript battle.
99
1010
To run:

0 commit comments

Comments
 (0)