//// height and width of the padded array //public static sbyte[,] RunLengthDecodeZigZag(int height, int width, byte[] data) //{ // return ZigZagTransform(height, width, RunLengthDecode(data)); //} // the dimension of data is multiple of 8 public static sbyte[] ZigZagTransform(sbyte[,] data) { int h = data.GetLength(0), w = data.GetLength(1); var stream = new sbyte[h * w]; int streamIndex = 0; for (int row = 0; row < h; row += N) { for (int col = 0; col < w; col += N) { var block8 = new sbyte[N, N]; // 8*8 block filling for (int _y = 0, Y = row; _y < N; ++_y, ++Y) { for (int _x = 0, X = col; _x < N; ++_x, ++X) { block8[_y, _x] = data[Y, X]; } } sbyte[] zigzagStream8 = ZigZagTransform8(block8); // append all return blocks sequentially for (int i = 0; i < 64; ++i) { stream[streamIndex++] = zigzagStream8[i]; } } } return(stream); }
public static byte[,] DefineEdges(byte[,] binaryArray, sbyte[,] mask) { int maskLengthAxisX = mask.GetLength(0); int maskLengthAxisY = mask.GetLength(1); int byteStepsAxisX = binaryArray.GetLength(0) - maskLengthAxisX; int byteStepsAxisY = binaryArray.GetLength(1) - maskLengthAxisY; var analizedField = new byte[byteStepsAxisX, byteStepsAxisY]; // Image traversal for (int x = 0; x < byteStepsAxisX; x++) { for (int y = 0; y < byteStepsAxisY; y++) { double color = 0; for (int mx = 0; mx < maskLengthAxisX; mx++) { for (int my = 0; my < maskLengthAxisY; my++) { color += binaryArray[x + mx, y + my] * mask[mx, my]; } } analizedField[x, y] = color.StabelizeColorChanel(); } } return(analizedField); }
public IEnumerator SetUp(sbyte[,] matrix) { //cG.alpha = 1; //this.matrix = matrix; yield return(null); int[] strategyA = (matrix.GetLength(0) == 2) ? GetRow(0) : GetColumn(0); int[] strategyB = (matrix.GetLength(0) == 2) ? GetRow(1) : GetColumn(1); #region Wyszukiwanie najmniejszej i największej wartości int min, max; int minA = strategyA.Min(); int minB = strategyB.Min(); int maxA = strategyA.Max(); int maxB = strategyB.Max(); min = (minA < minB) ? minA : minB; max = (maxA > maxB) ? maxA : maxB; #endregion //LogsManager.ins.AddLog("Trwa wypisywanie wartości dla gracza, który posiada dokładnie dwie strategie."); yield return(Game.Wait()); WriteValues(min, max); yield return(WriteLines(strategyA, strategyB)); }
public override void Draw(SpriteBatch spriteBatch) { ++_drawCounter; _drawCounter %= _blinkInterval; for (int y = 0; y < _map.GetLength(0); ++y) { for (int x = 0; x < _map.GetLength(1); ++x) { if ((_map[y, x] < 13 && _map[y, x] >= 0) || (_map[y, x] == 13 && 2 * _drawCounter / _blinkInterval == 0)) { Vector2 pos = new Vector2(x, y) * _spriteSize; pos.Y += _offset; Rectangle clipping = new Rectangle( (int)(_spriteSize.X * _map[y, x]), 0, (int)_spriteSize.X, (int)_spriteSize.Y); spriteBatch.Draw(Texture, pos, clipping, Color.White); } } } if (_fruit != Food.NONE) { //TODO: Sprite size is different for fruits... We should avoid to hardcode its value :/ Rectangle clipping = new Rectangle( (int)(28 * _fruitTextureOffset), 0, (int)28, (int)28); spriteBatch.Draw(_fruitsTexture[_textureIndex], _fruitPos - new Vector2(28, 28) / 2, clipping, Color.White); } }
private Node[,] buildNodes(int iWidth, int iHeight, sbyte[,] iMatrix) { Node[,] tNodes = new Node[iWidth, iHeight]; for (int widthTrav = 0; widthTrav < iWidth; widthTrav++) { for (int heightTrav = 0; heightTrav < iHeight; heightTrav++) { tNodes[widthTrav, heightTrav] = new Node(widthTrav, heightTrav, null); } } if (iMatrix == null) { return(tNodes); } if (iWidth != iMatrix.GetLength(0) || iHeight != iMatrix.GetLength(1)) { throw new ArgumentException("width or height is to match matrix width or height"); } for (int widthTrav = 0; widthTrav < iWidth; widthTrav++) { for (int heightTrav = 0; heightTrav < iHeight; heightTrav++) { tNodes[widthTrav, heightTrav].value = iMatrix[widthTrav, heightTrav]; } } return(tNodes); }
void Start() { #if UNITY_EDITOR CSV_Reader __csvReader = GameObject.FindGameObjectWithTag("Ground colliders").GetComponent <CSV_Reader>(); sbyte[,] __csvMap = __csvReader._GetValues(); _middle.x = __csvMap.GetLength(1); _middle.y = __csvMap.GetLength(0); #else _middle.x = CSV_Reader._csv_Reader._csvMap.GetLength(1); _middle.y = CSV_Reader._csv_Reader._csvMap.GetLength(0); #endif _middle.x = _middle.x / 2; _middle.y = -(_middle.y / 2); if (Application.isPlaying) { _CalculateScales(); _CreateLayersTrans(); _AddMarginToParSectAreas(); } else { #if UNITY_EDITOR _parallaxScales.RemoveRange(0, _parallaxScales.Count); for (int id = 0; id < _backgrounds.Count; id++) { _parallaxScales.Add(_backgrounds[id].transform.position.z / _limit); } #endif } }
public void CreateEquatorPermutationMoveTableTest() { sbyte[,] equatorPermutationMoveTable = MoveTables.CreateEquatorOrderMoveTable(); Assert.IsNotNull(equatorPermutationMoveTable); Assert.AreEqual(equatorPermutationMoveTable.GetLength(0), Coordinates.NumEquatorOrders); Assert.AreEqual(equatorPermutationMoveTable.GetLength(1), Constants.NumMoves); }
public void SetPath(sbyte[,] m) { path = new sbyte[m.GetLength(1)]; // Highest path length int pc = r.Next(0, m.GetLength(0)); // Path count for (int i = 0; i < m.GetLength(1); i++) { path[i] = m[pc, i]; } }
public void Haar2DByteForward(ref sbyte[,] Z, byte loss, byte rvalue) { int nX = Z.GetLength(0); int nY = Z.GetLength(1); double[,] dZ = new double[nX, nY]; int i, j; // Transform Rows - nX for (j = 0; j < nY; j++) { List <double> zRow = new List <double>(); for (i = 0; i < nX; i++) { zRow.Add(Z[i, j]); } zRow = DirectTransform(zRow, loss, rvalue); //for each rows for (i = 0; i < nX; i++) { dZ[i, j] = (int)zRow[i]; } } // Transform Columns - nY //double zMax = 0.0; //double zMin = 0.0; for (i = 0; i < nX; i++) { List <double> zCol = new List <double>(); for (j = 0; j < nY; j++) { zCol.Add(dZ[i, j]); } zCol = DirectTransform(zCol, loss, rvalue);; //for each columns for (j = 0; j < nY; j++) { if (zCol[j] > 127) { zCol[j] = 127; } if (zCol[j] < -127) { zCol[j] = -127; } Z[i, j] = (sbyte)zCol[j]; } } }
//encode and decode private List <byte> encoding(sbyte[,] arr) { List <byte> tmp = new List <byte>(); for (int i = 0; i < arr.GetLength(1); i += BLOCK_HEIGHT) { for (int j = 0; j < arr.GetLength(0); j += BLOCK_WIDTH) { sbyte prev = arr[j + patternList[0, 0], i + patternList[0, 1]]; byte count = 1; for (int k = 1; k < patternList.GetLength(0); ++k) { if (prev == arr[j + patternList[k, 0], i + patternList[k, 1]]) { ++count; } else if (count >= 3 || prev == 0) { tmp.Add((byte)0); tmp.Add(count); tmp.Add((byte)prev); count = 1; } else { for (int l = 0; l < count; ++l) { tmp.Add((byte)prev); } count = 1; } prev = arr[j + patternList[k, 0], i + patternList[k, 1]]; } if (count >= 3 || prev == 0) { tmp.Add((byte)0); tmp.Add(count); tmp.Add((byte)prev); count = 1; } else { for (int l = 0; l < count; ++l) { tmp.Add((byte)prev); } count = 1; } } } return(tmp); }
//compression public Bitmap convertIntraFrame(Bitmap bit) { intraFrame = new Bitmap(bit.Width, bit.Height); width = intraFrame.Width; height = intraFrame.Height; Y = new byte[width, height]; Cb = new byte[width, height]; Cr = new byte[width, height]; RGBtoYCbCr(bit, Y, Cb, Cr); subSampling(ref Cb, ref Cr); YDCT = new double[width, height]; CbDCT = new double[Cb.GetLength(0), Cb.GetLength(1)]; CrDCT = new double[Cr.GetLength(0), Cr.GetLength(1)]; YQuant = new sbyte[width, height]; CbQuant = new sbyte[Cb.GetLength(0), Cb.GetLength(1)]; CrQuant = new sbyte[Cr.GetLength(0), Cr.GetLength(1)]; YEncode = new List <byte>(); CbEncode = new List <byte>(); CrEncode = new List <byte>(); YDCT = DCT(Y); CbDCT = DCT(Cb); CrDCT = DCT(Cr); YQuant = quantization(YDCT); CbQuant = quantization(CbDCT); CrQuant = quantization(CrDCT); YEncode = encoding(YQuant); CbEncode = encoding(CbQuant); CrEncode = encoding(CrQuant); YQuant = decoding(YEncode, YQuant.GetLength(0), YQuant.GetLength(1)); CbQuant = decoding(CbEncode, CbQuant.GetLength(0), CbQuant.GetLength(1)); CrQuant = decoding(CrEncode, CrQuant.GetLength(0), CrQuant.GetLength(1)); YDCT = invQuantization(YQuant); CbDCT = invQuantization(CbQuant); CrDCT = invQuantization(CrQuant); Y = inverseDCT(YDCT, width, height); Cb = inverseDCT(CbDCT, Cb.GetLength(0), Cb.GetLength(1)); Cr = inverseDCT(CrDCT, Cr.GetLength(0), Cr.GetLength(1)); unsubSampling(ref Cb, ref Cr); YCbCrtoRGB(intraFrame, Y, Cb, Cr); return(intraFrame); }
public override void Update() { //隨機高度 do { isEnd = true; for (int x = 0; x < terrainData.GetLength(0); x++) { for (int y = 0; y < terrainData.GetLength(1); y++) { if (terrainData[x, y] != -1) { FindGeneratePoint(x, y); } else { isEnd = false; } } } } while (!isEnd); //處理被環繞的地形 for (int x = 0; x < terrainData.GetLength(0); x++) { for (int y = 0; y < terrainData.GetLength(1); y++) { if (terrainData[x, y] < 10) { FillSerround(x, y); } } } generaterManager.AddTicks(); /*Debug.Log(string.Format($"Basic terrain generate at ({target.Column},{target.Row}):" + * $"{Time.time - generaterManager.ScaleStartTime} secends, Total " + * $"{Time.time - generaterManager.StartTime} secends")); * generaterManager.ScaleStartTime = Time.time;*/ if (generateTargets.Count > 0) { target = generateTargets.Dequeue(); generaterManager.SetNextGenerater(new BassTerrainGenerater(generaterManager)); } else { generaterManager.SetNextGenerater(new MapPrintingInitail(generaterManager)); } }
public void CDF2DForward(ref sbyte[,] Z, int loss, int rvalue) { int nX = Z.GetLength(0); int nY = Z.GetLength(1); int i, j; // Transform Rows - nX for (j = 0; j < nY; j++) { List <double> zRow = new List <double>(); for (i = 0; i < nX; i++) { zRow.Add(Z[i, j]); } zRow = fwt97(zRow, loss, rvalue); //for each rows for (i = 0; i < nX; i++) { Z[i, j] = (sbyte)(zRow[i] / 1.586134342); //1.586134342 } } // Transform Columns - nY for (i = 0; i < nX; i++) { List <double> zCol = new List <double>(); for (j = 0; j < nY; j++) { zCol.Add(Z[i, j]); } zCol = fwt97(zCol, loss, rvalue); //for each columns for (j = 0; j < nY; j++) { Z[i, j] = (sbyte)(zCol[j] / 1.586134342); if (Z[i, j] > 127) { Z[i, j] = 127; } if (Z[i, j] < -127) { Z[i, j] = -127; } } } }
public void CDF2DInverse(ref sbyte[,] Z, int vD, int hD) { int nX = Z.GetLength(0); int nY = Z.GetLength(1); int i, j; // Transform Columns - nY for (i = 0; i < nX; i++) { List <double> zCol = new List <double>(); for (j = 0; j < nY; j++) { zCol.Add(Z[i, j]); // * 1.586134342 } zCol = inverse97(zCol, vD); //for each columns for (j = 0; j < nY; j++) { Z[i, j] = (sbyte)zCol[j]; } } // Transform Rows - nX for (j = 0; j < nY; j++) { List <double> zRow = new List <double>(); for (i = 0; i < nX; i++) { zRow.Add(Z[i, j]); //* 1.586134342 } zRow = inverse97(zRow, hD); //for each rows for (i = 0; i < nX; i++) { if (zRow[i] > 127) { zRow[i] = 127; } if (zRow[i] < -127) { zRow[i] = -127; } Z[i, j] = (sbyte)zRow[i]; } } }
public bool DoesGameFinished(sbyte[,] matrix) { _gameCapacity = matrix.GetLength(0); var diag1Sum = 0; var diag2Sum = 0; for (var i = 0; i < _gameCapacity; i++) { var rowSum = 0; var columnSum = 0; for (var j = _gameCapacity; j > 0; j--) { rowSum += matrix[i, _gameCapacity - j]; columnSum += matrix[_gameCapacity - j, i]; } diag1Sum += matrix[i, i]; diag2Sum += matrix[i, _gameCapacity - 1 - i]; if (!checkLine(rowSum) && !checkLine(columnSum)) { continue; } return(true); } return(checkLine(diag1Sum) || checkLine(diag2Sum)); }
public uint Checksum() { if (checksumVersion != version) { cachedChecksum = (uint)width ^ (uint)depth; for (int x = 0; x < heightMap.GetLength(0); x += 1) { for (int z = 0; z < heightMap.GetLength(1); z += 1) { cachedChecksum ^= (uint)heightMap[x, z]; } } checksumVersion = version; } return(cachedChecksum); }
public static byte[] GetBytes(sbyte[,] values) { int rows = values.GetLength(0); int cols = values.GetLength(1); byte[] buf = new byte[rows * cols * byte_size]; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { buf[c * rows + r] = (byte)values[r, c]; } } return(buf); }
static PathFinder() { EyesPosition = new Vector3(0f, 1.6f, 0f); OpenList = new PriorityQueue(MaxDepth * Direction.GetLength(0)); // 8 directions for each node Size = World.Size; Grid = new PathFindNode[Size, Size]; //Interface.Oxide.LogInfo("Queue: {0} Grid: {1} Size: {2}", OpenList.MaxSize, Grid.Length, Size); }
private double[,] invQuantization(sbyte[,] arr) { double[,] tmp = new double[arr.GetLength(0), arr.GetLength(1)]; for (int i = 0; i < arr.GetLength(1); i += BLOCK_HEIGHT) { for (int j = 0; j < arr.GetLength(0); j += BLOCK_WIDTH) { for (int w = 0; w < BLOCK_WIDTH; w++) { for (int h = 0; h < BLOCK_HEIGHT; h++) { tmp[j + w, i + h] = arr[j + w, i + h] * quantiza_matrix[w, h]; } } } } return(tmp); }
public void Haar2DInverse(ref sbyte[,] Z, int vHaar, int hHaar) { int nX = Z.GetLength(0); int nY = Z.GetLength(1); double[,] dZ = new double[nX, nY]; int i, j; // Transform Columns - nY for (i = 0; i < nX; i++) { List <double> zCol = new List <double>(); for (j = 0; j < nY; j++) { zCol.Add(Z[i, j]); } zCol = InverseTransform(zCol, vHaar);; //for each columns for (j = 0; j < nY; j++) { dZ[i, j] = (int)zCol[j]; } } // Transform Rows - nX for (j = 0; j < nY; j++) { List <double> zRow = new List <double>(); for (i = 0; i < nX; i++) { zRow.Add(dZ[i, j]); } zRow = InverseTransform(zRow, hHaar); //for each rows for (i = 0; i < nX; i++) { Z[i, j] = (sbyte)zRow[i]; } } }
public List <byte> arcRepeater(sbyte[,] btArr) { List <byte> btOut = new List <byte>(); List <sbyte> btTmp = new List <sbyte>(); int iX = btArr.GetLength(0); int iY = btArr.GetLength(1); btOut.Add((byte)(iX >> 8)); // hi byte btOut.Add((byte)(iX & 255)); // lo byte btOut.Add((byte)(iY >> 8)); // hi byte btOut.Add((byte)(iY & 255)); // lo byte for (int i = 0; i < iX; i++) { for (int j = 0; j < iY; j++) { btTmp.Add(btArr[i, j]); } } sbyte sprev = btTmp[0]; int jrep = 0; foreach (sbyte sbt in btTmp) { if (sbt == sprev) { jrep++; } else { // code prev here btOut.Add((byte)jrep); btOut.Add((byte)sprev); sprev = sbt; jrep = 1; } } return(btOut); }
public static sbyte Calculate(this sbyte[,] array) { sbyte res = 0; if (array.Length > 0) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] > 0) { res += array[i, j]; } } } } return(res); }
private string[] EscribirTableroString(sbyte[,] m) { string[] aux = new string[m.GetLength(0)]; for (sbyte i = 0; i < m.GetLength(0); i++) { for (sbyte j = 0; j < m.GetLength(1); j++) { if (Tablero[i, j] == 1) { aux[i] += "*"; } else { aux[i] += " "; } } } return(aux); }
public void Haar2DByteForward(ref sbyte[,] Z, byte loss, int vHaar, int hHaar) { int nX = Z.GetLength(0); int nY = Z.GetLength(1); double[,] dZ = new double[nX, nY]; int i, j; // Transform Rows - nX for (j = 0; j < nY; j++) { List <double> zRow = new List <double>(); for (i = 0; i < nX; i++) { zRow.Add(Z[i, j]); } zRow = DirectTransform(zRow, loss, hHaar); //for each rows for (i = 0; i < nX; i++) { dZ[i, j] = (int)zRow[i]; } } for (i = 0; i < nX; i++) { List <double> zCol = new List <double>(); for (j = 0; j < nY; j++) { zCol.Add(dZ[i, j]); } zCol = DirectTransform(zCol, loss, vHaar);; //for each columns for (j = 0; j < nY; j++) { Z[i, j] = (sbyte)zCol[j]; } } }
/// <summary> /// 导入外部地图数据 /// </summary> /// <param name="data"></param> public void ImportMapData(ref sbyte[,] data, int _offsetX = 0, int _offsetY = 0) { iOffsetX = _offsetX; iOffsetY = _offsetY; iWidth = data.GetLength(0); iHeight = data.GetLength(1); bitMap = new sbyte[iWidth, iHeight]; bitDynamic = new sbyte[iWidth, iHeight]; //值默认为0 for (int y = 0; y < iHeight; y++) { for (int x = 0; x < iWidth; x++) { bitMap[x, y] = data[x, y]; } } GMap.instance = this; }
public static int EvaluateGameScore(ColoredBoardNormalSmaller board, sbyte[,] score) { int result = 0; for (uint x = 0; x < score.GetLength(0); ++x) { for (uint y = 0; y < score.GetLength(1); ++y) { if (board[x, y]) { result += score[x, y]; } } } BadSpaceFill(ref board, (byte)score.GetLength(0), (byte)score.GetLength(1)); for (uint x = 0; x < score.GetLength(0); ++x) { for (uint y = 0; y < score.GetLength(1); ++y) { if (!board[x, y]) { result += Math.Abs(score[x, y]); } } } return(result); }
public override void Update() { for (int column = 0; column < terrainData.GetLength(0); column++) { for (int row = 0; row < terrainData.GetLength(1); row++) { if (terrainData[column, row] < 10) { mapPrinter.PrintGameMapGround(target.Column * 15 + column, target.Row * 15 + row, mapBuilder.GetBlockType(target) == BlockType.Safe); } //else if (HasGroundBehind(column, row)) else { mapPrinter.PrintGameMapWall(target.Column * 15 + column, target.Row * 15 + row); } } } generaterManager.AddTicks(); generaterManager.SetNextGenerater(new MiniMapPresenter(generaterManager)); }
static void CopiarFigura(sbyte[,] figura, sbyte y, sbyte x) { sbyte fila, columna; sbyte ancho_fig = (sbyte)figura.GetLength(1); sbyte alto_fig = (sbyte)figura.GetLength(0); sbyte posx, posy; x = (sbyte)(x - (ancho_fig / 2)); y = (sbyte)(y - (alto_fig / 2)); for (fila = 0; fila < alto_fig; fila++) { for (columna = 0; columna < ancho_fig; columna++) { posy = (sbyte)(y + fila); posx = (sbyte)(x + columna); if ((posy >= 0) && (posy < Tablero.GetLength(1)) && (posx >= 0) && (posx < Tablero.GetLength(1))) { Tablero[posy, posx] = figura[fila, columna]; } } } }
public static byte[,] DefineEdges(byte[,] binaryArray, sbyte[,] maskX, sbyte[,] maskY) { int maskLengthAxisX = maskX.GetLength(0); int maskLengthAxisY = maskX.GetLength(1); int byteStepsAxisX = binaryArray.GetLength(0) - maskLengthAxisX; int byteStepsAxisY = binaryArray.GetLength(1) - maskLengthAxisY; var analizedField = new byte[byteStepsAxisX, byteStepsAxisY]; // Image traversal for (int x = 0; x < byteStepsAxisX; x++) { for (int y = 0; y < byteStepsAxisY; y++) { double colorX = 0; double colorY = 0; for (int mx = 0; mx < maskLengthAxisX; mx++) { for (int my = 0; my < maskLengthAxisY; my++) { colorX += binaryArray[x + mx, y + my] * maskX[mx, my]; colorY += binaryArray[x + mx, y + my] * maskY[mx, my]; } } double totalColor = Math.Sqrt(Math.Pow(colorX, 2) + Math.Pow(colorY, 2)); analizedField[x, y] = totalColor.StabelizeColorChanel(); } } return(analizedField); }
private void FindNeighbours(Cell cell, int coordX, int coordY) { sbyte[] direction; for (int i = 0; i < Directions.GetLength(0); i++) { direction = new sbyte[] { Directions[i, 0], Directions[i, 1] }; int lookingX = coordX + direction[0]; int lookingY = coordY + direction[1]; if (lookingX >= 0 && lookingX < Cells.GetLength(0) && lookingY >= 0 && lookingY < Cells.GetLength(1)) { cell.AddNeighbour(Cells[lookingX, lookingY]); } } }