Skip to content

Commit

Permalink
puzz.link midloop
Browse files Browse the repository at this point in the history
  • Loading branch information
nmay231 committed Oct 6, 2021
1 parent 0ab9d24 commit 7d7d692
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/js/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,19 @@ function decode_puzzlink(url) {
pu["pu_q"].number[cell] = [number, info_number[i] % 2 ? 4 : 1, "1"];
}

pu.mode_qa("pu_a");
pu.mode_set("combi");
pu.subcombimode("linex");
this.usertab_choices = ["Surface", "Composite"];
break;
case "midloop":
pu = new Puzzle_square(cols, rows, size);
pu.mode_grid("nb_grid2"); // Dashed gridlines
setupProblem(pu, "combi");

info_edge = puzzlink_pu.decodeMidloop();
puzzlink_pu.drawMidloop(pu, info_edge);

pu.mode_qa("pu_a");
pu.mode_set("combi");
pu.subcombimode("linex");
Expand Down
48 changes: 48 additions & 0 deletions docs/js/puzzlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,54 @@ class Puzzlink {
}
return new_numbers;
}

decodeMidloop() {
// Every cell, corner and edge is a point, unless it is on the grid edge.
// Small even digits are white dots. Small odd digits are black dots.
// Large digits/characters are spacing
var points = {};
var i = 0;
for (var char of this.gridurl) {
char = parseInt(char, 36);
if (0 <= char && char < 16) {
points[i] = char % 2;
i += parseInt(char / 2) + 1;
} else {
i += char - 15;
}
}
return points;
}

drawMidloop(pu, info, behind_line = 2) {
var row_ind, col_ind, cell;
for (var i in info) {
row_ind = parseInt(i / (2 * this.cols - 1));
col_ind = i % (2 * this.cols - 1);
if (row_ind % 2 === 0 && col_ind % 2 === 0) {
// cell center
row_ind = (row_ind) / 2;
col_ind = (col_ind) / 2;
cell = pu.nx0 * (2 + row_ind) + 2 + col_ind;
} else if (col_ind % 2 === 0) {
// vertical edge
row_ind = (row_ind - 1) / 2;
col_ind = (col_ind) / 2;
cell = 2 * pu.nx0 * pu.ny0 + pu.nx0 * (2 + row_ind) + 2 + col_ind;
} else if (row_ind % 2 === 0) {
// horizonal edge
row_ind = (row_ind) / 2;
col_ind = (col_ind - 1) / 2;
cell = 3 * pu.nx0 * pu.ny0 + pu.nx0 * (2 + row_ind) + 2 + col_ind;
} else {
// corner/vertex
row_ind = (row_ind - 1) / 2;
col_ind = (col_ind - 1) / 2;
cell = pu.nx0 * pu.ny0 + pu.nx0 * (2 + row_ind) + 2 + col_ind;
}
pu["pu_q"].symbol[cell] = [info[i] + 1, "circle_S", behind_line];
}
}
}

class DisjointSets {
Expand Down

0 comments on commit 7d7d692

Please sign in to comment.