private int CountAliveNeighborsOf(BoardCellIndex index) { var neighborsTypes = new BoardCellType[] { GetCellType(new BoardCellIndex(index.X - 1, index.Y - 1)), GetCellType(new BoardCellIndex(index.X - 1, index.Y)), GetCellType(new BoardCellIndex(index.X - 1, index.Y + 1)), GetCellType(new BoardCellIndex(index.X, index.Y + 1)), GetCellType(new BoardCellIndex(index.X, index.Y - 1)), GetCellType(new BoardCellIndex(index.X + 1, index.Y - 1)), GetCellType(new BoardCellIndex(index.X + 1, index.Y)), GetCellType(new BoardCellIndex(index.X + 1, index.Y + 1)) }; var aliveCount = 0; foreach (var nType in neighborsTypes) { if (nType == BoardCellType.Alive) { ++aliveCount; } } return(aliveCount); }
private void ChangeCellType(BoardCellIndex index, BoardCellType newCellType) { if (IsValidCellIndex(index)) { var cellIndex1d = ToIndex1D(index); var cell = cells[cellIndex1d]; ChangeCellType(cell, cellIndex1d, newCellType); } }
private Vector2[] GetNewUVs(BoardCellType newCellType, BoardCellIndex cellIndex) { if (IsBorder(cellIndex)) { return(BoardCellUVsFactory.GetTransparentUVs()); } else { return(BoardCellUVsFactory.GetUVsFor(newCellType)); } }
private void SetPointArray(Coordinate[] coordinates, BoardCellType boardCellType) { if (coordinates == null) { return; } foreach (var point in coordinates) { SetBoardPositionType(point, boardCellType); } }
private void ChangeCellType(BoardCell cell, int cellIndex1d, BoardCellType newCellType) { var newUVs = GetNewUVs(newCellType, cell.Index); var firstUvIndex = cellIndex1d * 4; for (var i = 0; i < 4; ++i) { meshUVsBuffer[firstUvIndex + i] = newUVs[i]; } cell.Type = newCellType; }
private bool TryGetWinPositionsOnDirections(BoardCellType value, MapPosition position, MapNavigator direction, MapNavigator oppositeDirection, out IEnumerable <MapPosition> winPositions) { IList <MapPosition> potentialWinPositions = new List <MapPosition>(); potentialWinPositions.Add(position); GetMatchingPositionsOnDirection(value, position, direction, potentialWinPositions); GetMatchingPositionsOnDirection(value, position, oppositeDirection, potentialWinPositions); if (potentialWinPositions.Count >= this.WinSequenceSize) { winPositions = potentialWinPositions; return(true); } winPositions = null; return(false); }
private void GetMatchingPositionsOnDirection(BoardCellType cellType, MapPosition position, MapNavigator directionNavigator, IList <MapPosition> matchingPositions) { MapPosition currentPosition = position; do { currentPosition = directionNavigator.Next(currentPosition); if (!this.GameBoard.IsPositionOnMap(currentPosition)) { break; } if (this.GameBoard[currentPosition].CellType != cellType) { break; } matchingPositions.Add(currentPosition); } while (true); }
private void SetBoardPositionType(Coordinate coordinate, BoardCellType cellType) { grid[coordinate[0], coordinate[1]] = cellType; }
public BoardCellStruct(BoardCellId cellId, BoardCellType cellType) { CellId = cellId; CellType = cellType; Figure = null; }
public BoardCellStruct(BoardCellId cellId, BoardCellType cellType, FigureStructure figure) { CellId = cellId; CellType = cellType; Figure = figure; }
private void ChangeCellType(BoardCell cell, BoardCellType newCellType) { var cellIndex1d = ToIndex1D(cell.Index); ChangeCellType(cell, cellIndex1d, newCellType); }
public bool TryGetWinPositions(BoardCellType cellType, MapPosition position, out IEnumerable <MapPosition> winPositions) => TryGetWinPositionsOnDirections(cellType, position, MapNavigator.N, MapNavigator.S, out winPositions) || TryGetWinPositionsOnDirections(cellType, position, MapNavigator.NE, MapNavigator.SW, out winPositions) || TryGetWinPositionsOnDirections(cellType, position, MapNavigator.E, MapNavigator.W, out winPositions) || TryGetWinPositionsOnDirections(cellType, position, MapNavigator.SE, MapNavigator.NW, out winPositions);
public static Vector2[] GetUVsFor(BoardCellType type) { return(tileTypeToUVs[type]); }