makeSquareSet function
Takes a string and returns a SquareSet. Useful for debugging/testing purposes.
Example:
final str = '''
. 1 1 1 . . . .
. 1 . 1 . . . .
. 1 . . 1 . . .
. 1 . . . 1 . .
. 1 1 1 1 . . .
. 1 . . . 1 . .
. 1 . . . 1 . .
. 1 . . 1 . . .
'''
final squareSet = makeSquareSet(str);
// SquareSet(0x0E0A12221E222212)
Implementation
SquareSet makeSquareSet(String rep) {
SquareSet ret = SquareSet.empty;
final table = rep
.split('\n')
.where((l) => l.isNotEmpty)
.map((r) => r.split(' '))
.toList()
.reversed
.toList();
for (int y = 7; y >= 0; y--) {
for (int x = 0; x < 8; x++) {
final repSq = table[y][x];
if (repSq == '1') {
ret = ret.withSquare(x + y * 8);
}
}
}
return ret;
}