Skip to content

Commit ac4ab3b

Browse files
committed
Add parity change
1 parent a0dd7f0 commit ac4ab3b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/variety/diamond.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,42 @@
6767
mouseinput_clear: function() {
6868
this.inputFixedNumber(-1);
6969
},
70+
initialize: function() {
71+
this.prevDiamond = new this.klass.Address();
72+
this.common.initialize.call(this);
73+
},
74+
mousereset: function() {
75+
this.prevDiamond.reset();
76+
this.common.mousereset.call(this);
77+
},
7078

7179
inputcross: function(fixed) {
7280
if (this.inputData !== null && this.inputData < 8) {
7381
return;
7482
}
83+
84+
var prev = this.prevDiamond.getx();
7585
var cross = this.getcross();
86+
if (!prev.isnull) {
87+
var cell = this.getcell();
88+
var candidate = null;
89+
90+
// Prefer crosses that share a parity with the last placed diamond
91+
if (Math.abs(cell.bx - prev.bx) + Math.abs(cell.by - prev.by) === 4) {
92+
if (cell.bx > prev.bx + 1) {
93+
candidate = prev.relcross(4, 0);
94+
} else if (cell.bx < prev.bx - 1) {
95+
candidate = prev.relcross(-4, 0);
96+
} else if (cell.by > prev.by + 1) {
97+
candidate = prev.relcross(0, 4);
98+
} else if (cell.by < prev.by - 1) {
99+
candidate = prev.relcross(0, -4);
100+
}
101+
}
102+
if (candidate && !candidate.overlapsDiamond()) {
103+
cross = candidate;
104+
}
105+
}
76106
if (this.prevPos.equals(cross)) {
77107
return;
78108
}
@@ -96,6 +126,9 @@
96126
this.inputData |= 8;
97127
}
98128
cross.setDiamond(this.inputData & 7);
129+
if (cross.getDiamond() === 1) {
130+
this.prevDiamond.set(cross);
131+
}
99132
cross.draw();
100133
}
101134
},

0 commit comments

Comments
 (0)