Make unrolled version of equals.
--- a/board.js Mon Sep 08 19:42:32 2014 +0300
+++ b/board.js Tue Sep 09 02:32:31 2014 +0300
@@ -59,13 +59,25 @@
BoardArr2d.prototype.set = function(i, j, val) {
this.brd[i][j] = val;
}
-BoardArr2d.prototype.equals = function(brd) {
+BoardArr2d.prototype.equals_loop = function(brd) {
for (var i = 0; i < 4; i++)
for (var j = 0; j < 4; j++)
if (this.brd[i][j] !== brd.brd[i][j])
return false;
return true;
}
+BoardArr2d.prototype.equals_unrolled = function(brd) {
+ var x0 = this.brd[0], x1 = this.brd[1], x2 = this.brd[2], x3 = this.brd[3]
+ var y0 = brd.brd[0], y1 = brd.brd[1], y2 = brd.brd[2], y3 = brd.brd[3];
+ // More often corners differ, check it first.
+ return x0[0] === y0[0] && x0[3] === y0[3] && x3[0] === y3[0] && x3[3] === y3[3]
+ && x0[1] === y0[1] && x0[2] === y0[2]
+ && x3[1] === y3[1] && x3[2] === y3[2]
+ && x1[0] === y1[0] && x1[1] === y1[1] && x1[2] === y1[2] && x1[3] === y1[3]
+ && x2[0] === y2[0] && x2[1] === y2[1] && x2[2] === y2[2] && x2[3] === y2[3];
+}
+BoardArr2d.prototype.equals = BoardArr2d.prototype.equals_unrolled;
+
/* Return and optionally fill 2d board. */
BoardArr2d.prototype.exportTo = function(brd) {
brd = brd || [[],[],[],[]];