Board constructor

Board(
  1. List<List<Stone?>> state, {
  2. Map<Stone, int>? captures,
  3. KoInfo? koInfo,
})

Creates a board from an existing state.

  • All rows must have the same length; otherwise throws ArgumentError.
  • Width and height must be at most alpha.length; otherwise throws ArgumentError.
  • If captures is provided, initializes capture counts.
  • If koInfo is provided, sets current Ko information.

Implementation

Board(this.state, {Map<Stone, int>? captures, KoInfo? koInfo}) {
  final int height = state.length;
  final int width = state[0].length;
  if (height > alpha.length || width > alpha.length) {
    throw ArgumentError(
        'width or height must not be greater than ${alpha.length}');
  }
  for (final row in state) {
    if (row.length != width) {
      throw ArgumentError('All rows must have the same length');
    }
  }

  if (captures != null) {
    _captures[Stone.black] = captures[Stone.black] ?? 0;
    _captures[Stone.white] = captures[Stone.white] ?? 0;
  }

  if (koInfo != null) {
    _koInfo = koInfo;
  }
}