forked from JavascriptBattle/hero-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.js
executable file
·218 lines (182 loc) · 7.02 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
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
(the details of these objects can be found on javascriptbattle.com/#rules)
Such is the power of Javascript!!!
*/
// 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){
//FIXME : fix;
return null;
},
// The "Northerner"
// This hero will walk North. Always.
northener : function(gameData, helpers) {
var myHero = gameData.activeHero;
return 'North';
},
// The "Blind Man"
// This hero will walk in a random direction each turn.
blindMan : function(gameData, helpers) {
var myHero = gameData.activeHero;
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);
},
ultimateWarrior :function(gameData, helpers) {
var myHero = gameData.activeHero;
var healthWellStats = helpers.findNearestObjectDirectionAndDistance(gameData.board, myHero, function(boardTile) {
if (boardTile.type === 'HealthWell') {
return true;
}
});
var weakerEnemyStats = helpers.findNearestObjectDirectionAndDistance(gameData.board, myHero, function(enemyTile) {
return enemyTile.type === 'Hero' && enemyTile.team !== myHero.team && enemyTile.health < myHero.health;
});
var distanceToWeakerEnemy = weakerEnemyStats.distance;
var directionToWeakerEnemy = weakerEnemyStats.direction;
var distanceToHealthWell = healthWellStats.distance;
var directionToHealthWell = healthWellStats.direction;
if (myHero.health < 50) {
//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 (distanceToWeakerEnemy < 3) {
return directionToWeakerEnemy;
}
//If healthy, go capture a diamond mine!
return helpers.findNearestUnownedDiamondMine(gameData);
}
}
// Set our heros strategy
var move = moves.ultimateWarrior;
// Export the move function here
module.exports = move;