private void initRotationVariables(Position[,] blocks) { newRotationMatrix = new Position[blocks.GetLength(1), blocks.GetLength(0)]; blockPivot = blocks[blocks.GetLength(0) / 2, blocks.GetLength(1) / 2]; newRotationColumn = 0; newRotationRow = 0; xRotationPos = -(blocks.GetLength(0) / 2); yRotationPos = 0; invalidRotation = false; }
private static void PrintPositions(this Position[,] positions) { System.Console.WriteLine(); for (var i = 0; i < positions.GetLength(0); i++) { var line = string.Empty; for (var j = 0; j < positions.GetLength(1); j++) { switch (positions[i, j].State) { case PositionState.Floor: line += '.'; break; case PositionState.Empty: line += 'L'; break; case PositionState.Occupied: line += '#'; break; } } System.Console.WriteLine(line); } System.Console.WriteLine(); }
internal static Snap.NX.Bsurface CreateBsurface(Position[,] poles, double[,] weights, double[] knotsU, double[] knotsV) { int num10; int num11; Tag tag; int length = poles.GetLength(0); int num2 = knotsU.Length; int ku = num2 - length; int nv = poles.GetLength(1); int num5 = knotsV.Length; int kv = num5 - nv; double[] numArray = new double[(4 * length) * nv]; for (int i = 0; i < length; i++) { for (int j = 0; j < nv; j++) { int index = 4 * ((length * j) + i); numArray[index] = poles[i, j].X * weights[i, j]; numArray[index + 1] = poles[i, j].Y * weights[i, j]; numArray[index + 2] = poles[i, j].Z * weights[i, j]; numArray[index + 3] = weights[i, j]; } } Globals.UFSession.Modl.CreateBsurf(length, nv, ku, kv, knotsU, knotsV, numArray, out tag, out num10, out num11); NXOpen.Body objectFromTag = (NXOpen.Body)Snap.NX.NXObject.GetObjectFromTag(tag); Session.UndoMarkId undoMark = Globals.Session.SetUndoMark(Session.MarkVisibility.Invisible, ""); Globals.Session.UpdateManager.DoUpdate(undoMark); Globals.Session.DeleteUndoMark(undoMark, null); return(new Snap.NX.Bsurface(objectFromTag)); }
private static Position[,] SimulateRound(Position[,] before, int numberWhenPeopleLeave, Func <Position[, ], int, int, int> numberOfAdjacents) { Position[,] after = before.Clone() as Position[, ]; for (int i = 0; i < before.GetLength(0); ++i) { for (int j = 0; j < before.GetLength(1); ++j) { if (before[i, j] == Position.Floor) { continue; } int adjacents = numberOfAdjacents(before, i, j); if (adjacents >= numberWhenPeopleLeave) { after[i, j] = Position.Empty; } if (adjacents == 0) { after[i, j] = Position.Occupied; } } } return(after); }
private char BuscaProximoComandoValido() { if (playerController.VerificaPosPulo(lvl.PosPlayerX, lvl.PosPlayerY) != ' ') { return(PlayerController.jump); } else if (lvl.PosPlayerY > 0 && gameMat[lvl.PosPlayerX, lvl.PosPlayerY - 1].Tipo == Position.Tile) { //print("BuscaProximoComandoValido -> esquerda"); return(PlayerController.esquerda); } else if (lvl.PosPlayerX > 0 && gameMat[lvl.PosPlayerX - 1, lvl.PosPlayerY].Tipo == Position.Tile) { //print("BuscaProximoComandoValido -> cima"); return(PlayerController.cima); } else if (lvl.PosPlayerY < gameMat.GetLength(1) && gameMat[lvl.PosPlayerX, lvl.PosPlayerY + 1].Tipo == Position.Tile) { //print("BuscaProximoComandoValido -> direita"); return(PlayerController.direita); } else if (lvl.PosPlayerX < gameMat.GetLength(0) && gameMat[lvl.PosPlayerX + 1, lvl.PosPlayerY].Tipo == Position.Tile) { //print("BuscaProximoComandoValido -> baixo"); return(PlayerController.baixo); } return(' '); }
private static bool ApplyRulesPart2(Position[,] positions) { bool peopleMoved = false; for (var i = 0; i < positions.GetLength(0); i++) { for (var j = 0; j < positions.GetLength(1); j++) { var position = positions[i, j]; if (position.State == PositionState.Floor) { continue; } var adjacents = GetFirstNotFloorAdjacents(positions, i, j); if (position.State == PositionState.Empty && adjacents.Count(x => x.State == PositionState.Occupied) == 0) { peopleMoved = true; position.ChangeState = true; continue; } if (position.State == PositionState.Occupied && adjacents.Count(x => x.State == PositionState.Occupied) >= 5) { peopleMoved = true; position.ChangeState = true; continue; } } } positions.ApplyChanges(); return(peopleMoved); }
public Position[,] rotate(Position[,] boardPositions, Position[,] blocks) { initRotationVariables(blocks); for (int oldColumn = blocks.GetLength(1) - 1; oldColumn >= 0; oldColumn--) { resetRotationColumns(blocks); for (int oldRow = 0; oldRow < blocks.GetLength(0); oldRow++) { if (blocks[oldRow, oldColumn] != null) { invalidRotation = checkForInvalidRotations(boardPositions, blockPivot.x + xRotationPos, blockPivot.y + yRotationPos); if (!invalidRotation) { retrieveNewRotationBlock(boardPositions); } else { break; } } incrementRotationColumns(); } if (invalidRotation) { break; } incrementRotationRows(); } if (invalidRotation) { return(blocks); } return(newRotationMatrix); }
public Grid(int size) { points = new Position[size + 1, size + 1]; for (int i = 0; i < points.GetLength(0); i++) { for (int j = 0; j < points.GetLength(1); j++) { points[i, j] = new Position(i, j); } } }
private void checkLineComplete() { int lineCompleteCounter = 0; for (int y = 0; y < placedBlocks.GetLength(1); y++) { lineCompleteCounter = retrieveValueOfLineCompleted(lineCompleteCounter, y); if (lineCompleteCounter == placedBlocks.GetLength(0)) { addScoreAndLevel(); cleanLine(y); moveTopLines(y); } } }
internal static Snap.NX.Bsurface CreateBsurface(Position[,] poles, double[] knotsU, double[] knotsV) { int length = poles.GetLength(0); int num2 = poles.GetLength(1); double[,] weights = new double[length, num2]; for (int i = 0; i < length; i++) { for (int j = 0; j < num2; j++) { weights[i, j] = 1.0; } } return(CreateBsurface(poles, weights, knotsU, knotsV)); }
public static double[,] GetZ(Position[,] positions) { int length = positions.GetLength(0); int num2 = positions.GetLength(1); double[,] numArray = new double[length, num2]; for (int i = 0; i < length; i++) { for (int j = 0; j < num2; j++) { numArray[i, j] = positions[i, j].Z; } } return(numArray); }
public bool checkCollisionWithWallsAndBottom(Position[,] board, Position[,] blocks, int objXPosition, int objYPosition) { foreach (Position pos in blocks) { if (pos != null) { populateFakePositions(objXPosition, objYPosition, pos); if (fakeX < 0 || fakeX >= board.GetLength(0) || fakeY >= board.GetLength(1)) { return(true); } } } return(false); }
private static List <Position> GetAdjacents(Position[,] positions, int i, int j) { var toReturn = new List <Position>(); var iMaxValue = positions.GetLength(0); var jMaxValue = positions.GetLength(1); // Up if (j - 1 > -1) { toReturn.Add(positions[i, j - 1]); } // Right if (i + 1 < iMaxValue) { toReturn.Add(positions[i + 1, j]); } // Down if (j + 1 < jMaxValue) { toReturn.Add(positions[i, j + 1]); } // Left if (i - 1 > -1) { toReturn.Add(positions[i - 1, j]); } // Left Up if (i - 1 > -1 && j - 1 > -1) { toReturn.Add(positions[i - 1, j - 1]); } // Right Up if (i + 1 < iMaxValue && j - 1 > -1) { toReturn.Add(positions[i + 1, j - 1]); } // Right Down if (i + 1 < iMaxValue && j + 1 < jMaxValue) { toReturn.Add(positions[i + 1, j + 1]); } // Left Down if (i - 1 > -1 && j + 1 < jMaxValue) { toReturn.Add(positions[i - 1, j + 1]); } return(toReturn); }
private static void PrintPosition(Position[,] pos) { for (int i = 0; i < pos.GetLength(0); ++i) { for (int j = 0; j < pos.GetLength(1); ++j) { char c = pos[i, j] == Position.Floor ? '.' : pos[i, j] == Position.Empty ? 'L' : '#'; Console.Write(c); } Console.Write("\n"); } }
//Posiciona o jogador na primeira tile do jogo void posicionaJogador(Position[,] gameMat) { //Sempre a posição do meio int i = gameMat.GetLength(0) - 1; lvl.atualizaPosPlayer(i, 1); lvl.setaPorIniPlayer(i, 1); //Instancia o jogador Instantiate(player, new Vector3(gameMat[i, 1].PosX, gameMat[i, 1].PosY, -1.2f), Quaternion.identity); }
private static double[] ChordalNodesU(Position[,] intPoints) { int length = intPoints.GetLength(0); int num2 = intPoints.GetLength(1); Position[] positionArray = new Position[num2]; double[,] a = new double[length, num2]; for (int i = 0; i < length; i++) { double[] numArray2 = ChordalNodes(Snap.Math.MatrixMath.GetRow(intPoints, i)); for (int k = 0; k < num2; k++) { a[i, k] = numArray2[k]; } } double[] numArray3 = new double[num2]; for (int j = 0; j < num2; j++) { numArray3[j] = Snap.Math.Mean(Snap.Math.MatrixMath.GetColumn(a, j)); } return(numArray3); }
private void handleMovement(Position[,] gameBoardPositions, List <Position> snakeBody, Keys keyToMove, int x, int y) { if (nextKeyMovement == keyToMove) { if (canMoveToPosition(keyToMove, gameBoardPositions.GetLength(0), snakeBody)) { performMovement(gameBoardPositions, snakeBody, x, y); } else { snakeCollision = true; } } }
//Verifica se pode mover o personagem na direção bool VerificaMovimentoValido(char mov) { //Testa se está movendo para cima e se não é o fim da matriz if (mov == cima && lvl.PosPlayerX > 0) { if (gameMat[lvl.PosPlayerX - 1, lvl.PosPlayerY].Tipo == Position.Tile) { return(true); } } //Testa se está movendo para baixo e se não é o fim da matriz if (mov == baixo && lvl.PosPlayerX < gameMat.GetLength(0) - 1) { if (gameMat[lvl.PosPlayerX + 1, lvl.PosPlayerY].Tipo == Position.Tile) { return(true); } } ////Testa se está movendo para esquerda e se não é o fim da matriz if (mov == esquerda && lvl.PosPlayerY > 0) { if (gameMat[lvl.PosPlayerX, lvl.PosPlayerY - 1].Tipo == Position.Tile) { return(true); } } //Testa se está movendo para direita e se não é o fim da matriz if (mov == direita && lvl.PosPlayerY < gameMat.GetLength(1) - 1) { if (gameMat[lvl.PosPlayerX, lvl.PosPlayerY + 1].Tipo == Position.Tile) { return(true); } } return(false); }
private static bool IsSeatOccupiedSeenInDirection(Position[,] before, int i, int j, Func <int, int> dirI, Func <int, int> dirJ) { while (true) { i = dirI(i); j = dirJ(j); if (i < 0 || i >= before.GetLength(0) || j < 0 || j >= before.GetLength(1)) { return(false); } if (before[i, j] == Position.Empty) { return(false); } if (before[i, j] == Position.Occupied) { return(true); } } }
private static int NumberOfOccupiedAdjacents(Position[,] before, int i, int j) { int adjacents = 0; for (int ii = i - 1; ii <= i + 1; ++ii) { for (int jj = j - 1; jj <= j + 1; ++jj) { if (i == ii && j == jj) { continue; } if (ii >= 0 && ii < before.GetLength(0) && jj >= 0 && jj < before.GetLength(1) && before[ii, jj] == Position.Occupied) { ++adjacents; } } } return(adjacents); }
private static Position[,] generateBlock(Position[,] boardPositions, int[,] blockBluePrint, Color color) { Position[,] positions = new Position[blockBluePrint.GetLength(0), blockBluePrint.GetLength(1)]; for (int x = 0; x < blockBluePrint.GetLength(0); x++) { for (int y = 0; y < blockBluePrint.GetLength(1); y++) { if (blockBluePrint[x, y] == 1) { positions[x, y] = boardPositions[(boardPositions.GetLength(0) / 2) + x - (blockBluePrint.GetLength(0) / 2), y]; positions[x, y].color = color; } } } return(positions); }
public void PrintBoard() { for (int i = 0; i < Board.GetLength(0); i++) { for (int j = 0; j < Board.GetLength(1); j++) { var currentCell = Board[j, i]; if (currentCell.Visited) { Console.Write(" + "); } else { Console.Write(" - "); } if (currentCell.x == Board.GetLength(0) - 1) { Console.Write('\n'); } } } }
private static List <Position> GetFirstNotFloorAdjacents(Position[,] positions, int i, int j) { var toReturn = new List <Position>(); var iMaxValue = positions.GetLength(0); var jMaxValue = positions.GetLength(1); // Up for (var row = j - 1; row > -1; row--) { if (positions[i, row].State != PositionState.Floor) { // System.Console.WriteLine($"Added up: {i}:{row}"); toReturn.Add(positions[i, row]); break; } } // Right for (var column = i + 1; column < iMaxValue; column++) { if (positions[column, j].State != PositionState.Floor) { // System.Console.WriteLine($"Added right: {column}:{j}"); toReturn.Add(positions[column, j]); break; } } // Down for (var row = j + 1; row < jMaxValue; row++) { if (positions[i, row].State != PositionState.Floor) { // System.Console.WriteLine($"Added down: {i}:{row}"); toReturn.Add(positions[i, row]); break; } } // Left for (var column = i - 1; column > -1; column--) { if (positions[column, j].State != PositionState.Floor) { // System.Console.WriteLine($"Added left: {column}:{j}"); toReturn.Add(positions[column, j]); break; } } // Left up for (int column = i - 1, row = j - 1; column > -1 && row > -1; column--, row--) { if (positions[column, row].State != PositionState.Floor) { // System.Console.WriteLine($"Added left up: {column}:{row}"); toReturn.Add(positions[column, row]); break; } } // Right up for (int column = i + 1, row = j - 1; column < iMaxValue && row > -1; column++, row--) { if (positions[column, row].State != PositionState.Floor) { // System.Console.WriteLine($"Added right up: {column}:{row}"); toReturn.Add(positions[column, row]); break; } } // Right down for (int column = i + 1, row = j + 1; column < iMaxValue && row < jMaxValue; column++, row++) { if (positions[column, row].State != PositionState.Floor) { // System.Console.WriteLine($"Added right down: {column}:{row}"); toReturn.Add(positions[column, row]); break; } } // Left down for (int column = i - 1, row = j + 1; column > -1 && row < jMaxValue; column--, row++) { if (positions[column, row].State != PositionState.Floor) { // System.Console.WriteLine($"Added left down: {column}:{row}"); toReturn.Add(positions[column, row]); break; } } return(toReturn); }
public static int ColumnCount(Position[,] a) { return(a.GetLength(1)); }
public static int RowCount(Position[,] a) { return(a.GetLength(0)); }
// Use this for initialization void Start() { //Valor de offset para separar as tiles const float offset = 0.1f; const float camOffsetUp = 1f; //Altura da tile float tileHeight = tile.transform.localScale.x; //Altura da tela float height = Camera.main.orthographicSize; float tmpHeight = -height + (tileHeight / 2) + offset; //Seta a máxima posição para baixo/cima da tela, de forma a controlar o movimento da tela. lvl = (LevelController)gameController.GetComponent("LevelController"); lvl.MaxCamPosDown = -height; lvl.MaxCamPosUp = height; //Pega a matriz de jogo do nível atual scene = SceneManager.GetActiveScene(); //Busca a matriz de jogo conforme cada nível Position[,] gameMat = lvl.GetGameMat(scene.name); //Varre cada linha da matriz do jogo for (int i = gameMat.GetLength(0) - 1; i >= 0; i--) // X { if (gameMat[i, 0].Tipo == Position.Tile || gameMat[i, 0].Tipo == Position.Buraco) { if (gameMat[i, 0].Tipo == Position.Tile) { //Cria as tiles conforme a matriz Instantiate(tile, new Vector3(-tileHeight - offset, tmpHeight, -1), Quaternion.identity); } else if (gameMat[i, 0].Tipo == Position.Buraco) { //Cria os holes conforme a matriz Instantiate(hole, new Vector3(-tileHeight - offset, tmpHeight, -1), Quaternion.identity); } //Atualiza dados da posição da matriz gameMat[i, 0].setaPos(-tileHeight - offset, tmpHeight); //Posiciona objeto se a posição for final PosicionaObjFimLevel(gameMat[i, 0].Final, -tileHeight - offset, tmpHeight); } if (gameMat[i, 1].Tipo == Position.Tile || gameMat[i, 1].Tipo == Position.Buraco) { if (gameMat[i, 1].Tipo == Position.Tile) { //Cria as tiles conforme a matriz Instantiate(tile, new Vector3(0, tmpHeight, -1), Quaternion.identity); } else if (gameMat[i, 1].Tipo == Position.Buraco) { //Cria os holes conforme a matriz Instantiate(hole, new Vector3(0, tmpHeight, -1), Quaternion.identity); } //Atualiza dados da posição da matriz gameMat[i, 1].setaPos(0, tmpHeight); //Posiciona objeto se a posição for final PosicionaObjFimLevel(gameMat[i, 1].Final, 0, tmpHeight); } if (gameMat[i, 2].Tipo == Position.Tile || gameMat[i, 2].Tipo == Position.Buraco) { if (gameMat[i, 2].Tipo == Position.Tile) { //Cria as tiles conforme a matriz Instantiate(tile, new Vector3(tileHeight + offset, tmpHeight, -1), Quaternion.identity); } else if (gameMat[i, 2].Tipo == Position.Buraco) { //Cria os holes conforme a matriz Instantiate(hole, new Vector3(tileHeight + offset, tmpHeight, -1), Quaternion.identity); } //Atualiza dados da posição da matriz gameMat[i, 2].setaPos(tileHeight + offset, tmpHeight); //Posiciona objeto se a posição for final PosicionaObjFimLevel(gameMat[i, 2].Final, tileHeight + offset, tmpHeight); } tmpHeight += tileHeight + offset; //Atualiza a máxima posição para cima da tela, de forma a controlar o movimento da tela. if (tmpHeight > lvl.MaxCamPosUp) { lvl.MaxCamPosUp = tmpHeight - (tileHeight / 2) + camOffsetUp; } } //Posiciona o jogador na primeira tile do jogo posicionaJogador(gameMat); }
//GetColumnPar creates a list of values of some property identified as an string public List <double> GetColumnPar(int col, string parameter, int steps, Position dimens, int finStep) { List <double> columna = new List <double>(); int i = 0; int initStep = 0; while (i < malla.GetLength(0) && i <= finStep) // steps are the number of dismissed position { // dimens is an object position that contains the dimensional values of each property if (initStep == 0) // only initStep = 0 is added, others are dismiis, later some condition will make initStep return to 0 { Position pos = GetPosition(i, col); if (pos != null) { double value; if (parameter == "x") { value = Math.Round(pos.GetX(), 4); } else if (parameter == "T") { value = Math.Round(pos.GetTemperature() * dimens.GetTemperature(), 4); } else if (parameter == "D") { value = Math.Round(pos.GetDensity() * dimens.GetDensity(), 4); } else if (parameter == "V") { value = Math.Round(pos.GetVelocity() * dimens.GetVelocity(), 4); } else if (parameter == "P") // dimensional P units are hPa { if (dimens.GetPressure() != 1) { value = Math.Round(pos.GetPressure() * dimens.GetPressure(), 4) * dimens.R / 100; } else { value = Math.Round(pos.GetPressure() * dimens.GetPressure(), 4); } } else if (parameter == "A") { value = Math.Round(pos.GetArea(), 4); } else if (parameter == "M") { value = Math.Round(pos.MachNumber(), 4); } else { value = -2; } if (value != -2) { columna.Add(value); } } else { break; } } if (initStep == steps) // here we code the way we dismiss values, the next position of the while will has initStep = 0, that are the only cases added { initStep = -1; } initStep++; i++; } return(columna); }
private void resetRotationColumns(Position[,] blocks) { newRotationColumn = 0; yRotationPos = -(blocks.GetLength(1) / 2); }
private bool checkForInvalidRotations(Position[,] boardPositions, int x, int y) { return(x < 0 || x >= boardPositions.GetLength(0) || y >= boardPositions.GetLength(1)); }