// Performs full consistency checks, only the first time private GameBoard(int boardSize, FullPlayerSpecPair specs) { BoardSize = boardSize; (Player1, Player2) = specs.Map(x => x.Player); var positions = specs.Map(x => x.Positions.ToList()); #if DEBUG CheckPieces(boardSize, positions); #endif (BallCarrier1, BallCarrier2) = positions.Zip(specs, (l, spec) => l[spec.BallIndex]); (_player1Positions, _player2Positions) = positions.Map(ImmutableHashSet.CreateRange); var lookupBuilder = ImmutableDictionary.CreateBuilder <Position2D, Player>(); specs.Map(spec => spec.Positions.Select(p => new KeyValuePair <Position2D, Player>(p, spec.Player))) .ForEach(lookupBuilder.AddRange); _boardLookup = lookupBuilder.ToImmutable(); }