private static Board CreateFromData(string[] boardLines) { Board board = new Board (); BoardSquare[,] squares = new BoardSquare[boardLines [0].Length, boardLines.Length]; for (int y = 0; y < boardLines.Length; y++) { for (int x = 0; x < boardLines[y].Length; x++) { char incoming = boardLines [y] [x]; if (incoming.Equals ('_')) { squares [x, y] = new BoardSquare (board, BoardSquareType.EDGE, new Coords (){x = x, y = y}); } else if (incoming.Equals ('=')) { squares [x, y] = new BoardSquare (board, BoardSquareType.RAIL, new Coords (){x = x, y = y}); } else if (incoming.Equals ('#')) { squares [x, y] = new BoardSquare (board, BoardSquareType.NORMAL, new Coords (){x = x, y = y}); } else { throw new NotSupportedException ("Board Map includes tile that was not recognised."); } } } board.SetSquares (squares, (square) => { if (square.Pos.x < squares.GetLength (0) / 2) { return Player.P1; } else { return Player.P2; } } ); return board; }
public static void SetupBoardPool(Board template) { if (Pool != null) { return; } Pool = new Pooling.Pool<Board> (AMT_BOARDS_NEEDED_PER_SEARCH * Environment.ProcessorCount, pool => { Board newBoard = new Board (); BoardSquare[,] squares = new BoardSquare[template.Width, template.Height]; for (int y = 0; y < template.Height; y++) { for (int x = 0; x < template.Width; x++) { squares [x, y] = new BoardSquare (newBoard, template.Squares [x, y].Type, new Coords () { x = x, y = y }); } } newBoard.SetSquares (squares, template.TerritoryOf); return newBoard; }, Pooling.LoadingMode.Eager, Pooling.AccessMode.FIFO); }