@real_one_chess_king/game-logic
Version:
R.O.C.K. chess game logic
66 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isActionsEql = exports.isAffectsEql = exports.isAffectEql = void 0;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const deepEqual = (obj1, obj2) => {
if (obj1 === obj2)
return true;
if (typeof obj1 !== "object" ||
typeof obj2 !== "object" ||
obj1 === null ||
obj2 === null) {
return false;
}
if (Array.isArray(obj1) !== Array.isArray(obj2))
return false;
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length)
return false;
for (const key of keys1) {
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
return false;
}
}
return true;
};
const isAffectEql = (expected, received) => {
return deepEqual(expected, received);
};
exports.isAffectEql = isAffectEql;
const isAffectsEql = (expected, received) => {
if (!expected && !received)
return true;
if (!expected || !received)
return false;
if (expected.length !== received.length) {
console.log("Mismatch in Affect array length:", { expected, received });
return false;
}
return expected.every((expectedAffect, index) => {
return (0, exports.isAffectEql)(expectedAffect, received[index]);
});
};
exports.isAffectsEql = isAffectsEql;
const isActionsEql = (expected, received) => {
if (!expected && !received)
return true;
if (!expected || !received)
return false;
if (expected.length !== received.length) {
console.log("Mismatch in Action array length:", { expected, received });
return false;
}
const unmatchedReceived = [...received];
return expected.every((expectedAction) => {
const index = unmatchedReceived.findIndex((receivedAction) => deepEqual(expectedAction, receivedAction));
if (index === -1) {
console.log("No matching Action found for:", { expectedAction });
return false;
}
unmatchedReceived.splice(index, 1);
return true;
});
};
exports.isActionsEql = isActionsEql;
//# sourceMappingURL=matchers.js.map