- for (let row = 0; row < 8; ++row) {
- for (let col = 0; col < 8; ++col) {
- let col_text = String.fromCharCode('a1'.charCodeAt(0) + col);
- let row_text = String.fromCharCode('a1'.charCodeAt(1) + row);
- let square = col_text + row_text;
- let contents = hiddenboard.get(square);
- if (contents !== null) {
- if (contents.color === 'w') {
- ++imbalance[contents.type];
- } else {
- --imbalance[contents.type];
- }
- }
+ for (const c of fen) {
+ if (c === ' ') {
+ // End of board
+ break;
+ }
+ if (c != c.toUpperCase()) {
+ --imbalance[c];
+ } else if (c != c.toLowerCase()) {
+ ++imbalance[c.toLowerCase()];