I have already gotten help within a previous post, which I appreciate, but the issue is that this help altered default code given to you when starting/resetting the level and still does not work properly. Instead of assigning reindeer to pens like it’s supposed to, it instead assigns all empty pens to a single reindeer (Vixen) excluding all pens already occupied, and then Vixen moves to the rightmost pen being the last pen they were commanded to move to.
// This is the array of pen positions
var penPositions = [ {x:20,y:24}, {x:28,y:24}, {x:36,y:24}, {x:44,y:24}, {x:52,y:24} ];
// Use this array to keep track of each pen's reindeer.
var penOccupants = [ null, null, null, null, null ];
// And this array contains our reindeer.
var friends = hero.findFriends();
// Figure out which reindeer are already in their pens.
var reindeer = null;
for (let deerIndex = 0; deerIndex < friends.length; deerIndex++) {
reindeer = friends[deerIndex];
// For each position check if it matches a reindeer.
for (let penIndex = 0; penIndex < penPositions.length; penIndex++) {
var penPos = penPositions[penIndex];
if (penPos.x === reindeer.pos.x && penPos.y === reindeer.pos.y) {
// Put the reindeer in occupants at penIndex
penOccupants[penIndex] = reindeer;
// Remove the reindeer from the friends array.
friends[deerIndex] = null;
// break out of the inner loop here:
break;
}
}
}
// Assign the remaining reindeer to new positions.
for (deerIndex = 0; deerIndex < friends.length; deerIndex++) {
// If the reindeer is null, use continue:
if(reindeer === null){
continue;
}
// Look for the first pen with nothing.
for (var occIndex = 0; occIndex < penOccupants.length; occIndex++) {
// If there is nothing, the pen is open:
if (penOccupants[occIndex] === null) {
// Put the reindeer in the occupants array.
penOccupants[occIndex] = reindeer;
// Command the reindeer to move to the pen.
var targetPenPos = penPositions[occIndex];
hero.command(reindeer,"move",targetPenPos);
// break out early so we don't reassign:
break;
}
}
}
hero.say(penOccupants)
This code block includes the hero.say I used for debugging when it comes to the occupants for each pen.
I am labeling this as, even with much help within a previous post, it does not work properly and the post has gone without replies for a long stretch of time, so I feel it is safe to assume it is a bug. If anyone knows any workarounds I can use or if I’m simply missing something (which could be considered a “bug” anyways because chances are it’s in the starter code which is meant to work properly, and you write maybe 5-10 lines on this level), it would be appreciated if you could put it here.
What is also frustrating is that I have attempted to write my own code to complete this level, to no avail. My custom code falls short, in a similar fashion that the code I currently have does. As far as I can tell, it is an issue with CodeCombat in some form and not me or my code, especially as I have tried multiple different approaches just for it all to end the same way. I even try just commanding them all to go to a pen that matches the reindeer’s index, and it works properly yet does not fulfil the objective anyways.
TL;DR the level won’t work properly, as the default code results in a unsatisfactory result that does not complete the level and should not occur, and similar issues occur with custom written code in multiple different approaches. Even taking a “cheaty” approach and having all the reindeer move to a pen that matches their index does not result in the level being cleared.
For situations like this where a level won’t work correctly, a “skip level” option would be nice.