-
Notifications
You must be signed in to change notification settings - Fork 128
/
hero.js
186 lines (159 loc) · 6.34 KB
/
hero.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* eslint no-unused-vars: 0 */
/*
Strategies for the hero are contained within the "moves" object as
name-value pairs, like so:
//...
ambusher : function(gamedData, helpers){
// implementation of strategy.
},
heWhoLivesToFightAnotherDay: function(gamedData, helpers){
// implementation of strategy.
},
//...other strategy definitions.
The "moves" object only contains the data, but in order for a specific
strategy to be implemented we MUST set the "move" variable to a
definite property. This is done like so:
move = moves.heWhoLivesToFightAnotherDay;
You MUST also export the move function, in order for your code to run
So, at the bottom of this code, keep the line that says:
module.exports = move;
The "move" function must return "North", "South", "East", "West", or "Stay"
(Anything else will be interpreted by the game as "Stay")
The "move" function should accept two arguments that the website will be passing in:
- a "gameData" object which holds all information about the current state
of the battle
- a "helpers" object, which contains useful helper functions
- check out the helpers.js file to see what is available to you
*/
// Strategy definitions
var moves = {
// Aggressor
aggressor: function (gameData, helpers) {
// Here, we ask if your hero's health is below 30
if (gameData.activeHero.health <= 30){
// If it is, head towards the nearest health well
return helpers.findNearestHealthWell(gameData);
} else {
// Otherwise, go attack someone...anyone.
return helpers.findNearestEnemy(gameData);
}
},
// Health Nut
healthNut: function (gameData, helpers) {
// Here, we ask if your hero's health is below 75
if (gameData.activeHero.health <= 75){
// If it is, head towards the nearest health well
return helpers.findNearestHealthWell(gameData);
} else {
// Otherwise, go mine some diamonds!!!
return helpers.findNearestNonTeamDiamondMine(gameData);
}
},
// Balanced
balanced: function (gameData, helpers){
// Here we determine if it's an even or odd turn for your hero;
if ((gameData.turn / 2) % 2) {
// If it is even, act like an an Aggressor
return moves.aggressor(gameData, helpers);
} else {
// If it is odd, act like a Priest
return moves.priest(gameData, helpers);
}
},
// The "Northerner"
// This hero will walk North. Always.
northener: function (gameData, helpers) {
return 'North';
},
// The "Blind Man"
// This hero will walk in a random direction each turn.
blindMan: function (gameData, helpers) {
var choices = ['North', 'South', 'East', 'West'];
return choices[Math.floor(Math.random()*4)];
},
// The "Priest"
// This hero will heal nearby friendly champions.
priest: function (gameData, helpers) {
var myHero = gameData.activeHero;
if (myHero.health < 60) {
return helpers.findNearestHealthWell(gameData);
} else {
return helpers.findNearestTeamMember(gameData);
}
},
// The "Unwise Assassin"
// This hero will attempt to kill the closest enemy hero. No matter what.
unwiseAssassin: function (gameData, helpers) {
var myHero = gameData.activeHero;
if (myHero.health < 30) {
return helpers.findNearestHealthWell(gameData);
} else {
return helpers.findNearestEnemy(gameData);
}
},
// The "Careful Assassin"
// This hero will attempt to kill the closest weaker enemy hero.
carefulAssassin: function (gameData, helpers) {
var myHero = gameData.activeHero;
if (myHero.health < 50) {
return helpers.findNearestHealthWell(gameData);
} else {
return helpers.findNearestWeakerEnemy(gameData);
}
},
// The "Safe Diamond Miner"
// This hero will attempt to capture enemy diamond mines.
safeDiamondMiner: function (gameData, helpers) {
var myHero = gameData.activeHero;
// Get stats on the nearest health well
var healthWellStats = helpers.findNearestObjectDirectionAndDistance(gameData.board, myHero, function (boardTile) {
if (boardTile.type === 'HealthWell') {
return true;
}
});
var distanceToHealthWell = healthWellStats.distance;
var directionToHealthWell = healthWellStats.direction;
if (myHero.health < 40) {
// Heal no matter what if low health
return directionToHealthWell;
} else if (myHero.health < 100 && distanceToHealthWell === 1) {
// Heal if you aren't full health and are close to a health well already
return directionToHealthWell;
} else {
// If healthy, go capture a diamond mine!
return helpers.findNearestNonTeamDiamondMine(gameData);
}
},
// The "Selfish Diamond Miner"
// This hero will attempt to capture diamond mines (even those owned by teammates).
selfishDiamondMiner: function (gameData, helpers) {
var myHero = gameData.activeHero;
// Get stats on the nearest health well
var healthWellStats = helpers.findNearestObjectDirectionAndDistance(gameData.board, myHero, function (boardTile) {
if (boardTile.type === 'HealthWell') {
return true;
}
});
var distanceToHealthWell = healthWellStats.distance;
var directionToHealthWell = healthWellStats.direction;
if (myHero.health < 40) {
// Heal no matter what if low health
return directionToHealthWell;
} else if (myHero.health < 100 && distanceToHealthWell === 1) {
// Heal if you aren't full health and are close to a health well already
return directionToHealthWell;
} else {
// If healthy, go capture a diamond mine!
return helpers.findNearestUnownedDiamondMine(gameData);
}
},
// The "Coward"
// This hero will try really hard not to die.
coward: function (gameData, helpers) {
return helpers.findNearestHealthWell(gameData);
}
};
// Set our hero's strategy
var move = moves.aggressor;
// Export the move function here
module.exports = move;