Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getMaterialDiff(pieces) {
var diff = {
white: { king: 0, queen: 0, rook: 0, bishop: 0, knight: 0, pawn: 0 },
black: { king: 0, queen: 0, rook: 0, bishop: 0, knight: 0, pawn: 0 },
};
for (let k in pieces) {
const p = pieces[k], them = diff[opposite(p.color)];
if (them[p.role] > 0) them[p.role]--;
else diff[p.color][p.role]++;
}
return diff;
}