/// <summary> /// To join the current instance of Record collection to another instance /// </summary> /// <param name="target">Target array you wish to combine with the source</param> public void JoinArrays(RecordCollection target) { //loops through each record in the target and adds it to the current records. for (int i = 0; i < target.Records.currentCapacity; i++) { Records.AddRecord(target.Records[i]); } SortAlgorithms.HeapSort(this, c => c.Timestamp); }
void DebugControlPoll() { // Player: B, F, I. if (Input.GetKeyDown(KeyCode.B)) { player.BoostMaxPower(0.025f); // 2.5% boost } if (Input.GetKeyDown(KeyCode.F)) { player.TopFuel(); } if (Input.GetKeyDown(KeyCode.I)) { player.Invulnerable(); } // PickupTracker: U, Y. if (Input.GetKeyDown(KeyCode.U)) { pickupTracker.TriggerSpawn(); } if (Input.GetKeyDown(KeyCode.Y)) { pickupTracker.DespawnAll(); } // FishPool: J, K, L. if (Input.GetKeyDown(KeyCode.K)) { fishPool.ReclaimAllFish(); } if (Input.GetKeyDown(KeyCode.L)) { fishPool.Respawn(); } if (Input.GetKeyDown(KeyCode.J)) { fishPool.PartialSpawn(); } // Records: Z. if (Input.GetKeyDown(KeyCode.Z)) { records.AddRecord(Random.Range(0.9f, 11f)); } }
public void Cease(int count) { endTime = Time.time; elapsed = (Mathf.FloorToInt((endTime - startTime) * 10)) / 10f; // Get 1 decimal place. finished = true; float ratio = (elapsed / count) * 100f; int boardScore = 5000 - Mathf.FloorToInt(ratio); if (boardScore < 0) { boardScore = 1; } Debug.Log("New score: " + boardScore); ratio = Mathf.FloorToInt(ratio) / 100f; // Get 2 decimal places. string customName = pilot.ID + Splitter + pilot.Unique; if (Application.platform != RuntimePlatform.WebGLPlayer) { leaderboard.AddScore(customName, boardScore, Mathf.FloorToInt(ratio * 100), pilot.Unique); } records.AddRecord(ratio); records.Parse(); }
/// <summary> /// Initializes the ArrayList from the I/O files, does so by reading selected region files into string[] dictionary, /// then loops through each file name string key, access string[] value by row index and set the temp record through setter dictionary /// once looped though each file, the temp record is fully initialized, so it's added to the array /// </summary> /// <param name="dataSet">Allows user to choose which region to initialize</param> public void InitializeCollections(int dataSet) { /* a look up dictionary for the initializer * Key is the parsed variable from the txt file, Action is a simple delegate which takes 2 arguments; * SesmicRecord and String to perform property assignment operation */ var setters = new Dictionary <string, Action <SeismicRecord, string> > { /*using lambda expressions to assign values to keys. * in parenthesis i call for anonymoius lambda operator (type SesmicRecord) with a value argument */ ["Year"] = (record, value) => record.Year = int.Parse(value), //in this half It initialize the corresponding field of the anonymous property ["Month"] = (record, value) => { //Parses month strings to their integer equivalent into first array sloth for month to sort of give integer weight for the associated string record.Month[0] = DateTime.ParseExact(value.TrimEnd(' '), "MMMM", CultureInfo.InvariantCulture) .Month.ToString(); //trimmed the end spaces, otherwise it won't recognize it's a month record.Month[1] = value.TrimEnd(' ').ToUpper(); //sets the string equivalent to the month }, ["Day"] = (record, value) => record.Day = int.Parse(value), ["Time"] = (record, value) => record.Time = DateTime.ParseExact(value, "HH:mm:ss", CultureInfo.InvariantCulture).TimeOfDay, ["Magnitude"] = (record, value) => record.Magnitude = double.Parse(value), ["Latitude"] = (record, value) => record.Latitude = double.Parse(value), ["Longitude"] = (record, value) => record.Longitude = double.Parse(value), ["Depth"] = (record, value) => record.Depth = double.Parse(value), ["Region"] = (record, value) => record.Region = value, ["IRIS_ID"] = (record, value) => record.Iris_id = int.Parse(value), ["Timestamp"] = (record, value) => record.Timestamp = int.Parse(value), //conversion of values is necessary as the stream reads everything as a string. }; DirectoryInfo dataColumns = new DirectoryInfo(@"SesmicData\"); FileInfo[] Files = dataColumns.GetFiles($"*{dataSet}.txt"); Console.WriteLine($"Initializing region {dataSet}\n"); Dictionary <string, string[]> lines = new Dictionary <string, string[]>(); /*reading files is a very slow operation, so it's best to read all the text from the file and put it in an array * the string array can later be indexed by row to create a record which will be added to an array */ foreach (FileInfo file in Files) { lines.Add(file.Name, File.ReadAllLines(file.FullName)); } int row = 0; /*the condition compares current row with the overall length of string array entries * array is quadratic, so it's safe to assume all the files will have same (n) entries*/ while (row < lines[$"Day_{dataSet}.txt"].Length) { //temprory record to store values from string arrays SeismicRecord temp = new SeismicRecord(); //looping through each key in the dictionary foreach (KeyValuePair <string, string[]> file in lines) { /* retrieves the file name index (in this case it's to get the length) at a point _1 or _2 is deteccted * Day_1 will return pos. 3 (the pos. at which $"_{dataSet}" detected is at 3 */ int pos = file.Key.IndexOf($"_{dataSet}"); //delegate Action <SeismicRecord, string> fieldSetter; //if the pos -1 then indexOf couldn't retrieve the position, or if trying to retrieve the said substring from setter returns false if (pos < 0 || !setters.TryGetValue(file.Key.Substring(0, pos), out fieldSetter)) { //if either condition is true, skip this iteration continue; } else { //if the substring is retrievable initialize the temp with the value in a current indexed row fieldSetter(temp, file.Value[row]); } } /*once the foreach loop is completed, the temp will have all of its fields initialized * so the next step is to add the temp to the array and increment the index for next row*/ Records.AddRecord(temp); row++; } }