squareNumber method
Converts a human-readable square name into an integer, corresponding to the correct square on a board of this size.
Implementation
int squareNumber(String name) {
name = name.toLowerCase();
if (name == 'hand') return Squares.hand;
RegExp rx = RegExp(r'([A-Za-z])([0-9]+)');
RegExpMatch? match = rx.firstMatch(name);
assert(match != null, 'Invalid square name: $name');
assert(match!.groupCount == 2, 'Invalid square name: $name');
String fileStr = match!.group(1)!;
String rankStr = match.group(2)!;
int file = fileStr.codeUnits[0] - asciiALower;
int rank = v - int.parse(rankStr);
int square = rank * h + file;
return square;
}