@mercurym Congrats! Proud of you!
Ahh I lost to Durbination
Hey guys. Hero.mana says that itās defined, but is not being used for some reason. Was working in previous updates.
Is this an error?
@Venneth
@nick
Sorry for pinging you, but urgent as competition ends in few days.
Hello, can you provide a screenshot or a match link?
well #1 worldwide means number #1 in your age bracket too .-.
yeah lol but Im #3 now
compare that to what happend here :
Hey @MarmiteOnToast try translating this:
const allsquares = 'abcdefgh';
const possibleTowers = hero.availableTowerTypes; // better than calling it again and again
const tower = {
a: {name: 'none', level: 0},
b: {name: 'none', level: 0},
c: {name: 'none', level: 0},
d: {name: 'none', level: 0},
e: {name: 'none', level: 0},
f: {name: 'none', level: 0},
g: {name: 'none', level: 0},
h: {name: 'none', level: 0}
};
for (let p of Object.keys(tower)) tower[p]._squares = p;
const towerArray = [];
(function () {let keys = Object.keys(tower); for (let key of keys) towerArray.push(tower[key]);})();
const verify = (val, def) => (val === undefined ? def : val);
function randint (min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function sell (...args) {
if (possibleTowers.indexOf(args[0]) !== -1) {
if (JSON.stringify(args[1])[0] === '{') {
let amount = verify(args[1].amount, howMany(args[0]));
let startFromEnd = verify(args[1].startFromEnd, false);
let lowest = verify(args[1].lowest, true);
let squares;
if (amount > 0) {
let sl = Math[lowest ? 'min' : 'max'](... towerArray.filter(t => t.name === args[0]).map(t => t.level));
squares = allsquares.split('').filter(s => tower[s].name === args[0] && tower[s].level === sl);
} else return;
let already = [];
let v = [startFromEnd ? 0 : squares.length, startFromEnd ? squares.length : -1];
let i = v[0];
let pm=startFromEnd?(function(val){return val++;}):(function(val){return val--;});
mainloop: while (true) {
if (startFromEnd ? (i >= v[1]) : (i < v[1])) break;
if (Math.abs(i - v[0]) > amount) break;
if (args[1].random) {
let r = randint(0, squares.length - 1);
while (true) {
if (already.length === amount) break mainloop;
if (already.indexOf(r) === -1) break;
r = randint(0, squares.length - 1);
}
already.push(r);
build(squares[r]);
i = pm(i);
continue;
}
sell(squares[i]);
i = pm(i);
}
return;
}
if (args.length > 1) args = args.length > 1 ? args : args[0].split('');
for (let s of Object.keys(tower)) {
if (tower[s].name === args[0] && args.indexOf(s) === -1) {
hero.sell(s);
tower[s] = {name: 'none', level: 0};
}
}
return;
}
args = args.length > 1 ? args : args[0].split('');
for (let s of args){
hero.sell(s);
tower[s] = {name: 'none', level: 0};
}
}
const find = tt => towerArray.filter(t => t.name === tt);
const howMany = t => find(t).length;
const build = (t, s) => {
if (s.length > 1) {
let letters = s.split('');
for (let letter of letters) build(t, letter);
return;
}
if (tower[s].name !== t && tower[s].level !== 0) sell(s);
hero.build(t, s);
tower[s].name = t;
tower[s].level = tower[s].level + 1;
};
const towers = (start, end) => {
start = (start + 0 === start + '0') ? allsquares.indexOf(start) : start;
end = (end + 0 === end + '0') ? (allsquares.indexOf(end) + 2) : end;
let returnVar = [];
for (let i = start; i < end; i++) returnVar.push(tower[allsquares.charAt(i)]);
return returnVar;
}
const squares = (start, end) => {
start = (start + 0 === start + '0') ? allsquares.indexOf(start) : start;
end = (end + 0 === end + '0') ? (allsquares.indexOf(end) + 2) : end;
return allsquares.substring(start, end - start);
};
function upgrade (...args) {
if (args.length === 0) return upgrade(allsquares);
if (possibleTowers.indexOf(args[0]) !== -1) {
if (JSON.stringify(args[1])[0] === '{') {
let amount = verify(args[1].amount, howMany(args[0]));
let startFromEnd = verify(args[1].startFromEnd, false);
let lowest = verify(args[1].lowest, true);
let squares;
if (amount > 0) {
let sl = Math[lowest ? 'min' : 'max'](... towerArray.filter(t => t.name === args[0]).map(t => t.level));
squares = allsquares.split('').filter(s => tower[s].name === args[0] && tower[s].level === sl);
} else return;
let already = [];
let v = [startFromEnd ? 0 : squares.length, startFromEnd ? squares.length : -1];
let i = v[0];
let pm=startFromEnd?(function(val){return val++;}):(function(val){return val--;});
mainloop: while (true) {
if (startFromEnd ? (i >= v[1]) : (i < v[1])) break;
if (Math.abs(i - v[0]) > amount) break;
if (args[1].random) {
let r = randint(0, squares.length - 1);
while (true) {
if (already.length === amount) break mainloop;
if (already.indexOf(r) === -1) break;
r = randint(0, squares.length - 1);
}
already.push(r);
build(tower[squares[r]].name, squares[r]);
i = pm(i);
continue;
}
build(tower[squares[i]].name, squares[i]);
i = pm(i);
}
return;
}
if (args.length > 1) args = args.length > 1 ? args : args[0].split('');
for (let s of Object.keys(tower)) {
if (tower[s].name === args[0] && args.indexOf(s) === -1) {
build(tower[s].name, s);
}
}
return;
}
args = args.length > 1 ? args : args[0].split('');
for (let s of args) build(tower[s].name, s);
}
lol, omg thatās actually so long tho
Now my functions have the capability of doing this:
upgrade(typeOfBuilding, {random: true, amount: 8})
random
makes it just upgrade a random tower of that type that is at the lowest level, amount
makes it upgrade⦠well, a certain amount
of times, and it also has:
upgrade(typeOfBuilding, {startFromEnd: true, lowest: true})
I donāt remember what lowest
does, but I think it makes it start from the lowest level and if itās false then it starts from the highest? startFromEnd
makes it start from h
if random
is false and if startFromEnd
is false it starts from a
Default values: startFromEnd: false, random: false, lowest: true, amount: 1
I could make them with even more features but I feel like that would make the functions obnoxiously long and itās not really useful, like, if you canāt deal with any upgrading strategy with the code I gave you, like, dude, like, how, like, what? Like the amount of capabilities this code gives your building strategy-
When I was #1, I didnāt use rage and haste lol
how many lines is this code?
I found that a good way to deal good collective damage with the mage is to find the enemy that has the most enemies within 10 meters of it and have the mage target that enemy.
Sure Venneth.
Here is the match link.
[CodeCombat - Coding games to learn Python and JavaScript](https://Match Link)
hero.ability("summon", hero.mana)
Quite messy code, sorry. Just a work in progress.
Thank you for the match link, however your code ran just fine without any errors against that opponent
Thank you for the advice, Iām currently ranked 10th in my class, a good place to be honest, but I want to move up since it beat 1st and 3rd place but I canāt beat 7th and 6th, because I donāt do the enough points, and I wanted to see how I can upload that, also where I can put my code for improvements
Ah, okay then. It seems fixed, although now some games on home-ranking show lots of defeat when victory on a loaded game scene. Very annoying and the ranking falls from that.
Also noticed that VennethCC & Durbinationās codes cannot be rendered fully, and this makes it a tie, when by looking at the match on while true loop detection, seems like vennethCC wins.
We really need to limit the while true loops & sensors in our codes so ranking really balances out strongly.
Use this button to upload code:
The this will show up:
The copy and paste your code, and post. Once you do that, we can figure out how to improve your code and I can give you even more advice.
143