parseSquare function
Parses a string like 'a1', 'a2', etc. and returns a Square or null
if the square
doesn't exist.
Implementation
Square? parseSquare(String str) {
if (str.length != 2) return null;
final file = str.codeUnitAt(0) - 'a'.codeUnitAt(0);
final rank = str.codeUnitAt(1) - '1'.codeUnitAt(0);
if (file < 0 || file >= 8 || rank < 0 || rank >= 8) return null;
return file + 8 * rank;
}