Vector3 pointPos; //position to place each prefab along the given circle/eliptoid #endregion Fields #region Constructors public BoardCircle() { Matrix = new CellState[SIZE_X, SIZE_Y]; for (int x = 0; x < SIZE_X; x++) { for (int y = 0; y < SIZE_Y; y++) { //multiply 'i' by '1.0f' to ensure the result is a fraction float pointNum = (x*1.0f)/SIZE_X; //angle along the unit circle for placing points float angle = pointNum*Mathf.PI*2; float X = Mathf.Sin (angle)*radiusX; // for radial placement and simple height float Y = Mathf.Cos (angle)*radiusY; // for radial placement and simple height //float X = Mathf.Sin (angle)*(radiusX + radiusOffset* y); // for placement in a ring like fasion on the ground //float Y = Mathf.Cos (angle)*(radiusY + radiusOffset* y); // for placement in a ring like fasion on the ground //position for the point prefab if(vertical) pointPos = new Vector3(X, Y)+centerPos; else if (!vertical){ pointPos = new Vector3(X, y*SCALE- (SIZE_Y / 2)*SCALE, Y)+centerPos; // for centered pivot of the entire group pointPos = new Vector3(X, y*SCALE, Y)+centerPos; // for placement from bottom to top //pointPos = new Vector3(X, centerPos.y, Y)+centerPos; // for placement in a ring like fasion on the ground } //var position = new Vector3(x - (SIZE_X / 2), y - (SIZE_Y / 2), 0); //var position = new Vector3(x*SCALE- (SIZE_X / 2)*SCALE,y*SCALE- (SIZE_Y / 2)*SCALE,0); var position = pointPos; Matrix[x, y] = CellFactory.Create(position, Random.Range(1, 3) == 1); } } }
public CellularAutomaton(int width, int height, Ruleset ruleset, float startNoise, bool aliveBorders) { this.width = width; this.height = height; this.ruleset = ruleset; this.aliveBorders = aliveBorders; cells = new CellState[width, height]; copy = new CellState[width, height]; visitAliveBorders = (int neighbourX, int neighbourY) => { if (copy.IsInBounds(neighbourX, neighbourY)) { if (copy[neighbourX, neighbourY] == CellState.Alive) { aliveNeighbours++; } } else { aliveNeighbours++; } }; visitDeadBorders = (int neighbourX, int neighbourY) => { if (copy[neighbourX, neighbourY] == CellState.Alive) { aliveNeighbours++; } }; FillWithNoise(startNoise); }
public LifeGrid(int height, int width) { gridHeight = height; gridWidth = width; CurrentState = new CellState[gridHeight, gridWidth]; nextState = new CellState[gridHeight, gridWidth]; }
public GameOfLife(CellState[,] current) { _current = current; GridSize = new GridSize() { X = current.GetLength(0), Y = current.GetLength(1) }; }
public void InitWithSchem(string wirename) { state = InitializeWires(height, width); allowCursorDraw = true; sources = new List <source>(); loadSchematicsFromASCII(wirename); }
private LifeGrid(int columns, int rows, CellState[,] initalGrid) { Grid = initalGrid; SeedStateGrid = initalGrid; Columns = columns; Rows = rows; Generation = 0; }
public PuzzleGame() { _board = new CellState[5, 5]; for (int i = 0; i <= 4; i += 2) { _board[i, 1] = _board[i, 3] = Forbidden; } }
IEnumerator GetBestAction(CellState[,] state, CellState aiPlayer, Action action) { Score score = new Score(); yield return(StartCoroutine(RecursiveMinMaxing(state, aiPlayer, action, score))); Debug.Log("YOU SHOULD PLAY: " + action.ToString()); }
private bool CheckIsDead(CellState[,] field, int x, int y) { var q = new Queue <PT>(); var mask = new bool[10, 10]; q.Enqueue(new PT() { X = x, Y = y }); while (q.Count > 0) { var pt = q.Dequeue(); if (pt.X >= 0 && pt.Y >= 0 && pt.X < 10 && pt.Y < 10) { if (!mask[pt.X, pt.Y]) { mask[pt.X, pt.Y] = true; switch (field[pt.X, pt.Y]) { case CellState.Alive: return(false); case CellState.Free: case CellState.FreeFired: continue; case CellState.Dead: { q.Enqueue(new PT() { X = pt.X - 1, Y = pt.Y }); q.Enqueue(new PT() { X = pt.X + 1, Y = pt.Y }); q.Enqueue(new PT() { X = pt.X, Y = pt.Y - 1 }); q.Enqueue(new PT() { X = pt.X, Y = pt.Y + 1 }); } break; default: throw new NotImplementedException(""); } } } } return(true); }
private static void CheckAndAddBottomRadial(CellState[,] grid, List <Point> radialPoints, int x, int y) { if (y < grid.GetLength(1) - 1) { radialPoints.Add(new Point { X = x, Y = y + 1 }); } }
public Universe(ushort dimension) { Dimension = dimension; CurrentState = new CellState[Width, Height]; NextState = new CellState[Width, Height]; Age = 0; Population = 0; Vary = 0; }
public FillWords(IDrawer drawer, int fieldWidth, int fieldHeight) { _drawer = drawer; _fieldWidth = fieldWidth; _fieldHeight = fieldHeight; _field = new Field(fieldWidth, fieldHeight); _cellStates = new CellState[_field.GetFieldWidth(), _field.GetFieldHeight()]; }
public static void Initialize(int width = 100, int height = 100) { w = width; h = height; grid = new CellState[h, w]; gridCopy = new CellState[h, w]; initialState = new CellState[h, w]; temps = new int[h, w]; CurrentType = AutomatonType.Conway; }
public GameField(GameController controller) { _controller = controller; RowCount = 15; ColCount = 25; _field = new CellColor[RowCount, ColCount]; _stateField = new CellState[RowCount, ColCount]; }
public static CellState[,] SaveCellState(CellState[,] gameState, string filename = FileName) { using (var writer = System.IO.File.CreateText(FileName)) { var jsonString = JsonSerializer.Serialize(gameState); writer.Write(jsonString); return(gameState); } }
public Form1() { InitializeComponent(); ClientSize = new Size(nRows * cellSize, nColumns * cellSize); FormBorderStyle = FormBorderStyle.FixedSingle; KeyUp += KeyCallback; cellStates = new CellState[nRows, nColumns]; grid = new TableLayoutPanel(); grid.RowCount = nRows; grid.ColumnCount = nColumns; grid.BackColor = Color.Black; grid.Size = Size; Controls.Add(grid); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nColumns; ++j) { cellStates[i, j] = CellState.BACKGROUND; Button button = new Button(); button.BackColor = Color.White; button.KeyDown += KeyCallback; button.Text = (i * nColumns + j).ToString(); button.Width = cellSize; button.Height = cellSize; button.Margin = Padding.Empty; button.Padding = Padding.Empty; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 1; button.MouseDown += ButtonClick; button.Tag = i * nColumns + j; TableLayoutPanelCellPosition cellPos = new TableLayoutPanelCellPosition(j, i); grid.SetCellPosition(button, cellPos); grid.Controls.Add(button); } } int nCells = nRows * nColumns; for (int i = 0; i < nCells; ++i) { Q[i] = new double[nCells]; } }
private void AssertCellMatch(CellState[,] cells) { for (int i = 0; i < cells.GetLength(0); i++) { for (int j = 0; j < cells.GetLength(1); j++) { var expectedCell = cells[i, j]; AssertExpectedCell(expectedCell); } } }
public void CreateDirMatrix() { dirMatrix = new CellState[width * 2 + 1, height * 2 + 1]; for (var x = 0; x < width * 2 + 1; x++) { for (var y = 0; y < height * 2 + 1; y++) { dirMatrix[x, y] = this[x, y]; } } }
private void ChangeButton(CellState[,] map) { if (playerType == PlayerType.Human) { FillMe(map); } else { MakeMasked(map); } }
public static int CountEnemies(this CellState[,] currentBoard, Team team) { var stats = currentBoard.GetBoardStats(); if (team == Team.Black) { return(stats.WhiteKings + stats.WhitePieces); } return(stats.BlackPieces + stats.BlackKings); }
public CellularAutomaton(int width, int height, Ruleset ruleset, float startNoise, bool aliveBorders) { this.width = width; this.height = height; this.ruleset = ruleset; this.aliveBorders = aliveBorders; cells = new CellState[width, height]; copy = new CellState[width, height]; FillWithNoise(startNoise); }
public static CellState[,] LoadCellState(string fileName = FileName) { if (System.IO.File.Exists(fileName)) { var jsonString = System.IO.File.ReadAllText(fileName); CellState[,] res = JsonSerializer.Deserialize <CellState[, ]>(jsonString); return(res); } return(new CellState[, ]); }
private void CopyArray(CellState[,] sourceArray, CellState[,] destinationArray) { for (int x = 0; x < FieldWidth; x++) { for (int y = 0; y < FieldHeight; y++) { destinationArray[x, y] = new CellState(sourceArray[x, y].BallColor, cellSize, sourceArray[x, y].HasBall); } } }
public Battleships() { Player_1 = "Player_1"; Player_2 = "Player_2"; BoardSize = 1; Touch = 0; personalBoard1 = new ShipCell[BoardSize, BoardSize]; battleBoard1 = new CellState[BoardSize, BoardSize]; personalBoard2 = new ShipCell[BoardSize, BoardSize]; battleBoard2 = new CellState[BoardSize, BoardSize]; }
void Start() { arrayOfBlocks = new CellState[_gridWidth, _gridHeight]; for (int i = 0; i < _gridWidth; i++) { for (int j = 0; j < _gridHeight; j++) { arrayOfBlocks[i, j] = CellState.None; } } }
public Board() { Matrix = new CellState[SIZE, SIZE]; for (int x = 0; x < SIZE; x++) { for (int y = 0; y < SIZE; y++) { //var position = new Vector3(x - (SIZE / 2), y - (SIZE / 2), 0); var position = new Vector3(x*SCALE - (SIZE / 2)*SCALE,y*SCALE- (SIZE / 2)*SCALE,0); Matrix[x, y] = CellFactory.Create(position, Random.Range(1, 3) == 1); } } }
public Game(GameSettings settings) { field = new CellState[settings.Rows, settings.Columns]; previousField = new CellState[settings.Rows, settings.Columns]; aliveNeighbours = new int[settings.Rows, settings.Columns]; Rows = settings.Rows; Columns = settings.Columns; this.Reset(CellState.Dead); this.stayAliveCount = settings.StayAliveCount; this.birthCount = settings.BirthCount; this.isInfinite = settings.IsInfinite; }
public void Render(CellState[,] grid, ControlCommand currentComand) { const string header = "CONWAYS GAME OF LIFE"; var status = currentComand.ToString(); const string footer = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; Console.Clear(); Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (header.Length / 2)) + "}", header)); Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (status.Length / 2)) + "}", status)); Console.WriteLine(GridAsString(grid)); Console.WriteLine(String.Format("{0," + ((Console.WindowWidth / 2) + (footer.Length / 2)) + "}", footer)); }
/// <summary> /// it should be wrapped in try/catch /// </summary> public Cross(TextReader t) { // header Name = t.ReadLine()?.Trim(); if (string.IsNullOrWhiteSpace(Name)) throw new FormatException("First line have to contains name"); var s = t.ReadLine(); if (string.IsNullOrWhiteSpace(s)) throw new FormatException("Second line must contain 2 spase-separated value: width and height"); var ss = s.Split((char[]) null, StringSplitOptions.RemoveEmptyEntries); if (ss.Length != 2) throw new FormatException("Second line must contain 2 spase-separated value: width and height"); int width = int.Parse(ss[0]); int height = int.Parse(ss[1]); Top = new Line[width]; Left = new Line[height]; map = new CellState[width, height]; // top block if (!string.IsNullOrWhiteSpace(t.ReadLine())) throw new FormatException("Line 3 is not empty"); for (int i = 0; i < width; i++) { Top[i] = ImportLine(t); } // left block if (!string.IsNullOrWhiteSpace(t.ReadLine())) throw new FormatException($"Line {width + 4} is not empty"); for (int i = 0; i < height; i++) { Left[i] = ImportLine(t); } // map (if exists) var mapFlag = t.ReadLine(); if (mapFlag == null) return; if (!string.IsNullOrWhiteSpace(mapFlag)) throw new FormatException($"Line {width + height + 5} is not empty"); for (int i = 0; i < height; i++) { var mapLine = t.ReadLine(); if (string.IsNullOrWhiteSpace(mapLine) || mapLine.Length != width) throw new FormatException($"Line {width + height + 6 + i} must contains map line"); for (int j = 0; j < width; j++) { if (!"012".Contains(mapLine[j])) throw new FormatException($"Line {width + height + 6 + i} map containing wrong symbol"); map[j, i] = (CellState) (byte) (mapLine[j] - '0'); } } }
public void DrawScreen(CellState[,] gameState, int height, int width) { StringBuilder borders = new StringBuilder("", height * width); //builds the 2d array takes in the method creating the bounds and the floor and the ceiling and the platform. char character = Convert.ToChar(32); for (int y = 0; y < 62; y++) { character = NewMethod(gameState, height, width, borders, character, y); } Console.SetCursorPosition(0, 0); Console.Write(borders); }
protected virtual void UpdateCellsCollection(CellState[,] cellStates) { for (int x = 0; x < GameSettings.CELL_COUNT_X; x++) { for (int y = 0; y < GameSettings.CELL_COUNT_Y; y++) { var index = GameSettings.CELL_COUNT_X * x + y; Cells[index].State = cellStates[x, y]; } } }
public void UpdateState() { for (int i = 0; i < this.gridHeight; i++) { for (int j = 0; j < this.gridWidth; j++) { var liveNeighbors = GetLiveNeighbors(i, j); nextState[i, j] = LifeRules.GetNewState(currentState[i, j], liveNeighbors); } } currentState = nextState; nextState = new CellState[this.gridHeight, this.gridWidth]; }
void Step() { state = new CellState[height, width]; int PlayerX = player.getX(); int PlayerY = player.getY(); state[PlayerY, PlayerX] = CellState.Impaler; int Player2X = player2.getX(); int Player2Y = player2.getY(); state[Player2Y, Player2X] = CellState.Enemy; CheckCollision(); }
private static CellState[,] CloneMatrix(CellState[,] oldMatrix) { CellState[, ]? newMatrix = new CellState[oldMatrix.GetLength(0), oldMatrix.GetLength(1)]; for (int y = 0; y < oldMatrix.GetLength(1); y++) { for (int x = 0; x < oldMatrix.GetLength(0); x++) { newMatrix[x, y] = oldMatrix[x, y]; } } return(newMatrix); }
public Cross(int width, int height) { Name = $@"{width} x {height}"; Top = new Line[width]; Left = new Line[height]; for (int i = 0; i < width; i++) Top[i] = new Line(); for (int i = 0; i < height; i++) Left[i] = new Line(); map = new CellState[width, height]; for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) map[i, j] = CellState.Dot; }
public Board2(CellState[,] cells) { _cells = cells; }
// Used to reset the pathfinding when the level is regenerated public static void ResetPathfinding() { gridWidth = LevelGen.CellGrid.Width; gridHeight = LevelGen.CellGrid.Height; // Allocate grids cellStates = new CellState[gridWidth, gridHeight]; pathFindingGrid = new GridCell[gridWidth, gridHeight]; // Initialise state grid for (int x = 0; x < gridWidth; ++x) for (int y = 0; y < gridHeight; ++y) { cellStates[x, y] = CellState.UNKNOWN; } // Initialise pathfinding grid for (int x = 0; x < gridWidth; ++x) for (int y = 0; y < gridHeight; ++y) { pathFindingGrid[x, y] = new GridCell(x, y, false); } cellGrid = new CellGrid(pathFindingGrid, LevelGen.Instance.transform, LevelGen.MAZE_RESOLUTION); currentTargets.Clear(); }
public Sim(SimConfig config, Rules rules) { Cells = new CellState[config.Width, config.Height]; CellsLastChange = new int[config.Width, config.Height]; Rules = rules; Agents = new List<Agent>(); for (var agentX = 1; agentX < config.Width; agentX += 2) { for (var agentY = 1; agentY < config.Height; agentY += 2) { var agent = new Agent { Sim = this, Location = new Point(agentX, agentY), Goal = rules.Goal, CellVisitOrder = rules.CellVisitOrder, }; Agents.Add(agent); Cells[agentX, agentY] = CellState.Agent; } } }
public void Clear() { this.stones = new CellState[size, size]; }
public static void Initialize(int width = 100, int height = 100) { w = width; h = height; grid = new CellState[h, w]; gridCopy = new CellState[h, w]; initialState = new CellState[h, w]; temps = new int[h, w]; CurrentType = AutomatonType.Conway; }
public Board2(int width, int height) { _cells = new CellState[width, height]; InitializeBoard(); }
public BoardModel(int sz) { d_size = sz; d_board = new CellState[sz, sz]; BoardModelUtil.ClearBoard( this ); }
void reallocate() { m_aCells = new CellState[m_ncx, m_ncy]; for (uint i=0; i<m_ncx; i++) for (uint j=0; j<m_ncy; j++) m_aCells[i, j] = CellState.eFree; }