allowMovement method

bool allowMovement(
  1. int piece,
  2. int square
)

For use with restricted movement regions - determines whether it is allowed for piece to move to square.

Implementation

bool allowMovement(int piece, int square) {
  final pd = pieces[piece.type];
  if (regions.isEmpty || pd.type.regionEffects.isEmpty) {
    return true;
  }
  List<RegionEffect> effects = pd.type.restrictMovementRegionEffects;
  if (effects.isEmpty) {
    return true;
  }
  String? regionId = effects.first.regionForPlayer(piece.colour);
  if (regionId == null) return true;

  final region = regions[regionId];
  if (region == null) return true;
  return region.containsSquare(square);
}