This repository was archived by the owner on Jul 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.lks
More file actions
253 lines (208 loc) · 6.28 KB
/
test.lks
File metadata and controls
253 lines (208 loc) · 6.28 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
global turn = 0;
/*
* EASY
* - Take into account enemy weapons (memorize them)
* - Try to move away in priority (we can always move towards later)
* - Taunt if we're winning (but don't waste action points)
* - Function to check if we're safe (take into acount enemy movement)
* - Function to check in how many MP the enemy is reachable
* MEDIUM
* - Balance heals/attacks (right now we heal if we're low or critical)
* - Sort weapons based on damage/cost ratio
* HARD
* - Build a tree of possible actions to decide best damage throughoutput
* - Get all possible actions in an array, sorted by highest damage
* - Get the first elements of the array to construct our action list
* EXTREME
* - Terrain awareness, use objects to our advantage
* - Monte Carlo with known chips/weapons :D/
*/
turn += 1;
debug("==== Turn " + turn);
function tryMove(enemy)
{
var mpUsed = 1;
while (getMP() > 0
and !inWeaponRange(enemy, getWeapon())
and mpUsed > 0)
{
debug("In range: " + inWeaponRange(enemy, getWeapon()));
mpUsed = moveToward(enemy, 1);
debug(" > MOVE");
}
}
function getWeaponAverageDamage(weapon)
{
var effect = getDamageEffect(weapon);
return (effect[1] + effect[2]) / 2;
}
function getDamageEffect(weapon)
{
// [type, min, max, turns, targets]
var effects = getWeaponEffects(weapon);
for (var i = 0; i < count(effects); i++)
if (effects[i][0] == EFFECT_DAMAGE)
return effects[i];
return null;
}
function getBestWeapon(enemy)
{
var weapons = getWeapons();
var best = null;
var bestDamage = 0;
var bestTurns = 0;
var tp = getTP();
var me = getCell();
var them = getCell(enemy);
for (var i = 0; i < count(weapons); i++) {
var cur = weapons[i];
// check if we can fire this weapon now
if (isInlineWeapon(cur) and !isOnSameLine(me, them))
continue;
// check line of sight
if (weaponNeedLos(cur) and !lineOfSight(me, them))
continue;
// check range
if (getCellDistance(me, them) > getWeaponMaxRange(cur))
continue;
// calculate the damage for this weapon
var damage = getWeaponAverageDamage(cur); // [type, min, max, ...]
var switch = (getWeapon() == cur ? 0 : 1); // cost for switch
var turns = floor((tp - switch) / getWeaponCost(cur));
damage *= turns;
debug(getWeaponName(cur) + " would deal " + damage + " damage for " + turns + " turns");
if (damage > bestDamage)
{
bestDamage = damage;
bestTurns = turns;
best = cur;
}
}
debug("BEST: " + getWeaponName(best) + ", with " + bestDamage + " average for " + bestTurns + " turns");
return best;
}
function equipWeapon(weapon)
{
if (getWeapon() != weapon)
{
debug("WEAPON: " + getWeaponName(weapon));
setWeapon(weapon);
}
}
function tryChip(chip)
{
var result = useChip(chip, getLeek());
if(result == USE_SUCCESS)
debug(" > " + getChipName(chip));
return result;
}
function attack(enemy)
{
// TODO: Learn how to use other chips
debug(" > ATTACK");
return useWeapon(enemy) == USE_SUCCESS
or useChip(CHIP_SPARK, enemy) == USE_SUCCESS;
}
function heal()
{
debug(" > HEAL");
return useChip(CHIP_CURE, getLeek()) == USE_SUCCESS;
// or useChip(CHIP_BANDAGE, getLeek()) == USE_SUCCESS;
}
function isSafe()
{
//TODO: Safe
// distance > enemyMaxAttackDistance + enemyMovement
}
function inWeaponRange(enemy, weapon)
{
var me = getCell();
var them = getCell(enemy);
return lineOfSight(me, them)
and getCellDistance(me, them) <= getWeaponMaxRange(weapon);
}
// Fun message
if (turn == 1)
say("Bonne chance :D");
// Self chips (only use one)
var chipOrder = [CHIP_HELMET, CHIP_SHIELD, CHIP_WALL];
for (var i = 0; i < count(chipOrder); i++)
if (tryChip(chipOrder[i]) == USE_SUCCESS)
break;
// Get our enemy
var enemy = getNearestEnemy();
// Move in 1 increments
debug("==== Movement phase");
tryMove(enemy);
// Try to shoot 'em up!
debug("==== Action phase");
// Attempt to equip a weapon
var bestWeapon = getBestWeapon(enemy);
if (bestWeapon != null)
equipWeapon(bestWeapon);
else if(getWeapon() == null)
equipWeapon(WEAPON_PISTOL);
// try to move again
tryMove(enemy);
// ACTION
var didSomething = true;
var shouldFlee = false;
while (getTP() > 0 and didSomething)
{
didSomething = false;
var life = getLife() / getTotalLife();
debug("Life left: " + life);
var enemyLife = getLife(enemy);
var enemyLifeRatio = getLife() / (enemyLife == 0 ? 1 : enemyLife);
debug("Enemy life ratio: " + enemyLifeRatio);
if (life < 0.30 and enemyLifeRatio < 0.75) // I am a risk taker
{
didSomething = heal();
shouldFlee = true;
}
if (!didSomething) // I am a brain eater
didSomething = attack(enemy);
if (didSomething) // I am very danger
shouldFlee = false;
}
// Useful, I know. You'll thank me later!
if (getLife(enemy) == 0)
{
say("C'était amusant!");
return;
}
// Get cell to move to
debug("==== Flee phase");
var mpUsed = 1;
while (getMP() > 0 and mpUsed > 0)
{
mpUsed = 0;
var enemyDist = getCellDistance(getCell(), getCell(enemy)) + getMP(enemy);
debug("Enemy weapon range: " + getWeaponMaxRange(getWeapon(enemy)));
debug("Cell distance to enemy: " + (enemyDist - getMP(enemy)));
debug("Safe distance: " + enemyDist);
debug("Distance to enemy: " + getDistance(getCell(), getCell(enemy)));
debug("In range to shoot: " + inWeaponRange(enemy, getWeapon()));
// Run away
if (shouldFlee)
mpUsed = moveAwayFrom(enemy);
// Attempt to counter weapons with min range
if ((getWeaponMinRange(getWeapon(enemy)) > 1
and getWeaponMinRange(getWeapon(enemy)) > enemyDist))
mpUsed = moveToward(enemy, 1);
else if (getWeaponMaxRange(getWeapon(enemy)) < enemyDist)
mpUsed = moveAwayFrom(enemy, 1);
else if (getChipMaxRange(CHIP_SPARK) < enemyDist)
mpUsed = moveAwayFrom(enemy, 1);
else
mpUsed = moveAwayFrom(enemy); // Run
// else
// moveToward(enemy, 1); // maybe not a good idea :(
if (mpUsed > 0)
debug(" > MOVE");
}
if (getLife(enemy) <= 5)
{
say("T'en a de la chance toi... " + getLife(enemy) + " PV serieux >->;;");
}
debug(getOperations() + " operations");