/// <summary> /// Generates a chunk that has no special land features /// </summary> /// <param name="x"></param> /// <param name="z"></param> /// <param name="cb"></param> /// <returns></returns> private ChunkData GenerateSimpleChunk(int x, int z, ChunkBase2 cb) { if (cb.Biome == ChunkBiome.ocean) { return(new ChunkData(x, z, (int[, ])OCEAN.Clone(), false)); }/* * if(cb.Biome == ChunkBiome.dessert) * { * return new ChunkData(x, z, (int[,])EMPTY_DESERT.Clone(), cb.IsLand, 1, (float[,])OCEAN_HEIGHT.Clone()); * }if(cb.Biome == ChunkBiome.mountain) * { * return new ChunkData(x, z, (int[,])MOUNTAIN.Clone(), cb.IsLand, 1, (float[,])OCEAN_HEIGHT.Clone()); * * }*/ int[,] tiles = (int[, ])(cb.Biome == ChunkBiome.dessert ? EMPTY_DESERT.Clone() : cb.Biome == ChunkBiome.mountain ? MOUNTAIN.Clone() : EMPTY_PLAINS.Clone()); GenerationRandom genRan = new GenerationRandom(Seed + x << 16 + z); //if(genRan.Random() > 0.1f) // return new ChunkData(x, z, tiles, cb.IsLand); Dictionary <int, WorldObjectData> obs = new Dictionary <int, WorldObjectData>(256); float[,] heights = new float[World.ChunkSize, World.ChunkSize]; for (int i = 0; i < World.ChunkSize; i++) { for (int j = 0; j < World.ChunkSize; j++) { if (genRan.Random() < 0.01f) { //obs.Add(WorldObject.ObjectPositionHash(i,j), new Tree(new Vec2i(x * World.ChunkSize + i, z * World.ChunkSize + j))); } else if (genRan.Random() < 0.3f) { //obs.Add(WorldObject.ObjectPositionHash(i, j), new Tree(new Vec2i(x * World.ChunkSize + i, z * World.ChunkSize + j))); } heights[i, j] = GameGen.TerGen.GetWorldHeightAt(x * World.ChunkSize + i, z * World.ChunkSize + j); } } ChunkData cd = new ChunkData(x, z, tiles, true, cb.Height, heightMap: heights); return(cd); }
public bool BreadthFirst() { for (int z = 0; z < mazeGenerator.iterationsPerCall; z++) { int num = 0; int[,] newMap = (int[, ])mazeMap.Clone(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (mazeMap[i, j] == 2) { num++; newMap[i, j] = 3; drawSquare(i, j, 3); if (i + 1 < height && mazeMap[i + 1, j] == 0) { newMap[i + 1, j] = 2; drawSquare(i + 1, j, 2); } if (i - 1 > -1 && mazeMap[i - 1, j] == 0) { newMap[i - 1, j] = 2; drawSquare(i - 1, j, 2); } if (j + 1 < height && mazeMap[i, j + 1] == 0) { newMap[i, j + 1] = 2; drawSquare(i, j + 1, 2); } if (j - 1 > -1 && mazeMap[i, j - 1] == 0) { newMap[i, j - 1] = 2; drawSquare(i, j - 1, 2); } } } } if (num == 0) { Console.WriteLine("The maze doesnt have a solution."); return(false); } mazeMap = newMap; } return(true); }
/// <summary> /// A method to check which of the two options (Token or Ticket) has been selected. Will be called every time the option is toggled.<br/> /// Because there are only two options (and therefore only two radioboxes) a second <i>CheckedChanged</i> method on the tickets radiobox is redundant. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <summary> /// A method to determine the "optimal" purchasing strategy for the user with <b>myTokens</b> tokens to reach <b>target</b> number of tokens or exchange tickets.<br/> /// Note that EN has a weird dip in package effectiveness with the 2000 gem package, set at 76.92 gems per dollar compared to the 8000, 4000, and 800 dollar packages that give a rate of 80 gems per dollar.<br/> /// I do not believe this should be significant enough to incur major losses, but this is nonetheless a possible source of error. /// </summary> private void Calculate() { //Calculate token goal if using tickets int netToken; if (targetingTickets) { int elevenx = target / 11; int single = target % 11; netToken = elevenx * 100 + single * 10 - myTokens; } else { netToken = target - myTokens; } tokensReq = netToken; //Calculate gem cost for reaching target value int hundPack = netToken / 100; int tenPack = (int)Math.Ceiling((netToken % 100) / 10.0); int gemCost = (hundPack * 600 + tenPack * 80) - myGems; gemsReq = gemCost; //Trivial case where net gem cost is zero or negative (the user already has enough resources to fund their target) if (gemCost <= 0) { efficientOutputLabel.Text = "You already have enough tokens and gems to reach your goal."; return; } //Set temporary array for calculation depending on server int[,] gems; if (serverGl) { gems = (int[, ])glGemArray.Clone(); } else { gems = (int[, ])krGemArray.Clone(); } //Assess strategy EfficientOutputCalc(gemCost, gems); FormatEfficientOutput(); }
public int[,] ShowValidMoves(int row, int column, int[,] potentialMoves, int[,] potentialCaptures) { int[,] result = (int[, ])boardState.Clone(); int[,] mappedMoves = (int[, ])potentialMoves.Clone(); int[,] mappedCaptures = (int[, ])potentialCaptures.Clone(); for (int i = 0; i < mappedMoves.GetLength(0); i++) { mappedMoves[i, 0] += row; mappedMoves[i, 1] += column; // prevent off-board moves if (isOutOfBounds(mappedMoves, i) == true) { continue; } if (result[mappedMoves[i, 0], mappedMoves[i, 1]] == 0) { result[mappedMoves[i, 0], mappedMoves[i, 1]] = -1; } // else break; } for (int i = 0; i < mappedCaptures.GetLength(0); i++) { mappedCaptures[i, 0] += row; mappedCaptures[i, 1] += column; // prevent off-board captures if (isOutOfBounds(mappedCaptures, i) == true) { continue; } // prevent capture of own pieces int turn = ChessForm.turn; if (turn % 2 == 0 && boardState[mappedCaptures[i, 0], mappedCaptures[i, 1]] > 6 || turn % 2 == 1 && boardState[mappedCaptures[i, 0], mappedCaptures[i, 1]] < 7) { if (boardState[mappedCaptures[i, 0], mappedCaptures[i, 1]] > 0) { result[mappedCaptures[i, 0], mappedCaptures[i, 1]] = -2; } } } return(result); }
private static int minimaxValue(int[,] board, int originalTurn, int currentTurn, int currentSearchLevel, int maxSearchLevel) { int opponent = (currentTurn == Constants.W_TOKEN) ? Constants.B_TOKEN : Constants.W_TOKEN; if (currentSearchLevel == maxSearchLevel || GameFlow.isGameOver(board)) { return(heuristic(board, originalTurn)); } List <int[]> moves = GameFlow.getPosibleMoves(board); if (moves.Count <= 0) { return(minimaxValue(board, originalTurn, opponent, currentSearchLevel + 1, maxSearchLevel)); } else { int bestMovalHeuristic = (originalTurn == currentTurn) ? -99999 : 99999; for (int i = 0; i < moves.Count; i++) { int[,] tmpBoard = (int[, ])board.Clone(); int[] move = moves[i]; GameFlow.makeMove(tmpBoard, move[0], move[1], currentTurn); int val = minimaxValue(tmpBoard, originalTurn, opponent, currentSearchLevel + 1, maxSearchLevel); if (originalTurn == currentTurn) { if (val > bestMovalHeuristic) { bestMovalHeuristic = val; } } else { if (val < bestMovalHeuristic) { bestMovalHeuristic = val; } } } return(bestMovalHeuristic); } }
// MiniMax private int miniMax(int[,] miniboard, bool turn) { if (_boardManagerPrefab.isGameOver(miniboard) != 0) // Check if game ended { int result = calcScore(miniboard); return(result); } else // If not game over { int value; if (!turn) // Simulating player 1 turn { value = 10000; } else { value = -10000; } for (int i = 0; i < miniboard.GetLength(0); i++) // Test all available spaces { for (int j = 0; j < miniboard.GetLength(0); j++) { if (miniboard[i, j] == 0) { int[,] copyBoard = (int[, ])miniboard.Clone(); // Create a new int board that's a copy of entered parameter board if (!turn) // Simulating player 1 turn { copyBoard[i, j] = GameManager.instance.playerMagic; value = Mathf.Min(value, miniMax(copyBoard, !turn)); } else if (turn) // Simulating AI turn { copyBoard[i, j] = GameManager.instance.aiMagic; value = Mathf.Max(value, miniMax(copyBoard, !turn)); } } } } return(value); } }
public int[,] sortColumns(int[,] array) { int max = 0; int indexOfColumnWithMax = 0; int[] bufferarray = new int[array.GetLength(0)]; for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] > max) { max = array[i, j]; indexOfColumnWithMax = j; } } } Console.WriteLine(indexOfColumnWithMax); for (int i = 0; i < bufferarray.Length; i++) { bufferarray[i] = array[i, indexOfColumnWithMax]; Console.Write(bufferarray[i]); } Array.Sort(bufferarray); int[,] clone = (int[, ])array.Clone(); for (int k = 0; k < bufferarray.Length; k++) { for (int j = 0; j < clone.GetLength(0); j++) { if (clone[j, indexOfColumnWithMax] == bufferarray[k]) { for (int l = 0; l < array.GetLength(1); l++) { array[k, l] = clone[j, l]; } } } } return(array); }
public static int[,] ZeroMatrix(int[,] arr) { int rows = arr.GetLength(0); int cols = arr.GetLength(1); int[,] copy = (int[, ])arr.Clone(); for (int i = 0; i < rows; i++) { for (int k = 0; k < cols; k++) { if (copy[i, k] == 0) { arr = ZeroColRow(arr, i, k); } } } return(arr); }
private static void Backtracking(int stage) { for (int i = 0; i < BTmatrix.GetLength(0); i++) { if (Aceptable(i, stage) && !btSolved) { BTmatrix[i, stage] = 1; if (stage == BTmatrix.GetLength(1) - 1) { BTmatrixAux = (int[, ])BTmatrix.Clone(); btSolved = true; } else { Backtracking(stage + 1); } BTmatrix[i, stage] = 0; } } }
// Clones the current sudoku public Sudoku Clone() { Sudoku clone = new Sudoku { fixedNumbers = new HashSet <Tuple <int, int> >(fixedNumbers), grid = grid.Clone() as int[, ], constraintSet = new HashSet <Tuple <Tuple <int, int>, Tuple <int, int> > >(constraintSet), domains = new List <int> [Length, Length], mcvList = new List <Tuple <Tuple <int, int>, int> >(mcvList) }; for (int i = 0; i < Length; i++) { for (int j = 0; j < Length; j++) { clone.domains[i, j] = new List <int>(domains[i, j]); } } return(clone); }
public void setInitialState() { field = (int[, ])initialState.Clone(); correctCells = 0; for (int i = 0; i < FIELD_SIZE; ++i) { for (int j = 0; j < FIELD_SIZE; ++j) { if (field[i, j] > 0) { correctnessTable[i, j] = true; ++correctCells; } else { correctnessTable[i, j] = false; } } } }
public State GetResultingState(Action action) { //Apply action to the state int[,] newBoard = (int[, ])board.Clone(); newBoard[action.Row, action.Col] = (int)currentPlayer; Player player; //Switch player if (currentPlayer == Player.Blue) { player = Player.Red; } else { player = Player.Blue; } return(new State(newBoard, player)); }
private int[,] combineRight(int[,] boardIn) { int[,] board = boardIn.Clone() as int[, ]; // move top to bottom (rows) for (int i = 0; i < board.GetLength(0); i++) { // move right to left (columns) for (int j = board.GetLength(1) - 1; j > 0; j--) { // combine tiles if (board[i, j] == board[i, j - 1]) { board[i, j] *= 2; board[i, j - 1] = 0; } } } return(board); }
private int[,] combineDown(int[,] boardIn) { int[,] board = boardIn.Clone() as int[, ]; // move left to right (columns) for (int j = 0; j < board.GetLength(1); j++) { // move bottom to top (rows) for (int i = board.GetLength(0) - 1; i > 0; i--) { // combine tiles if (board[i, j] == board[i - 1, j]) { board[i, j] *= 2; board[i - 1, j] = 0; } } } return(board); }
private int[,] combineUp(int[,] boardIn) { int[,] board = boardIn.Clone() as int[, ]; // move left to right (columns) for (int j = 0; j < board.GetLength(1); j++) { // move top to bottom (rows) for (int i = 0; i < board.GetLength(0) - 1; i++) { // combine tiles if (board[i, j] == board[i + 1, j]) { board[i, j] *= 2; board[i + 1, j] = 0; } } } return(board); }
public void Click(Vector2 position) { if (Input.GetKey(KeyCode.LeftShift)) { if (pole[(int)position.x, (int)position.y] == 0) { ArrayChange(target, 0); target = position; ArrayChange(target, -2); } } else { if (pole[(int)position.x, (int)position.y] != -2) { ArrayChange(position, pole[(int)position.x, (int)position.y] == 0 ? -1 : 0); } } Vlna((int[, ])pole.Clone(), ps.GetPos()); }
public Sudoku Clone() // Clones the current sudoku { // The grid cloned Sudoku clone = new Sudoku(grid.Clone() as int[, ]) // A new array for the hashsets { columnUniques = columnUniques.Clone() as HashSet <int>[], rowsUniques = rowsUniques.Clone() as HashSet <int>[] }; // All hashsets cloned in arrays for (int i = 0; i < Length; i++) { clone.columnUniques[i] = new HashSet <int>(columnUniques[i]); clone.rowsUniques[i] = new HashSet <int>(rowsUniques[i]); } clone.fixedNumbers = new HashSet <Tuple <int, int> >(fixedNumbers); return(clone); }
/// <summary> /// Given an array with cells of the room set to one number, finds a cell in that list /// that is an approximate center of the room. For convex shapes this may not be ideal. /// </summary> /// <param name="regions"></param> /// <param name="roomNum"></param> /// <returns></returns> public static DetectorPoint GetApproximateRoomCenter(int[,] array, int roomNum, int[,] roomDensity = null) { if (!array.UniqueValues().Contains(roomNum)) { throw new ArgumentException($"Room {roomNum} not on the map.", nameof(roomNum)); } var a = (int[, ])array.Clone(); if (roomDensity == null) { roomDensity = GetRoomDensityMap(a); } a.UpDate(i => (i == roomNum) ? 1 : 0); roomDensity = roomDensity.Multiply(a); var point = MaxPoint(roomDensity); return(point); }
// It returns an array and making selected tiles value to -1 to indicate it and // added it to a List by using FloodFill Algorithm public List <Vector2Int> GetSelectedBlockTiles(Vector2Int index) { int[,] temp = _tiles.Clone() as int[, ]; List <Vector2Int> returnPositionOfSelectedCubes = new List <Vector2Int>(); BlockSelector.FloodFill(temp, index.x, index.y); for (int i = 0; i < ROW; i++) { for (int j = 0; j < COLUMN; j++) { if (temp[i, j] == -1) { returnPositionOfSelectedCubes.Add(new Vector2Int(i, j)); } } } return(returnPositionOfSelectedCubes); }
/// <summary> /// Sorts the matrix according to the established sort order. /// </summary> /// <param name="array">Matrix numbers</param> /// <param name="sortOrder">Sort Order</param> /// public override void Sort(int [,] matrix, SortOrder sortOrder) { int length; int[,] arrayClone = (int[, ])matrix.Clone(); int[] sumRows = SumRowsArray(matrix, out length); Comparisons comparisons = new Comparisons(sortOrder); for (int i = 0; i < length; i++) { for (int j = i + 1; j < length; j++) { if (comparisons.Compare(sumRows[i], sumRows[j])) { ArrayHelper.SwapRows(matrix, i, j, length); ArrayHelper.SwapValues(ref sumRows[i], ref sumRows[j]); } } } }
public Tuple <int, int> GetBestAction(int[,] state) { Tuple <int, int> bestAction = null; int best = int.MinValue; List <Tuple <int, int> > cells = Game.GetFreeCells(state); foreach (Tuple <int, int> c in cells) { int[,] newState = (int[, ])state.Clone(); newState[c.Item1, c.Item2] = id; int score = SimulateMin(newState); if (bestAction == null || score > best) { best = score; bestAction = c; } } return(bestAction); }
public override Node GetNextState(int move) { int[,] nextBoard = (int[, ])board.Clone(); MiniCoord nextCoord = miniBoard; int x = move / 9; int y = move % 9; nextBoard[x, y] = ActivePlayer; nextCoord.Set(x % 3, y % 3); if (MiniWinner(nextCoord) != -1 || MiniFull(nextCoord)) { nextCoord.Reset(); } return(new UltimateTicTacToeNode() { ActivePlayer = (ActivePlayer + 1) % 2, board = nextBoard, miniBoard = nextCoord }); }
public static int[,] ForMove(this int[,] source, Move side) { var size = source.GetLength(0); switch (side) { case Move.Left: return((int[, ])source.Clone()); case Move.Right: return(source.Matrix(OneEighty(size))); case Move.Up: return(source.Matrix(CounterClockwise(size))); case Move.Down: return(source.Matrix(Clockwise(size))); } throw new ArgumentException("Invalid Move", nameof(side)); }
// Выбираем ветку - НУЖНО ТЕСТИРОВАНИЕ private void SetMainMatrix() { if (classicLeftBranchLimit <= classicRightBranchLimit && classicLeftBranchLimit <= classic_plus_LeftBranchLimit && classicLeftBranchLimit <= classic_plus_RightBranchLimit) { } if (classic_plus_LeftBranchLimit <= classic_plus_RightBranchLimit) { MainMatrix = classic_plus_matrix_left_branch.Clone() as int[, ]; way_func.Add(zero_row_index + 1, zero_column_index + 1); MainMatrixMinLimit += classic_plus_LeftBranchLimit; } else { MainMatrix = classic_plus_matrix_right_branch.Clone() as int[, ]; MainMatrixMinLimit += classic_plus_RightBranchLimit; } }
private void UndoStep(object sender, EventArgs e) { if (canUndo) { foreach (Control c in this.Controls) { if (c is TextBox && c.Name == "Score") { c.Text = undoPoint; } } foreach (Control c in panel1.Controls) { PictureBox p = (PictureBox)c; p.Image = null; } LoadImage(UndoBoard); board = (int[, ])UndoBoard.Clone(); } }
public static void Recursion(int[,] board, int row, int col) { for (int i = row; i < N; i++) { for (int j = col; j < N; j++) { var tempBoard = (int[, ])board.Clone(); if (canAdd(tempBoard, i, j)) { tempBoard[i, j] = 1; if (CheckQueensCount(tempBoard)) { totalSolutions++; } Recursion(tempBoard, row + 1, 0); } } } }
public int[,] solve(int[,] question) { int[,] result = (int[, ])question.Clone(); while (true) { result = solvePossibleNum(result); if (!validate(result)) { break; } if (!isPossibleToSolve(result)) { break; } } return(result); }
public int[,] FloydWarshallAlgorithm(int [,] incidencyMatrix) { int[,] distanceMatrix = (int[, ])incidencyMatrix.Clone(); InicializeDistanceMatrix(distanceMatrix); for (int k = 0; k < distanceMatrix.GetLength(0); k++) { for (int i = 0; i < distanceMatrix.GetLength(0); i++) { for (int j = 0; j < distanceMatrix.GetLength(0); j++) { if (distanceMatrix[i, j] > distanceMatrix[i, k] + distanceMatrix[k, j]) { distanceMatrix[i, j] = distanceMatrix[i, k] + distanceMatrix[k, j]; } } } } return(distanceMatrix); }
public List <KeyValuePair <Tuple <int, int>, int> > ReduceMoves(int[,] board, IEnumerable <Tuple <int, int> > CellsToCheck) { Dictionary <Tuple <int, int>, int> iscores = new Dictionary <Tuple <int, int>, int>(); foreach (Tuple <int, int> cell in CellsToCheck) { int[,] newBoard = (int[, ])board.Clone(); newBoard[cell.Item1, cell.Item2] = 1; int estimation = Evaluate(newBoard, cell, 1); iscores[cell] = estimation; } var items = from i in iscores orderby i.Value descending select i; List <KeyValuePair <Tuple <int, int>, int> > cellsToCheckList = items.Take(10).ToList(); if (cellsToCheckList[0].Value > 430000) { return(cellsToCheckList.Take(1).ToList()); } return(cellsToCheckList); }
//二维矩阵得到最多苹果 static int GetMaxApple(int[,] map) { //初始化二维矩阵储存当前最大值,并将【0,0】赋值为当前的map【0,0】 int[,] maxApple = (int[, ])map.Clone(); Array.Clear(maxApple, 0, maxApple.Length); maxApple[0, 0] = map[0, 0]; int row = maxApple.GetLength(0); int column = maxApple.GetLength(1); //按行遍历map for (int i = 0; i < row; i++) { for (int j = 0; j < column; j++) { //如果非首行,则判断上面来的路径的最大值和当前值比较。 if (i > 0) { maxApple[i, j] = maxApple[i - 1, j] + map[i, j] > maxApple[i, j] ? maxApple[i - 1, j] + map[i, j] : maxApple[i, j]; } //如果非首列,则判断左面路径的最大值和当前值比较。 if (j > 0) { maxApple[i, j] = maxApple[i, j - 1] + map[i, j] > maxApple[i, j] ? maxApple[i, j - 1] + map[i, j] : maxApple[i, j]; } } } //遍历maxApple的最下行和最右列,找到最大值输出。 int max = 0; for (int i = 0; i < row; i++) { max = max > maxApple[i, column - 1] ? max : maxApple[i, column - 1]; } for (int i = 0; i < column; i++) { max = max > maxApple[row - 1, i] ? max : maxApple[row - 1, i]; } return(max); }
static void Main(string[] args) { Matrix = readConnectivityMatrix("input.txt"); Matrix2 = (int[,]) Matrix.Clone(); //printMatrix(); outputAnswer(solveProblem(Matrix2), "output.txt"); Console.WriteLine(validate("output.txt")); Console.ReadKey(); }
internal void lightingThreadUpdate() { if (lightingNeedsUpdate) { Profiler.start("lighting"); TempLightMatrix = (int[,])LightMatrix.Clone(); int border = 16; for (int x = viewPortInTiles.X - border; x < viewPortInTiles.X + viewPortInTiles.Width + 1 + border; x++) { for (int y = viewPortInTiles.Y - border; y < viewPortInTiles.Y + viewPortInTiles.Height + 1 + border; y++) { lightUpdate1(x, y); } } for (int x = viewPortInTiles.X - border; x < viewPortInTiles.X + viewPortInTiles.Width + 1 + border; x++) { lightUpdate2(x, viewPortInTiles.Y - border, true); for (int y = viewPortInTiles.Y + 1 - border; y < viewPortInTiles.Y + viewPortInTiles.Height + 1 + border; y++) { lightUpdate2(x, y, false); } } LightMatrix = (int[,])TempLightMatrix.Clone(); lightingNeedsUpdate = false; Profiler.end("lighting"); lightingThreadFps.update(); } }
// // Method: GetNextShape(), // public void GetNextShape() { // get next shape m_Shapes.NextShape(); m_intShape = m_Shapes.GetShape(); // save original orientation m_intShapeOriginal = (int[,]) m_intShape.Clone(); // initialize well location m_intShapeHeight = m_Shapes.GetHeight; m_intShapeWidth = m_Shapes.GetWidth; m_intCurrentRow = (0 - m_Shapes.GetHeight); m_intCurrentCol = (10 - m_Shapes.GetWidth) / 2; }
private void upKeyDown() { testIsGameOver(); if (isGameOver || isGameWin == 1) { return; } lastStep = (int[,])table.Clone(); resetAnimation(); for (int j = 0; j < 4; j++) { if (table[0, j] == 0) { if (table[1, j] == 0) { if (table[2, j] == 0) { if (table[3, j] == 0) {; } else { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 150, table[3, j]); table[0, j] = table[3, j]; table[3, j] = 0; } } else { if (table[3, j] == 0) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 150, table[2, j]); table[0, j] = table[2, j]; table[2, j] = 0; } else if (table[3, j] == table[2, j]) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 150, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 150, table[3, j], table[3, j]); table[0, j] = table[2, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[2, j] = 0; table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 150, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j]); table[0, j] = table[2, j]; table[1, j] = table[3, j]; table[2, j] = 0; table[3, j] = 0; } } } else { if (table[2, j] == 0) { if (table[j, 3] == 0) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); table[0, j] = table[1, j]; table[1, j] = 0; } else if (table[1, j] == table[3, j]) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 150, table[3, j], table[3, j]); table[0, j] = table[1, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[1, j] = 0; table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j]); table[0, j] = table[1, j]; table[1, j] = table[3, j]; table[3, j] = 0; } } else { if (table[3, j] == 0) { if (table[1, j] == table[2, j]) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 150, table[2, j], table[2, j]); table[0, j] = table[2, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[1, j] = 0; table[2, j] = 0; } else { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); table[0, j] = table[1, j]; table[1, j] = table[2, j]; table[2, j] = 0; } } else { if (table[1, j] == table[2, j]) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 150, table[2, j], table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j]); table[0, j] = table[2, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[2, j] = 0; table[1, j] = table[3, j]; table[3, j] = 0; } else if (table[2, j] == table[3, j]) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j], table[3, j]); table[0, j] = table[1, j]; table[1, j] = table[3, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[1, j]).ToString(); table[2, j] = 0; table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 350, table[3, j]); table[0, j] = table[1, j]; table[1, j] = table[2, j]; table[2, j] = table[3, j]; table[3, j] = 0; } } } } } else { makeComposedPictures(100 * j + 50, 150, 100 * j + 50, 150, table[0, j]); if (table[1, j] == 0) { if (table[2, j] == 0) { if (table[3, j] == 0) { ; } else if (table[0, j] == table[3, j]) { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 150, table[3, j], table[3, j]); table[0, j] = table[3, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j]); table[1, j] = table[3, j]; table[3, j] = 0; } } else if (table[2, j] == table[0, j]) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 150, table[2, j], table[2, j]); table[0, j] = table[2, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[2, j] = 0; if (table[3, j] != 0) { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j]); table[1, j] = table[3, j]; table[3, j] = 0; } } else { if (table[3, j] == 0) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); table[1, j] = table[2, j]; table[2, j] = 0; } else if (table[3, j] == table[2, j]) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j], table[3, j]); table[1, j] = table[3, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[1, j]).ToString(); table[2, j] = 0; table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 350, table[3, j]); table[1, j] = table[2, j]; table[2, j] = table[3, j]; table[3, j] = 0; } } } else if (table[1, j] == table[0, j]) { if (table[2, j] == 0) { if (table[3, j] == 0) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j], table[1, j]); table[0, j] = table[1, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[1, j] = 0; } else { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j], table[1, j]); table[0, j] = table[1, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j]); table[1, j] = table[3, j]; table[3, j] = 0; } } else { if (table[3, j] == table[2, j]) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j], table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j], table[3, j]); table[0, j] = table[1, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[1, j] = table[2, j]; table[1, j] = table[3, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[1, j]).ToString(); table[2, j] = 0; table[3, j] = 0; } else { if (table[3, j] == 0) { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j], table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); table[0, j] = table[1, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[1, j] = table[2, j]; table[2, j] = 0; } else { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 150, table[1, j], table[1, j]); makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 350, table[3, j]); table[0, j] = table[1, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[0, j]).ToString(); table[1, j] = table[2, j]; table[2, j] = table[3, j]; table[3, j] = 0; } } } } else { makeComposedPictures(100 * j + 50, 250, 100 * j + 50, 250, table[1, j]); if (table[2, j] == 0) { if (table[3, j] == 0) { ; } else if (table[3, j] == table[1, j]) { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 250, table[3, j], table[3, j]); table[1, j] = table[3, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[1, j]).ToString(); table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 350, table[3, j]); table[2, j] = table[3, j]; table[3, j] = 0; } } else if (table[1, j] == table[2, j]) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 250, table[2, j], table[2, j]); table[1, j] = table[2, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[1, j]).ToString(); table[2, j] = 0; if (table[3, j] != 0) { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 350, table[3, j]); table[2, j] = table[3, j]; table[3, j] = 0; } } else if (table[2, j] == table[3, j]) { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 350, table[2, j]); makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 350, table[3, j], table[3, j]); table[2, j] = table[3, j] << 1; label_score.Text = (Convert.ToInt32(label_score.Text) + table[2, j]).ToString(); table[3, j] = 0; } else { makeComposedPictures(100 * j + 50, 350, 100 * j + 50, 350, table[2, j]); if (table[3, j] != 0) { makeComposedPictures(100 * j + 50, 450, 100 * j + 50, 450, table[3, j]); } } } } } int score = Convert.ToInt32(label_score.Text); int best = Convert.ToInt32(label_best.Text); if (score > best) label_best.Text = score.ToString(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (lastStep[i, j] != table[i, j]) { randomProduct(); showAnimation(); testIsWin(); if (isGameWin == 1) { Graphics g = (new PaintEventArgs(CreateGraphics(), ClientRectangle)).Graphics; g.DrawImage(gameWin, 40, 140); g.Dispose(); } return; } } } table = (int[,])lastStep.Clone(); }