/// <summary> /// Determines if the current /// </summary> /// /// <param name="filter">color filter to match the expected text color</param> /// <param name="expectedText">hash of the expected text body</param> /// <param name="allowedPixelDifference">maximum allowed deviation from the expected hash value in pixels</param> /// <param name="filter">color filter to match the expected text color</param> /// <returns>true if the text matches the expected hash</returns> public bool DialogBodyTextMatch(double expectedText, int allowedPixelDifference) { double match = DialogBodyText(); double tolerance = (allowedPixelDifference + 0.5) * PixelSize; //use an extra half pixel to avoid rounding errors return(Numerical.WithinRange(expectedText, match, tolerance)); }
/// <summary> /// Determines if the client is logged into world 385 (F2P) or world 386 (P2P). /// Also identifies worlds 358 and 368 as bot worlds. /// Assumes that the client is logged into the game. /// </summary> /// /// <param name="readWindow">Set to true to force a new screen read</param> /// <returns>true if the client is logged into world 385 or 386</returns> protected bool LoggedIntoBotWorld(bool readWindow = false) { Screen.MakeSureWindowHasBeenRead(readWindow); Inventory.OpenLogout(); SafeWaitPlus(1000, 150); Screen.ReadWindow(); if (!Screen.WorldSwitcherIsOpen()) { ClickWorldSwitcher(); SafeWaitPlus(1500, 500); Screen.ReadWindow(); } Stopwatch watch = new Stopwatch(); watch.Start(); while (!Screen.WorldSwitcherIsOpen() && (watch.ElapsedMilliseconds < 3000) && !StopFlag) { ClickWorldSwitcher(); SafeWait(600, 200); Screen.ReadWindow(); } int left = Screen.Width - 84; int right = left + 30; int top = Screen.Height - 297; int bottom = top + 20; long colorSum = ImageProcessing.ColorSum(Vision.ScreenPiece(left, right, top, bottom)); bool freeBotWorld = Numerical.CloseEnough(120452, colorSum, 0.00001); bool memberBotWorld = Numerical.CloseEnough(121998, colorSum, 0.00001); return(memberBotWorld || freeBotWorld); }
/// <summary> /// Finds the next slot that matches a single color filter /// </summary> /// <param name="emptySlotNumber">Set to a number higher than 1 to find the second, third, etc empty slot.</param> /// <returns>The first matching inventory slot scanning left to right then top to bottom. Returns null if no match is found.</returns> public Point?FirstColorMatchingSlot(ColorFilter colorFilter, double matchStrictness = 0.1, bool safeTab = true, int emptySlotNumber = 1) { emptySlotNumber = (int)Numerical.LimitToRange(emptySlotNumber, 1, INVENTORY_CAPACITY); if (OpenInventory(safeTab)) { Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow()); } Point?inventorySlot; int slotCount = 0; for (int slot = 0; slot < INVENTORY_CAPACITY; slot++) { inventorySlot = InventoryIndexToCoordinates(slot); if (SlotMatchesColorFilter(inventorySlot.Value.X, inventorySlot.Value.Y, colorFilter, matchStrictness, false, false)) { slotCount++; if (slotCount >= emptySlotNumber) { return(inventorySlot); } } if (BotProgram.StopFlag) { return(null); } } return(null); }
/// <summary> /// Returns the cached value for the MapCell at (x, y). /// Assumes this value is actually contained in the cache /// and may have undesired behavior if not (anything from /// array bounds exceptions to just returning wrong data). /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public MapCellType Get(int x, int y) { return(cache[ Numerical.Mod(x - xMin + xStartIndex, cacheWidth), Numerical.Mod(y - yMin + yStartIndex, cacheHeight) ]); }
/// <summary> /// Waits for the furnace crafting popup to appear /// </summary> /// <returns>true if the popup is found</returns> public bool WaitForPopup(int timeout) { const int popupTitleHash = 842393; Color[,] screen; Stopwatch watch = new Stopwatch(); watch.Start(); long titleHash; int left = Left + 144; int right = Left + 344; int top = Top + 4; int bottom = Top + 23; while (watch.ElapsedMilliseconds < timeout) { if (BotProgram.StopFlag) { return(false); } screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow()); screen = ImageProcessing.ScreenPiece(screen, left, right, top, bottom); titleHash = ImageProcessing.ColorSum(screen); if (Numerical.CloseEnough(popupTitleHash, titleHash, 0.001)) { return(true); } } return(false); }
/// <summary> /// Checks a piece of the screen against an expected value for approximate equivalence /// </summary> /// <param name="image">full image of the game screen</param> /// <param name="left">left bound of the piece of the screen to check</param> /// <param name="right">right bound of the piece of the screen to check</param> /// <param name="top">top bound of the piece of the screen to check</param> /// <param name="bottom">bottom bound of the piece of the screen to check</param> /// <param name="expectedColorSum">the expected color sum of the piece of the screen</param> /// <param name="tolerance">allowed deviation of the actual value from the expected value</param> /// <returns></returns> public static bool ScreenPieceCheck(Color[,] image, int left, int right, int top, int bottom, long expectedColorSum, double tolerance) { Color[,] screenPiece = ScreenPiece(image, left, right, top, bottom); long colorSum = ColorSum(screenPiece); return(Numerical.CloseEnough(expectedColorSum, colorSum, tolerance)); }
/// <summary> /// Waits for the "Enter amount:" prompt to appear over the chat box /// </summary> /// <param name="timeout">Gives up after the max wait time has elapsed</param> /// <returns>true if the prompt appears</returns> public static bool WaitForEnterAmount(Process rsClient, int timeout) { Point screenSize = ScreenScraper.GetWindowSize(rsClient); const int asterisk = 91235; const int left = 252; const int right = 265; int top = screenSize.Y - 81; int bottom = screenSize.Y - 69; Color[,] screen; Stopwatch watch = new Stopwatch(); watch.Start(); long asteriskHash; while (watch.ElapsedMilliseconds < timeout) { if (BotProgram.StopFlag) { return(false); } screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow()); screen = ImageProcessing.ScreenPiece(screen, left, right, top, bottom); asteriskHash = ImageProcessing.ColorSum(screen); if (Numerical.CloseEnough(asterisk, asteriskHash, 0.01)) { return(true); } } return(false); }
public void HalfGaussianTest(double psuedoMean, double stdDev, bool positive) { double total = 0; double sample; for (int i = 0; i < numSamples; i++) { sample = Probability.HalfGaussian(psuedoMean, stdDev, positive); if (positive) { Assert.IsTrue(sample >= psuedoMean); } else { Assert.IsTrue(sample <= psuedoMean); } total += sample; } double average = total / ((double)numSamples); double expectedMean = Numerical.BooleanAdd(psuedoMean, stdDev * (Math.Sqrt(2) / Math.Sqrt(Math.PI)), positive); double expectedStdDev = stdDev * Math.Sqrt(1 - (2 / Math.PI)); double maxDeviation = 10 * (expectedStdDev / Math.Sqrt(numSamples)); Assert.AreEqual(expectedMean, average, maxDeviation); }
public virtual void Draw(GameTime gameTime) { spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); float maxdepth = ((squaresWideToDraw + 1) + ((squaresTallToDraw + 1) * Tile.TileWidth)) * 10; //converts pixels to steps int leftX = Numerical.intDivide(Camera.Location.X, Tile.TileStepX); int topY = Numerical.intDivide(Camera.Location.Y, Tile.TileStepY); //if the sum is now odd, we will get weird errors, so just move over a little //we will fix the inelegance with more offset if (Numerical.Mod(leftX + topY, 2) == 1) { leftX--; } int firstX = (leftX + topY) / 2 - 1; int firstY = (leftX - topY) / 2; int offsetX = Camera.Location.X - (firstX + firstY) * Tile.TileStepX; int offsetY = Camera.Location.Y - (firstX - firstY) * Tile.TileStepY; drawTileMapCells(maxdepth, firstX, firstY, offsetX, offsetY); drawInGameObjects(maxdepth, firstX, firstY, offsetX, offsetY); spriteBatch.End(); }
public void GaussianRectangleTest(int left, int right, int top, int bottom) { double totalX = 0; double totalY = 0; Point sample; for (int i = 0; i < numSamples; i++) { sample = Probability.GaussianRectangle(left, right, top, bottom); Assert.IsFalse(sample.X < left); Assert.IsFalse(sample.X > right); Assert.IsFalse(sample.Y < top); Assert.IsFalse(sample.Y > bottom); totalX += sample.X; totalY += sample.Y; } double meanX = totalX / numSamples; double meanY = totalY / numSamples; double expectedX = Numerical.Average(left, right); double expectedY = Numerical.Average(top, bottom); double maxHorizontalDispersion = 2.5 * ((right - left) / Math.Sqrt(numSamples)); double maxVerticalDispersion = 2.5 * ((bottom - top) / Math.Sqrt(numSamples)); Assert.AreEqual(expectedX, meanX, maxHorizontalDispersion); Assert.AreEqual(expectedY, meanY, maxVerticalDispersion); }
/// <summary> /// Locates a bank booth in the Seers' Village bank /// </summary> /// <param name="bankBooth"></param> /// <returns>true if a bank booth is found</returns> internal bool LocateBankBoothSeersVillage(out Blob bankBooth) { bankBooth = null; List <Blob> possibleBankBooths = Vision.LocateObjects(RGBHSBRangeFactory.BankBoothSeersVillage(), MinBankBoothSize, MaxBankBoothSize); if (possibleBankBooths == null) { return(false); } List <Blob> bankBooths = new List <Blob>(); foreach (Blob booth in possibleBankBooths) { double widthToHeight = booth.Width / (double)booth.Height; if (Numerical.WithinBounds(widthToHeight, 2.3, 3.2)) { bankBooths.Add(booth); } } if (bankBooths.Count != 9) { return(false); } bankBooths.Sort(new BlobHorizontalComparer()); bankBooths.RemoveAt(5); //remove closed bank booths bankBooths.RemoveAt(4); bankBooths.RemoveAt(2); bankBooth = Blob.ClosestBlob(Screen.Center, bankBooths); return(true); }
/// <summary> /// Responds to a given dialog body hash /// </summary> /// <param name="bodyHash">total number of text pixels in a dialog box body</param> protected bool ProcessDialog(long bodyCount) { if (Numerical.CloseEnough(16029632, bodyCount, _hashPrecision)) //"Yes<br>No" - title:"Convert the planks for 2500 coins?" { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(16029168, bodyCount, _hashPrecision)) //"Yes<br>No" - title:"Convert the planks for 6250 coins?" { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(16023580, bodyCount, _hashPrecision)) //"Yes<br>No" - title:"Convert the planks for 12500 coins?" { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(16021762, bodyCount, _hashPrecision)) //"Yes<br>No" - title:"Convert the planks for 37500 coins?" { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(15831076, bodyCount, _hashPrecision)) //"Take to sawmill: 25 x logs<br>"Something else..." { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(15801599, bodyCount, _hashPrecision)) //"Take to sawmill: 25 x Oak logs<br>"Something else..." { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(15790514, bodyCount, _hashPrecision)) //"Take to sawmill: 25 x Teak logs<br>"Something else..." { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(15741143, bodyCount, _hashPrecision)) //"Take to sawmill: 25 x Mahogany logs<br>"Something else..." { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(15774502, bodyCount, _hashPrecision)) //"Serve...<br>Go to the bank...<br>Go to the sawmill<br>Greet guests<br>You're fired" { StartSawmillTask(); } else if (Numerical.CloseEnough(15989089, bodyCount, _hashPrecision)) //"Sawmill<br>Bank<br>Never mind" { Keyboard.WriteNumber(1); } else if (Numerical.CloseEnough(15959844, bodyCount, _hashPrecision) || Numerical.CloseEnough(16167022, bodyCount, _hashPrecision)) //"Enter amount:" { Keyboard.WriteNumber(25); SafeWaitPlus(50, 25); Keyboard.Enter(); } else if (Numerical.CloseEnough(15768332, bodyCount, _hashPrecision)) //"Okay, here's 10,000 coins.<br>I'll pay you later.<br>You're fired!" { Keyboard.WriteNumber(1); } else { return(false); } return(true); //one of the conditions was met }
/// <summary> /// Saves the user-selected custom settings /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveSettings_Click(object sender, EventArgs e) { settings.FairyRing = (NatureRingsSettingsData.FairyRingOptions)FairyRingSelect.SelectedIndex; settings.GloryType = (NatureRingsSettingsData.GloryOptions)GloryTypeSelect.SelectedIndex; settings.BankChoice = (NatureRingsSettingsData.BankOptions)BankSelect.SelectedIndex; settings.NumberOfPouches = (int)Numerical.LimitToRange(PouchesSelect.SelectedIndex, 0, 4); Close(); }
public void AveragePointsTest(int ax, int ay, int bx, int by, int cx, int cy) { Point a = new Point(ax, ay); Point b = new Point(bx, by); Point average = Numerical.Average(a, b); Point expected = new Point(cx, cy); Assert.IsTrue(expected.Equals(average)); }
internal NumericalListItem(Numerical numerical) { Value = numerical.Value; if (numerical.OperatorSpecified) { ComparisonOperator = numerical.Operator; } UcumString = numerical.UcumString; Numerical = numerical; }
public void NonZeroTest(double possibleZero) { double nonZero = Numerical.NonZero(possibleZero); Assert.AreNotEqual(nonZero, 0.0); if (possibleZero == 0.0) { Assert.AreEqual(0.0, nonZero, 0.001); } }
public void CloseEnoughTest1(long[] targets, long test, double tolerance, bool close) { List <long> targetList = new List <long>(); foreach (long target in targets) { targetList.Add(target); } Assert.AreEqual(Numerical.CloseEnough(targetList, test, tolerance), close); }
public CharacteristicQuantificationNumericalWpfControl(Numerical numerical) { InitializeComponent(); _ddlComparisonOperator.ItemsSource = _availableOperators; _lblUcumString.Content = numerical.UcumString; _txtValue.Text = numerical.Value.ToString(CultureInfo.CurrentCulture); }
/// <summary> /// Determines if the absorption shield is at least 900 and therefore close to maximum /// </summary> /// <returns>true is the absorption shield has a value of 900-999 (999 is max value but 1000+ would break this method if made possible)</returns> protected bool AbsorptionShieldIsHigh() { int left = 20; int right = 31; int top = 25; int bottom = 59; double hundredsPlaceWhite = Vision.FractionalMatchPiece(RGBHSBRangeFactory.White(), left, right, top, bottom); return(Numerical.WithinRange(hundredsPlaceWhite, 0.1476, 0.0005)); //TODO determine good values for range }
public override string ToString() { if (!String.IsNullOrEmpty(this.Text)) { return(this.Text); } else { return(Numerical.ToString()); } }
/// <summary> /// Gets the start parameters specified by the user in the startup form /// </summary> /// <returns></returns> private void CollectStartParams() { CollectGeneralSettings(); if (Numerical.WithinBounds(RotationBotSelection, 0, RunParams.RotationParams.Count - 1)) { RunParams.RotationParams[RotationBotSelection] = CollectRotationSettings(); } if (Numerical.WithinBounds(PhasmatysBotSelection, 0, RunParams.PhasmatysParams.Count - 1)) { RunParams.PhasmatysParams[PhasmatysBotSelection] = CollectPhasmatysSettings(); } }
/// <summary> /// Determines if "Click here to continue is showing" /// </summary> /// <returns>true if the player can push space to continue a dialog</returns> protected bool ContinueBar() { int left = 233; int right = left + 144; int top = Screen.Height - 59; int bottom = top + 10; bool[,] continueBar = Vision.ColorFilterPiece(ContinueBarBlue, left, right, top, bottom); int textSize = ImageProcessing.MatchCount(continueBar); return(Numerical.CloseEnough(285, textSize, 0.01)); }
private TemplateTree.Numerical AimTemplateTreeNumericalFromXsdNumerical(Numerical numerical) { return(new TemplateTree.Numerical { Value = numerical.value, Operator = (ComparisonOperator)numerical.@operator, UcumString = numerical.ucumString, OperatorSpecified = numerical.operatorSpecified, DefaultAnswer = numerical.defaultAnswer, NextId = numerical.nextId, NoMoreQuestions = numerical.noMoreQuestions }); }
// Sample of how RSA works. // Note that n * n should not overflow a long // This limits x*y to about 2^15. public static void Main(string[] args) { long x = 25000; long y = 30000; long message = 37373737; long p, q, n, nPrime, e, d; for (p = x; !Numerical.IsPrime(p); p++) { ; } Console.WriteLine("p: " + p); for (q = y + 2; !Numerical.IsPrime(q); q++) { ; } Console.WriteLine("q: " + q); n = p * q; Console.WriteLine("n: " + n); nPrime = (p - 1) * (q - 1); Console.WriteLine("nPrime: " + nPrime); for (e = nPrime / 10; Numerical.Gcd(e, nPrime) != 1; e++) { ; } Console.WriteLine("e: " + e); d = Numerical.Inverse(e, nPrime); Console.WriteLine("d: " + d); Console.WriteLine("Verify inverse: " + (e * d % (nPrime))); Console.WriteLine("message: " + message); long code = Numerical.Power(message, e, n); long decode = Numerical.Power(code, d, n); Console.WriteLine("Code: " + code); Console.WriteLine("Decode: " + decode); if (message != decode) { Console.WriteLine("OOPS: "); } else { Console.WriteLine("Success!!!!"); } }
/// <summary> /// Logs in to for the selected bot on a rotation tab /// </summary> /// <param name="rotationList">rotation tab to use</param> /// <param name="botSelection">selected bot on the rotation tab</param> /// <param name="startButton">reference to the start button used for this tab</param> private void RotationLogIn(RunParamsList rotationList, int botSelection, Button startButton) { CollectStartParams(); if (rotationList == null || !Numerical.WithinBounds(botSelection, 0, RunParams.PhasmatysParams.Count - 1)) { return; } rotationList[botSelection].TaskComplete = new BotResponse(BotDone); RunningBot = new LogInToGame(rotationList[botSelection]); RunningBot.Start(); SetActiveState(startButton); UpdateTimer.Enabled = true; }
public CharacteristicQuantificationNumericalControl(Numerical numerical) { InitializeComponent(); _ddlComparisonOperator.DataSource = _availableOperators; _ddlComparisonOperator.DisplayMember = "Name"; _ddlComparisonOperator.ValueMember = "Value"; _lblUcumString.Text = numerical.UcumString; _txtValue.Mask = @"9.099999"; _txtValue.ValidatingType = typeof(double); _txtValue.Text = numerical.Value.ToString(); }
private void addRightColumn() { //set up the new right column, which replaces the old left column for (int y = 0; y < cacheHeight; y++) { cache[xStartIndex, Numerical.Mod(y + yStartIndex, cacheHeight)] = map.MakeMapCell(xMin + cacheWidth, y + yMin); } //updates the minimum xMin++; //fixes the indexing xStartIndex = Numerical.Mod(xStartIndex + 1, cacheWidth); }
private void addLeftColumn() { //allows for the next left column xMin--; //fixes the indexing xStartIndex = Numerical.Mod(xStartIndex - 1, cacheWidth); //fix the new left column for (int y = 0; y < cacheHeight; y++) { cache[xStartIndex, Numerical.Mod(y + yStartIndex, cacheHeight)] = map.MakeMapCell(xMin, y + yMin); } }
private void addTopRow() { //allows for a new top row yMin--; //fixes the indexing so that the old data is still indexed correctly yStartIndex = Numerical.Mod(yStartIndex - 1, cacheHeight); //now fix the new top row for (int x = 0; x < cacheWidth; x++) { cache[Numerical.Mod(x + xStartIndex, cacheWidth), yStartIndex] = map.MakeMapCell(x + xMin, yMin); } }
private void addBottomRow() { //set up the new bottom row, which replaces the old top row for (int x = 0; x < cacheWidth; x++) { cache[Numerical.Mod(x + xStartIndex, cacheWidth), yStartIndex] = map.MakeMapCell(x + xMin, yMin + cacheHeight); } //updates the minimum yMin++; //fixes the indexing yStartIndex = Numerical.Mod(yStartIndex + 1, cacheHeight); }