encode method

dynamic encode(
  1. dynamic arrangement
)

Given an arrangement of pieces, returns the starting position's ID.

see {link https://chess960frc.blogspot.com/2010/11/calculate-sp-numbers-in-your-head.html}

param arrangement A starting position's arrangement returns The starting position's ID, or -1 if invalid arrangement

Implementation

dynamic encode(arrangement) {
    if (!FischerRandomValidators().isValidArrangement(arrangement)) return -1;
    String arrngs = '';
    if (arrangement is List<String>) arrngs = arrangement.join('');
    if (arrangement is String) arrngs = arrangement;
    return POSITIONS.indexOf(arrngs);
  }