public static int[,,] Make(int waterSize, int woodSize, int windSize) { int[,,] initialEnvironment = CreateInitialEnvironment(waterSize, woodSize, windSize); int[,,] firstEarthCrystalEnvironment = (int[, , ])initialEnvironment.Clone(); int[,,] secondEarthCrystalEnvironment = (int[, , ])initialEnvironment.Clone(); int[,,] firstWindCrystalEnvironment = (int[, , ])initialEnvironment.Clone(); int[,,] secondWindCrystalEnvironment = (int[, , ])initialEnvironment.Clone(); Random rand = new Random(); GrowEarthCrystal(firstEarthCrystalEnvironment, waterSize, woodSize, windSize, rand); GrowEarthCrystal(secondEarthCrystalEnvironment, waterSize, woodSize, windSize, rand); GrowWindCrystal(firstWindCrystalEnvironment, waterSize, woodSize, windSize, rand); GrowWindCrystal(secondWindCrystalEnvironment, waterSize, woodSize, windSize, rand); for (int wind = 1; wind < windSize - 1; wind++) { for (int wood = 1; wood < woodSize - 1; wood++) { for (int water = 1; water < waterSize - 1; water++) { initialEnvironment[water, wood, wind] += firstEarthCrystalEnvironment[water, wood, wind]; initialEnvironment[water, wood, wind] += secondEarthCrystalEnvironment[water, wood, wind]; initialEnvironment[water, wood, wind] += firstWindCrystalEnvironment[water, wood, wind]; initialEnvironment[water, wood, wind] += secondWindCrystalEnvironment[water, wood, wind]; } } } return(initialEnvironment); }
public void Reset() { visitedCoordinates = new List <Vector3>(); if (baseCells != null) { visitedCells = baseCells.Clone() as int[, , ]; return; } int cellX = (int)Math.Round(Vector3.Distance(boundsDefiner.point1, new Vector3(boundsDefiner.point2.x, boundsDefiner.point1.y, boundsDefiner.point1.z))); int cellY = (int)Math.Round(Vector3.Distance(boundsDefiner.point1, new Vector3(boundsDefiner.point1.x, boundsDefiner.point2.y, boundsDefiner.point1.z))); int cellZ = (int)Math.Round(Vector3.Distance(boundsDefiner.point1, new Vector3(boundsDefiner.point1.x, boundsDefiner.point1.y, boundsDefiner.point2.z))); cellCount = new Vector3(cellX, cellY, cellZ); visitedCells = new int[cellX, cellY, cellZ]; baseCells = new int[cellX, cellY, cellZ]; Debug.LogError(cellCount); for (int x = 0; x < cellCount.x; x++) { for (int y = 0; y < cellCount.y; y++) { for (int z = 0; z < cellCount.z; z++) { visitedCells[x, y, z] = IsInAnyCollider(meshCol, new Vector3(x, y, z)) ? 0 : 1; } } } baseCells = visitedCells.Clone() as int[, , ]; }
// Clicked on position, so check if it is the same, and (destroy and) build if neccesary void ClickedPosition(int posX, int posY) { // If it's the same, just keep the previous one and do nothing, else (destroy and) build if (level [posX, posY, selectedLayer] != selectedTile) { // Push level on undoStack since it is going to change undoStack.Push(level.Clone() as int[, , ]); // If the position is not empty, destroy the the current element (using gameObjects array) if (level [posX, posY, selectedLayer] != EMPTY) { DestroyImmediate(gameObjects [posX, posY, selectedLayer].gameObject); } // Create the new game object CreateBlock(selectedTile, posX, posY, selectedLayer); } }
public TileData(WorldSettings settings) { Vector2 size = settings.size; int layers = 7; int xSize = (int)size.x; int ySize = (int)size.y; tileTypes = new int[xSize, ySize, layers]; tileTypesToBuild = new int[xSize, ySize, layers]; //We have to default everything to -1 so that when we load it doesn't mistake empty tiles for the first tile in the list. for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { for (int l = 0; l < layers; l++) { tileTypes[x, y, l] = -1; } } } zones = new List <SerializableZone>(); waterToSimulate = new List <SerializableVector3>(); tileTypesToBuild = (int[, , ])tileTypes.Clone(); tileRotation = (int[, , ])tileTypes.Clone(); tileTypes = (int[, , ])tileTypes.Clone(); pathfindingCosts = new float[xSize, ySize]; pathfindingRatios = new float[xSize, ySize]; waterLevels = new float[xSize, ySize]; wallHealth = new int[xSize, ySize]; tasks = new List <SerializableTask>(); objects = new List <Data>(); }
public int[,,] meanRGB(int[,,] data) { int[,,] result = (int[, , ])data.Clone(); // Step 2: 設定像點資料 for (int y = 0; y < data.GetLength(1); y++) { for (int x = 0; x < data.GetLength(2); x++) { int gray = (data[0, y, x] + data[1, y, x] + data[2, y, x]) / 3; result[0, y, x] = gray; result[1, y, x] = gray; result[2, y, x] = gray; } } // Step 3: 更新顯示影像 return(result); }
/// <summary> /// 最終決定要保留原色還是變成白色 /// </summary> /// <returns>The sobel.</returns> /// <param name="data">Data.</param> /// <param name="door">Door.</param> /// <param name="G">G.</param> public int[,,] Sobel(int[,,] data, int door, int[,,] G) { int[,,] result = (int[, , ])data.Clone(); for (int ch = 0; ch < data.GetLength(0); ch++) { for (int i = 1; i < data.GetLength(1) - 1; i++) { for (int j = 1; j < data.GetLength(2) - 1; j++) { if (G[ch, i - 1, j - 1] >= door) { result[ch, i, j] = 255; } } } } return(result); }
/// <summary> /// Combine GX和GY /// </summary> /// <returns>The sobel.</returns> /// <param name="data">Data.</param> /// <param name="door">Door.</param> /// <param name="GX">Gx.</param> /// <param name="GY">Gy.</param> public int[,,] Sobel(int[,,] data, int door, int[,,] GX, int[,,] GY) { int[,,] result = (int[, , ])data.Clone(); for (int ch = 0; ch < data.GetLength(0); ch++) { for (int i = 1; i < data.GetLength(1) - 1; i++) { for (int j = 1; j < data.GetLength(2) - 1; j++) { double G = Math.Pow(Math.Pow(GX[ch, i - 1, j - 1], 2) + Math.Pow(GY[ch, i - 1, j - 1], 2), 0.5); if (G >= door) { result[ch, i, j] = 255; } } } } return(result); }
public void UpdateEnergyHorizontalSeam(int width, int height, int[, ,] pixels, int[] seam) { Width = width; Height = height; Pixels = (int[, , ])pixels.Clone(); for (var i = 0; i < Width; i++) { for (var j = Math.Max(0, seam[i] - 3); j < seam[i] + 3 && j < Height; j++) { Energy[i, j] = GetPixelEnergy(i, j); } } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { AvgEnergy += Energy[x, y]; } } AvgEnergy /= Width * Height; }
// Used to smooth the randomly generated map by updating the map depending on the walls around private void SmoothMap() { int surroundingWallCount; _smoothedMap = (int[, , ])_map.Clone(); for (int i = 0; i < _width; i++) { for (int j = 0; j < _height; j++) { for (int k = 0; k < _depth; k++) { surroundingWallCount = GetSurroundingWallCount(i, j, k); if (surroundingWallCount > _smoothLimit) { _smoothedMap[i, j, k] = 1; } else if (surroundingWallCount < _smoothLimit) { _smoothedMap[i, j, k] = 0; } } } } }
public void ComputeEnergy(int width, int height, int[, ,] pixels) { Width = width; Height = height; Pixels = (int[, , ])pixels.Clone(); Energy = new int[width, height]; Parallel.For(0, width, x => { for (int y = 0; y < height; ++y) { Energy[x, y] = GetPixelEnergy(x, y); } }); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { AvgEnergy += Energy[x, y]; } } AvgEnergy /= Width * Height; }
//Makes a shadow move in a fictive world public int[,,] GetNewBoardStateShadow(int[,,] oldBoardState, int player, int pawn, int move) { int[,,] boardState = oldBoardState.Clone() as int[, , ]; //find pawn for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { if (boardState[x, y, 1] == player && boardState[x, y, 2] == pawn) { // LastMoves[player, pawn].XLast = x; // LastMoves[player, pawn].YLast = y; // Slet dens tidligere position boardState[x, y, 1] = 0; boardState[x, y, 2] = 0; //Debug.Log("Player"+player+","+x+","+y); switch (move) { case 0: if (x > 0) { boardState[x - 1, y, 1] = player; boardState[x - 1, y, 2] = pawn; Kill(ref boardState, x - 1, y); } return(boardState); case 1: if (y < 4) { boardState[x, y + 1, 1] = player; boardState[x, y + 1, 2] = pawn; Kill(ref boardState, x, y + 1); } return(boardState); case 2: if (x < 4) { boardState[x + 1, y, 1] = player; boardState[x + 1, y, 2] = pawn; Kill(ref boardState, x + 1, y); } return(boardState); case 3: if (y > 0) { boardState[x, y - 1, 1] = player; boardState[x, y - 1, 2] = pawn; Kill(ref boardState, x, y - 1); } return(boardState); } } } } // Debug.Log("Either illegal move or could not find on board"); // lægger brik på bræt; if (player == 1) { if (boardState[2, 0, 1] == 2) { //give point and extra move } boardState[2, 0, 1] = 1; boardState[2, 0, 2] = pawn; } if (player == 2) { if (boardState[2, 4, 1] == 1) { //give point and extra move } boardState[2, 4, 1] = 2; boardState[2, 4, 2] = pawn; } return(boardState); }
private void _MouseDown(object sender, MouseEventArgs e) { // sel due to state _pressdown = true; if (_status != 0 && e.Button == MouseButtons.Right) { _status = 0; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button5.Enabled = true; button6.Enabled = true; button7.Enabled = true; trackBar5.Enabled = true; trackBar6.Enabled = true; pictureBox2.Image = _imgDes; pictureBox2.Update(); _cosStatus = 0; } if ((_status == 1 || _status == 2) && _cosStatus == 0) { _g.FillEllipse(new SolidBrush(Color.Black), e.X - 10, e.Y - 10, 20, 20); _centerX = e.X * _imgOri.Width / pictureBox2.Width; _centerY = e.Y * _imgOri.Height / pictureBox2.Height; _cosStatus = 1; } else if (_status == 1 && _cosStatus == 1) { rotation(); _status = 0; _cosStatus = 0; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button5.Enabled = true; button6.Enabled = true; button7.Enabled = true; progressBar1.Value = 100; groupBox6.Text = "Ready"; groupBox6.Update(); progressBar1.Update(); } else if (_status == 2 && _cosStatus == 1) { wave(); _status = 0; _cosStatus = 0; button1.Enabled = true; button2.Enabled = true; button3.Enabled = true; button4.Enabled = true; button5.Enabled = true; button6.Enabled = true; button7.Enabled = true; progressBar1.Value = 100; groupBox6.Text = "Ready"; groupBox6.Update(); progressBar1.Update(); } else if (_status == 3) { int lx = _imgOri.Width; int ax = lx / 2; int ly = _imgOri.Height; int ay = ly / 2; int bx = trackBar6.Value; int by = trackBar5.Value; if (trackBar5.Enabled) { trackBar5.Enabled = false; trackBar6.Enabled = false; _point = new int[ax / bx + (lx - ax) / bx + 3, ay / by + (ly - ay) / by + 3, 2]; int xdl = ax - (ax / bx + 1) * bx; for (int i = 0; i < ax / bx + (lx - ax) / bx + 3; ++i) { int ydl = ay - (ay / by + 1) * by; for (int j = 0; j < ay / by + (ly - ay) / by + 3; ++j) { _point[i, j, 0] = xdl; _point[i, j, 1] = ydl; ydl += by; } xdl += bx; } _basepoint = (int[, , ])_point.Clone(); } int ttyx = e.X * _imgOri.Width / pictureBox2.Width; int ttyy = e.Y * _imgOri.Height / pictureBox2.Height; int min = Int32.MaxValue; for (int i = 0; i < ax / bx + (lx - ax) / bx + 3; ++i) { for (int j = 0; j < ay / by + (ly - ay) / by + 3; ++j) { if ((ttyx - _point[i, j, 0]) * (ttyx - _point[i, j, 0]) + (ttyy - _point[i, j, 1]) * (ttyy - _point[i, j, 1]) < min) { min = (ttyx - _point[i, j, 0]) * (ttyx - _point[i, j, 0]) + (ttyy - _point[i, j, 1]) * (ttyy - _point[i, j, 1]); _selectedX = i; _selectedY = j; } } } _g.FillEllipse(new SolidBrush(Color.Red), _point[_selectedX, _selectedY, 0] * pictureBox2.Width / _imgOri.Width - 5, _point[_selectedX, _selectedY, 1] * pictureBox2.Height / _imgOri.Height - 5, 10, 10); Point dl = Cursor.Position; Cursor.Position = new Point( _point[_selectedX, _selectedY, 0] * pictureBox2.Width / _imgOri.Width - e.X + dl.X, _point[_selectedX, _selectedY, 1] * pictureBox2.Height / _imgOri.Height - e.Y + dl.Y ); progressBar1.Value = 100; groupBox6.Text = "Ready"; groupBox6.Update(); progressBar1.Update(); _basepoint = (int[, , ])_point.Clone(); } }
// Push a level to the undo stack thereby saving it's state public void PushLevel(int[,,] level) { _undoStack.Push(level.Clone() as int[, , ]); }
public int[,,] cloneGame() { // Need to find a way to de-alias it return((int[, , ])gameMatrix.Clone()); }
private void menuRestore_Click(object sender, EventArgs e) { lands = (int[, , ])originalLands.Clone(); pbLand.Refresh(); }
public static int[,,] Clone3D(int[,,] a) { return(a.Clone() as int[, , ]); }
public void RecordSudokuLog() { cellManager.HighlightCells(0); Tuple <int[, ], int[, , ]> tuple = new Tuple <int[, ], int[, , ]>((int[, ])sudoku.Clone(), (int[, , ])memoSudoku.Clone()); lateSudoku.Add(tuple); undoIndex++; }
public void SetMemoSudoku(int[,,] ms) { this.memoSudoku = (int[, , ])ms.Clone(); }
public int[,,] GetNewBoardStateShadow(int[,,] oldBoardState, int player, int pawn, int move, int points, out int newPoints) { newPoints = points; int[,,] boardState = oldBoardState.Clone() as int[, , ]; //find pawn for (int x = 0; x < 5; x++) { string s = "| "; for (int y = 4; y >= 0; y--) { s += " " + oldBoardState[x, y, 2]; } //Debug.Log(s); } for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { if (boardState[x, y, 1] == player && boardState[x, y, 2] == pawn) { // LastMoves[player, pawn].XLast = x; // LastMoves[player, pawn].YLast = y; // Slet dens tidligere position boardState[x, y, 1] = 0; boardState[x, y, 2] = 0; //Debug.Log("Player"+player+","+x+","+y); switch (move) { case 0: if (x > 0) { boardState[x - 1, y, 1] = player; boardState[x - 1, y, 2] = pawn; Kill(ref boardState, x - 1, y); } return(boardState); case 1: if (y < 4) { boardState[x, y + 1, 1] = player; boardState[x, y + 1, 2] = pawn; Kill(ref boardState, x, y + 1); } return(boardState); case 2: if (x < 4) { boardState[x + 1, y, 1] = player; boardState[x + 1, y, 2] = pawn; Kill(ref boardState, x + 1, y); } return(boardState); case 3: if (y > 0) { boardState[x, y - 1, 1] = player; boardState[x, y - 1, 2] = pawn; Kill(ref boardState, x, y - 1); } return(boardState); } } } } // lægger brik på bræt; if (player == 1) { if (boardState[2, 0, 1] == 2) { newPoints += 1; } boardState[2, 0, 1] = 1; boardState[2, 0, 2] = pawn; } if (player == 2) { if (boardState[2, 4, 1] == 1) { newPoints += 1; } boardState[2, 4, 1] = 2; boardState[2, 4, 2] = pawn; } return(boardState); }
public void fromMatrix(int[,,] cubein) { this.cube = (int[, , ])cubein.Clone(); }