PLZ PLZ PLZ give me solution for GRidmancer


#1

PLZ PLZ PLZ give me solution for GRidmancer


#2

When asking for help on a level, it is better to ask specific questions about your own code rather than just asking for the solution. What are you having trouble with?

Gridmancer is an older level and I believe that there have been some posts and discussions of it:

If you read up there you can learn a lot about the level and programming.


#3

Heres my link:

Help me I beg u. Put the solution in.


#4

That looks like it is still the original sample code.

Sorry, I’m too much of a teacher to just give answers, if you can’t be bothered to start it on your own or to read a blog post about it, I’m not going to just give you an answer.


#5

Providing a link to a level does not give them your solution. Instead it will always use the user’s solution. It might look like the original code if you haven’t played that level yet. The logic here is that the session id simply saves the enemy’s submission, so you could test against it again.

Also, like dwhittaker suggested, instead of simply asking for a solution you should aim to see what troubled you and fix that. You want to learn instead of just getting answers, or else you’ll be here asking again the next time. Explaining what you have specifically have trouble with would be more beneficial to everyone.


#6

Thanks. I played round with my code and I have covered all the grid but it still dosen’t say I’m done. Please have a look at it and fix if you can.

Link is:


#7

Again, the link you provide does NOT allow us to view your code. Giving a session link will play against the opponent with my code. It simply plugs my code into some instance of the level. If you want us to view your code, you’re going to need to put it somewhere in plaintext for us to look at.


#8

The Gridmancer level doesn’t actually have a victory trigger, even if you get down to solving it in the optimal 29 non-overlapping rectangles, so it’s up to you to decide when your solution is good enough.


#9

Heres my code:

// Fill the empty space with the minimum number of rectangles.
// (Rectangles should not overlap each other or walls.)
// The grid size is 1 meter, but the smallest wall/floor tile is 4 meters.
// Check the blue guide button at the top for more info.
// Make sure to sign up on the home page to save your code.
var grid = this.getNavGrid().grid;
var tileSize = 4;
for (var y = 0; y + tileSize < grid.length; y += tileSize) {
for (var x = 0; x + tileSize < grid[0].length; x += tileSize) {
var occupied = grid[y][x].length > 0;
if (!occupied) {
this.addRect(x + tileSize / 2, y + tileSize / 2, tileSize, tileSize);
this.wait(); // Hover over the timeline to help debug!
}
}
}
var tileSize = 4;
var xRangeHash = {};
for (var y = 0; y + tileSize < grid.length; y += tileSize) {
xRangeHash[y] = {};
var currentXRange = [];
for (var x = 0; x + tileSize < grid.length; x += tileSize) {
var occupied = grid[y][x].length > 0;
if (!occupied) {
currentXRange.push(x);
} else if (currentXRange.length > 0) {
currentXRange.push(x);
var terminus = currentXRange.length - 1;
xRangeHash[y][currentXRange[0]] = { “finish”: currentXRange[terminus] };
currentXRange = [];
} else {
currentXRange = [];
}
}
}
var potentialRanges = [];
for (var y in xRangeHash) {
for (var start in xRangeHash[y]) {
var finish = xRangeHash[y][start].finish;
var indexOfOldRange = false;
var rangeArray = [
start,
finish
];
for (var i = 0; i < potentialRanges.length; i++) {
if (potentialRanges[i][0] == rangeArray[0] && potentialRanges[i][1] == rangeArray[1]) {
indexOfOldRange = i;
break;
}
}
if (indexOfOldRange !== false) {
potentialRanges[indexOfOldRange][2] += tileSize;
potentialRanges[indexOfOldRange][3] = y;
} else {
potentialRanges.push([
start,
finish,
tileSize,
y
]);
}
}
for (var i = potentialRanges.length - 1; i > -1; i–) {
if (potentialRanges[i][3] != y) {
var xCenter = potentialRanges[i][0] / 2 + potentialRanges[i][1] / 2;
var yCenter = y - potentialRanges[i][2] / 2;
var xSpan = potentialRanges[i][1] - potentialRanges[i][0];
var ySpan = potentialRanges[i][2];
this.addRect(xCenter, yCenter, xSpan, ySpan);
potentialRanges.splice(i, 1);
}
}
}