/// <summary> /// Создает новый граф из файла. /// </summary> /// <param name="FileName">Путь к файлу</param> /// <returns>Возвращает граф, загруженный из файла</returns> public static void LoadFromFile(ref Graph g, String FileName) { String[] lines = File.ReadAllLines(FileName); Int32 cursor = 0; Int32[,] Matr = new Int32[Convert.ToInt32(lines[cursor]), Convert.ToInt32(lines[cursor])]; cursor++; cursor += Matr.GetLength(0); for (int i = 0; i < Matr.GetLength(0); i++) { for (int j = 0; j < Matr.GetLength(1); j++) { Matr[i, j] = Convert.ToInt32(lines[cursor]); cursor++; } } cursor = 1; g.GraphFromMatrix(Matr); foreach (Vertex v in g.Simple()) { v.Value = lines[cursor]; cursor++; } }
/// <summary> /// Вернёт байты готового тестового сетерео файла длинной в 1 секунду, с частотой дискретизации 44.1 кГц и 32 битным значением звука который вы можете воспроизвести. /// Если не вылетит в ошибку - библиотека работает :) /// </summary> /// <returns></returns> public Byte[] GetTestWAVData() { Int32[,] sound = new Int32[44100, 2]; Random ran = new Random(); for (Int32 i = 0; i < sound.GetLength(0); i++) { sound[i, 0] = (Int32)(Math.Sin(i * 0.1f * (i / 1000f)) * (Int32.MaxValue * 0.05f)); } for (Int32 i = 0; i < sound.GetLength(0); i++) { sound[i, 1] = (Int32)(Math.Sin(i * 0.1f * Math.Abs(Math.Cos(i / 10000f))) * (Int32.MaxValue * 1f)); } WAVElib wlib = new WAVElib(); wlib.SampleRate = 44100; wlib.BitsPerSample = 32; wlib.Sound = sound; Byte[] res = wlib.GetWAVData(); wlib.Dispose(); return(res); }
/// <summary> /// /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="foundation">Existing elements of the same type as the proposed locations</param> /// <param name="closed">Points that are invalid for placement but do not count as foundation points</param> /// <param name="proposed">List of points where new items are trying to be added.</param> /// <returns></returns> public static Boolean AreValidPlots(Int32 width, Int32 height, List <Point> foundation, List <Point> closed, List <Point> proposed) { highestAssigned = 0; grid = new Int32[width, height]; if (foundation != null && foundation.Count() > 0) { highestAssigned++; foreach (var p in foundation) { grid[p.X, p.Y] = highestAssigned; } } foreach (var p in closed) { grid[p.X, p.Y] = -1; } foreach (var p in proposed) { if (p.X >= width || p.Y >= height || p.X < 0 || p.Y < 0) { return(false); } // If anything exists at the target location // the placement is invalid if (grid[p.X, p.Y] != 0) { return(false); } PlaceNew(p); } for (var x = 0; x < grid.GetLength(0); x++) { for (var y = 0; y < grid.GetLength(1); y++) { if (grid[x, y] > 1) { return(false); } } } return(true); }
/// <summary> /// Принимает массив массивов типа Int32[] - каналов и склеивает их в один. /// Длинна всех каналов должна быть одинаковой! /// </summary> /// <returns></returns> public Int32[,] MakeSound(Object[] channels) { Int32[,] sound = new Int32[((Int32[])channels[0]).Length, channels.Length]; for (Int32 ch = 0; ch < channels.Length; ch++) { for (Int32 i = 0; i < sound.GetLength(0); i++) { sound[i, ch] = ((Int32[])channels[ch])[i]; } } return(sound); }
public void Test1() { var points = new Dictionary <int, Point> { { 0, new Point(1, 1) }, { 1, new Point(1, 6) }, { 2, new Point(8, 3) }, { 3, new Point(3, 4) }, { 4, new Point(5, 5) }, { 5, new Point(8, 9) }, }; var result = Functions.GetBound(points); var expected = new Int32[, ] { { 0, 0, 0, 0, -1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, -1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 3, 3, -1, 1, 1, 1, 1 }, { 0, 0, 3, 3, 3, 3, -1, -1, -1, -1 }, { 0, 0, 3, 3, 3, 4, 4, 4, 4, 5 }, { -1, -1, 4, 4, 4, 4, 4, 4, 4, 5 }, { 2, 2, 2, 2, 4, 4, 4, 4, 5, 5 }, { 2, 2, 2, 2, 2, 4, 4, 5, 5, 5 }, { 2, 2, 2, 2, 2, 2, -1, 5, 5, 5 } }; Assert.AreEqual(expected.GetLength(0), result.GetLength(0)); Assert.AreEqual(expected.GetLength(1), result.GetLength(1)); for (int i = 0; i < expected.GetLength(0); i++) { for (int j = 0; j < expected.GetLength(1); j++) { Assert.AreEqual(expected[i, j], result[i, j]); } } }
public void EqualsTest() { var data = new Int32[, ] { { 0, 0 }, { -1, -1 }, { 1, 1 } }; var length = data.GetLength(0); for (var i = 0; i < length; i++) { InteropInt32 interopInt32 = data[i, 0]; InteropInt32 interopInt322 = data[i, 1]; Assert.IsTrue(interopInt32.Equals(interopInt322)); } }
public BaseTextureAtlas(BaseDevice device, Int32 maxTextures, Int32 width, Int32 height) { Device = device; MaxTextures = maxTextures; Width = width; Height = height; Textures = new BaseTexture[MaxTextures]; Allocated = new Int32[MaxTextures][]; //[MAX_SCRAPS][BLOCK_WIDTH]; for (var i = 0; i < Allocated.GetLength(0); i++) { Allocated[i] = new Int32[Width]; } Texels = new Byte[MaxTextures][]; // [MAX_SCRAPS][BLOCK_WIDTH*BLOCK_HEIGHT*4]; for (var i = 0; i < Texels.GetLength(0); i++) { Texels[i] = new Byte[Width * Height * 4]; } }
public Boolean runTest() { Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; String strBaseLoc; short[] in2Arr = new Int16[10]; int[] in4Arr = new Int32[5]; long[] in8Arr = new Int64[0]; String[] strArr = new String[6]; Boolean[] boArr = new Boolean[3]; Double[] dblArr = new Double[2]; Single[] snglArr = new Single[32000]; Char[] chArr = new Char[10000]; int rank; try { LABEL_860_GENERAL: do { strLoc = "Loc_819yt"; rank = -1; in2Arr = new Int16[5]; iCountTestcases++; try { in2Arr.GetLength(rank); iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_499ws! , GetLength==" + in2Arr.Length); } catch (IndexOutOfRangeException ioorExc) {} catch (Exception exc) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_758! exc==" + exc); } strLoc = "Loc_819ee"; rank = 1; in2Arr = new Int16[5]; iCountTestcases++; try { in2Arr.GetLength(rank); iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_500ws! , GetLength==" + in2Arr.Length); } catch (IndexOutOfRangeException ioorExc) {} catch (Exception exc) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_750! exc==" + exc); } strLoc = "Loc_482wu"; rank = 0; in2Arr = new Int16[10]; iCountTestcases++; if (in2Arr.GetLength(rank) != 10) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_481ua! , GetLength==" + in2Arr.Length); } strLoc = "Loc_471ay"; in4Arr = new Int32[5]; iCountTestcases++; if (in4Arr.GetLength(rank) != 5) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_29qaq! , GetLength==" + in4Arr.Length); } strLoc = "Loc_982uq"; in8Arr = new Int64[0]; iCountTestcases++; if (in8Arr.GetLength(rank) != 0) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_237sy! , GetLength==" + in8Arr.Length); } strLoc = "Loc_172ms"; boArr = new Boolean[3]; iCountTestcases++; if (boArr.GetLength(rank) != 3) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_382! , GetLength==" + boArr.Length); } strLoc = "Loc_49su"; dblArr = new Double[2]; iCountTestcases++; if (dblArr.GetLength(rank) != 2) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_200su! , GetLength==" + dblArr.Length); } strLoc = "Loc_371su"; snglArr = new Single[32000]; iCountTestcases++; if (snglArr.GetLength(rank) != 32000) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_319aw! , GetLength==" + snglArr.Length); } strLoc = "Loc_129wi"; strArr = new String[5]; strArr[2] = null; iCountTestcases++; if (strArr.GetLength(rank) != 5) { iCountErrors++; Console.WriteLine(s_strTFAbbrev + "Err_71ahw! , GetLength==" + strArr.Length); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==" + exc_general); } if (iCountErrors == 0) { return(true); } else { return(false); } }
static void Main(string[] args) { int[,] ladder = new Int32[, ] { { 1, 38 }, { 4, 14 }, { 9, 31 }, { 21, 42 }, { 28, 84 }, { 51, 67 }, { 71, 91 }, { 80, 100 } }; int[,] snake = new Int32[, ] { { 17, 7 }, { 54, 34 }, { 62, 19 }, { 64, 60 }, { 87, 24 }, { 93, 73 }, { 95, 75 }, { 98, 79 } }; int i = 0; int j = 0; int your_turn; Console.WriteLine("Ïnput -> How many players in games:\t"); int user_no = Convert.ToInt16(Console.ReadLine()); int[,] user_array = new int[user_no, 2]; //how many users will be involved in snake gme // store users into array for (i = 0; i < user_no; i++) { for (j = 0; j < 2; j++) { if (j == 0) { user_array[i, j] = i + 1; } else { user_array[i, j] = 0; } //Console.WriteLine(user_array[i,j]); } } int goal = 0; while (goal < 100) // winner stage { for (i = 0; i < user_no; i++) // need to make one by one { if (user_array[i, 1] >= 100) // get user step from array to check goal or not { goal = 100; break; // Reached point } else // if not reach goal, go on { int turn = 0; // we need to go one by on. Don't make two twice. while (turn != i + 1) // we need to go one by on. Don't make two twice. { Console.Write("\nEnter Your turn:\t"); your_turn = Convert.ToInt16(Console.ReadLine());// now. who is turn? if (your_turn == i + 1) { Random rnd = new Random(); // declare random number int rnd_no = rnd.Next(1, 6); // get one random number Console.WriteLine("Your existing step is " + user_array[i, 1] + "\n"); user_array[i, 1] += rnd_no; turn = i + 1; // 1; end while; let's go to for loop for (int a = 0; a < ladder.GetLength(0); a++) { if (ladder[a, 0] == user_array[i, 1]) { // Console.WriteLine("Random number is " + rnd_no+"\nCongrat!!!!! You get a ladder: "+ladder[a,1]); Console.WriteLine("\nCongrat!!!!! You get a ladder: " + ladder[a, 1]); user_array[i, 1] = ladder[a, 1]; // Console.WriteLine("You reached here: " + user_array[i,1]); } if (snake[a, 0] == user_array[i, 1]) { // Console.WriteLine("Random number is " + rnd_no + "\nYou get a snake: " + snake[a, 1]); Console.WriteLine("\nYou get a snake: " + snake[a, 1]); user_array[i, 1] = snake[a, 1]; // Console.WriteLine("You reached here: " + user_array[i, 1]); } } if (user_array[i, 1] > 100) { int value = user_array[i, 1] - 100; int value1 = 100 - value; user_array[i, 1] = value1; Console.WriteLine("Because of Random number is " + rnd_no + "\nPlayer: " + (i + 1) + " *******Now Your Step is " + user_array[i, 1] + "\n"); // show user your step } else if (user_array[i, 1] == 100) // for check to get goal { goal = 100; // show user your step Console.WriteLine("Because of Random number is " + rnd_no + "\nPlayer: " + (i + 1) + " *** Now Your Step is " + user_array[i, 1] + "\n"); i = user_no + user_no; // for break while and for turn = i + 1; // for break while and for break; } else { Console.WriteLine("Because of Random number is " + rnd_no + "\nPlayer: " + (i + 1) + " *** Now Your Step is " + user_array[i, 1] + "\n"); // show user your step } break; } else { Console.WriteLine("\nSo Sorry!\nIt is not your turn:Now Player No: " + (i + 1) + " turn!!!"); turn = your_turn; // let go while loop coz not your turn!!!! Try again! } }//end while } //end else } //end for Console.WriteLine("________________________________________________________"); } //end while if (goal == 10) { for (i = 0; i < user_no; i++) { j = 1; Console.WriteLine("\n\n" + user_array[i, j]); } } }
public static void Main(params String[] arguments) { const Int32 squareDimension = 6; const Int32 hourglassSquareDimension = 3; // Just for the sake of clarity, think about the center // And the number just above =] // const Int32 hourglassCenterMiddleOffset = 1; var a = new Int32[squareDimension, squareDimension]; // 2 { 0, 1 } // var dimensions = a.Rank; // Silly but comprehensive var rowCount = a.GetLength(0); var columnCount = a.GetLength(1); for (var i = 0; i < squareDimension; i++) { var aRowStringTokens = Console.ReadLine().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var aRow = Array.ConvertAll(aRowStringTokens, Int32.Parse); for (var j = 0; j < aRow.Length; j++) { a[i, j] = aRow[j]; } } // Array Example: // a = new Int32[squareDimension , squareDimension] // { // { 1, 1, 1, 0, 0, 0 }, // { 0, 1, 0, 0, 0, 0 }, // { 1, 1, 1, 0, 0, 0 }, // { 0, 0, 2, 4, 4, 0 }, // { 0, 0, 0, 2, 0, 0 }, // { 0, 0, 1, 2, 4, 0 }, // } ; // // Hourglass Pattern: // *** // * // *** // The overlapping effect... var rowHourglassCount = rowCount - hourglassSquareDimension + 1; var columnHourglassCount = columnCount - hourglassSquareDimension + 1; // Maximum value initialized to the minimum var maxSum = Int32.MinValue; // In this particular case only 16 cases to check for (var i = 0; i < rowHourglassCount; i++) { for (var j = 0; j < columnHourglassCount; j++) { // var topLeft = a[i, j]; // var topCenter = a[i, j + 1]; // var topRight = a[i, j + 2]; // var middleCenter = a[i + 1, j + 1]; // var bottomLeft = a[i + 2, j]; // var bottomCenter = a[i + 2, j + 1]; // var bottomRight = a[i + 2, j + 2]; // Sum all the hourglass slots... var currentSum = (a[i, j] + a[i, j + 1] + a[i, j + 2] + a[i + 1, j + 1] + a[i + 2, j] + a[i + 2, j + 1] + a[i + 2, j + 2]); // Compare current sum with maximum sum // Replace maximum if current sum is greater than maximum sum... if (currentSum > maxSum) { maxSum = currentSum; } } } // Display something if we have to something to show... if (maxSum > Int32.MinValue) { Console.WriteLine(maxSum); } }