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 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 file = match!.group(1)!;
String rank = match.group(2)!;
int _file = file.codeUnits[0] - ASCII_a;
int _rank = v - int.parse(rank);
int square = _rank * h + _file;
return square;
}