public void SceenshotCapture() { screenshot1.Capture(); Assert.IsNotNull(screenshot1.Image); Assert.AreEqual(captureWidth, screenshot1.Image.Width); Assert.AreEqual(captureHeight, screenshot1.Image.Height); }
public void NoSuchElementException() { try { driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); driver.Url = "https://jqueryui.com/resizable/"; driver.SwitchTo().Frame(0); //move inside the frame ..to perform task ..here only 1 frame IWebElement resize = driver.FindElement(By.XPath("//body/div[3]")); Thread.Sleep(2000); //Actions class Actions action = new Actions(driver); action.MoveToElement(resize).DragAndDropToOffset(resize, 100, 100); //in resizeable first move mouse to element then resize it here we give x and y both to resize Thread.Sleep(2000); } catch (NoSuchElementException exception) { Screenshot.Capture(driver, " No such Element exception"); Console.WriteLine(exception.Message); } finally { driver.Quit(); } }
public override void CollectFrame(GPUContext context, ref StagingTexture frame, RenderOptions options) { // Save the staging texture to the file var path = options.GetOutputPath(ref frame) + Extension; Screenshot.Capture(frame.Texture, path); }
public void Initialize() { screenshot = new Screenshot(100, 100, new System.Drawing.Point(0, 0)); screenshot.Capture(); frms = new frmScreenshot(screenshot); }
private void VisualizeDeployPoints() { var clockwisePoints = GameGrid.RedPoints.OrderBy(point => Math.Atan2(point.X, point.Y)).ToList(); var inflatedPoints = clockwisePoints.Select( point => new PointFT((float)(point.X + (point.X / Math.Sqrt(point.DistanceSq(new PointFT(0, 0)))) * 4), (float)(point.Y + (point.Y / Math.Sqrt(point.DistanceSq(new PointFT(0, 0)))) * 4))) .ToList(); using (Bitmap bmp = Screenshot.Capture()) { using (Graphics g = Graphics.FromImage(bmp)) { foreach (PointFT redPoint in clockwisePoints) { Visualize.RectangleT(bmp, new RectangleT((int)redPoint.X, (int)redPoint.Y, 1, 1), new Pen(Color.FromArgb(128, Color.DarkRed))); } foreach (PointFT redPoint in inflatedPoints) { Visualize.RectangleT(bmp, new RectangleT((int)redPoint.X, (int)redPoint.Y, 1, 1), new Pen(Color.FromArgb(128, Color.DarkBlue))); } } var d = DateTime.UtcNow; Screenshot.Save(bmp, $"RedLineDeploy {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } }
private void VisualizeDeployment() { using (var bmp = Screenshot.Capture()) { using (var g = Graphics.FromImage(bmp)) { // find the radius of 5 tiles var p1 = new PointFT(0f, 0f).ToScreenAbsolute(); var p2 = new PointFT(0f, 5f).ToScreenAbsolute(); var distance = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2)); Visualize.RectangleT(bmp, _border, new Pen(Color.FromArgb(128, Color.Red))); g.DrawLine(new Pen(Color.FromArgb(192, Color.Red)), _attackLine.Item1.ToScreenAbsolute(), _attackLine.Item2.ToScreenAbsolute()); //foreach (PointFT point in _tankPoints) // Visualize.RectangleT(bmp, new RectangleT((int)point.X, (int)point.Y, 1, 1), new Pen(Color.Orange)); Visualize.RectangleT(bmp, new RectangleT((int)_qwPoint.X, (int)_qwPoint.Y, 1, 1), new Pen(Color.Blue)); Visualize.RectangleT(bmp, new RectangleT((int)_core.X, (int)_core.Y, 1, 1), new Pen(Color.Purple)); g.FillEllipse(new SolidBrush(Color.FromArgb(128, Color.Gold)), _healPoint.ToScreenAbsolute().ToRectangle((int)distance, (int)distance)); g.FillEllipse(new SolidBrush(Color.FromArgb(128, Color.Magenta)), _ragePoint.ToScreenAbsolute().ToRectangle((int)distance, (int)distance)); g.FillEllipse(new SolidBrush(Color.FromArgb(128, Color.Magenta)), _queenRagePoint.ToScreenAbsolute().ToRectangle((int)distance, (int)distance)); } var d = DateTime.UtcNow; Screenshot.Save(bmp, $"Breakthrough Deploy {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } }
/// <summary> /// Tests to see whether or not we can easily reach the town hall to snipe it or not. /// </summary> /// <param name="townHall"></param> /// <returns></returns> public static bool CanSnipe(this TownHall townHall) { if (townHall != null) { Target target = townHall.GetTownHallPoints(); Log.Debug($"[Berts Agorithms] Town Hall Center Location: X:{target.Center.X} Y:{target.Center.Y}"); Log.Debug($"[Berts Agorithms] Town Hall Outer Edge Location: X:{target.Edge.X} Y:{target.Edge.Y}"); Log.Debug($"[Berts Agorithms] DistanceSq from Town Hall to closest outer red point: {target.EdgeToRedline.ToString("F1")}"); #if DEBUG //Get a screen Capture... using (Bitmap canvas = Screenshot.Capture()) { //Draw some stuff on it. Visualize.Target(canvas, Origin, 40, Color.White); Visualize.Target(canvas, target.Center, 40, Color.Orange); Visualize.Target(canvas, target.Edge, 40, Color.Red); //Save the Image to the Debug Folder... var d = DateTime.UtcNow; Screenshot.Save(canvas, $"CanSnipe TownHall {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } Log.Debug("[Berts Algorithms] Snipe Townhall Debug Image Saved!"); #endif if (target.EdgeToRedline < _townHallToRedZoneMinDistance) // means there is no wall or building between us and the OUTSIDE of the Town Hall { return(true); } } return(false); }
public void NoAlertPresentException() { driver.Url = "http://www.uitestpractice.com/Students/Switcht"; //Url of website driver.Manage().Window.Maximize(); //Maximize the windows driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); // implicit wait try { IWebElement simple = driver.FindElement(By.Id("prompt")); // prompt alert button id simple.Click(); //click on simple button Thread.Sleep(3000); driver.SwitchTo().Alert().SendKeys("amit swaraj"); //give value to prmot alert Thread.Sleep(3000); driver.SwitchTo().Alert().Accept(); //accept the alert and come out from alert Thread.Sleep(3000); } // driver.SwitchTo().Alert().Dismiss(); user for cancil and come out from alert catch (Exception exception) { Screenshot.Capture(driver, " No such Element exception"); Console.WriteLine(exception.Message); } finally { driver.Quit(); } }
public void DragAndDropTest() { test = extent.CreateTest("Create new Post").Info("Test Started"); driver.Manage().Window.Maximize(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); driver.Url = "http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html"; IWebElement source = driver.FindElement(By.XPath("//body//div[14]")); // take source postion to drop Thread.Sleep(2000); IWebElement dest = driver.FindElement(By.XPath("//div[contains(text(),'United States')]")); // drop to destination Thread.Sleep(2000); Actions action = new Actions(driver); // actions class // action.ClickAndHold(source).MoveToElement(dest).Release().Build().Perform(); // Thread.Sleep(2000); //user will click and hold source position then move to dest postion and release to that postion //Another method to drap and drop action.DragAndDrop(source, dest).Build().Perform(); Thread.Sleep(2000); String path = Screenshot.Capture(driver, "DragAndDropTest"); test.AddScreenCaptureFromPath(path); test.Log(Status.Info, "Chrome Browser Launched"); driver.Quit(); }
public void TappedCaptureScreenshot() { string filename = string.Format("{0}.png", DateTime.UtcNow.ToString("yy-MM-dd-HH-mm-ss-ff")); localPath = Screenshot.Capture(filename); isCaptured = true; label.text = "Capture as: " + localPath; }
public override IEnumerable <int> AttackRoutine() { // Bottom right side var rightBottom = new PointFT((float)GameGrid.MaxX - 2, (float)GameGrid.DeployExtents.MinY); var bottomRight = new PointFT((float)GameGrid.MinX + 8, (float)GameGrid.DeployExtents.MinY); var center = new PointFT(bottomRight.X + 0.5f * (rightBottom.X - bottomRight.X), bottomRight.Y + 0.5f * (rightBottom.Y - bottomRight.Y)); // Screenshot for 3 points for the deployment line using (var bmp = Screenshot.Capture()) { using (var g = Graphics.FromImage(bmp)) { Visualize.RectangleT(bmp, new RectangleT((int)rightBottom.X, (int)rightBottom.Y, 1, 1), new Pen(Color.Blue)); Visualize.RectangleT(bmp, new RectangleT((int)bottomRight.X, (int)bottomRight.Y, 1, 1), new Pen(Color.Blue)); Visualize.RectangleT(bmp, new RectangleT((int)center.X, (int)center.Y, 1, 1), new Pen(Color.White)); } var d = DateTime.UtcNow; Screenshot.Save(bmp, "Bottom Right {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } // Deploy troops var units = Deploy.GetTroops(); units.OrderForDeploy(); for (var i = 3; i >= 1; i--) { switch (i) { case 3: point = rightBottom; break; case 2: point = bottomRight; break; case 1: point = center; break; } foreach (var unit in units) { if (unit?.Count > 0) { foreach (var t in Deploy.AtPoint(unit, point, unit.Count / i)) { yield return(t); } } } } }
public static void SaveBasicDebugScreenShot(string algorithmName, string AttackId, string filenameSuffix) { var d = DateTime.UtcNow; var debugFileName = $"{algorithmName} {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}[{AttackId}]".GetSafeFilename(); //Get a screen Capture of all targets we found... using (Bitmap canvas = Screenshot.Capture()) { Screenshot.Save(canvas, $"{debugFileName}_{filenameSuffix}"); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); Screenshot screenshot = (Screenshot)target; if (GUILayout.Button("Screenshot")) { screenshot.Capture(); } }
private static void VisualizeTownhall() { var th = TownHall.Find(); using (var bmp = Screenshot.Capture()) { Visualize.Grid(bmp); Visualize.Axes(bmp); Visualize.RectangleT(bmp, th.Location); Screenshot.Show(bmp); } }
public void OnUpdate() { if (!_settings.EnableOutsideFlight && !IsInFlight()) { return; } _screenshot.Update(); if (_autoIntervalEnabled) { if (_autoIntervalStopwatch.Elapsed > TimeSpan.FromSeconds(_settings.AutoIntervalDelayInSeconds)) { _screenshot.Capture(_settings.SupersampleAmount, _settings.AutoHideUI, _settings.AutoHideUIDelayInMilliseconds); _autoIntervalStopwatch.Reset(); _autoIntervalStopwatch.Start(); } } if (Input.GetKeyDown(_settings.ScreenshotKey)) { Screenshot(); } if (Input.GetKeyDown(_settings.DisplayKey)) { Visible = !Visible; } if (FlightGlobals.fetch != null && FlightGlobals.ActiveVessel != null) { if (Input.GetKeyDown(KeyCode.F2)) { _mainUIEnabled = !_mainUIEnabled; } } }
/// <summary> /// Draws all our visual objects (for example beforehand added deployPoints) /// </summary> /// <param name="visuals">List of visual objects to draw</param> void VisualizeDeployment(List <VisualObject> visuals) { using (var bmp = Screenshot.Capture()) { using (var g = Graphics.FromImage(bmp)) { foreach (var visual in visuals) { visual.Draw(g); } } var d = DateTime.UtcNow; Screenshot.Save(bmp, $"BabyLoonDeploy {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}"); } }
public void NoSuchFrameException() { try { driver.Manage().Window.Maximize(); driver.Url = "http://demo.automationtesting.in/Frames.html"; //Frame Xpath IWebElement frame = driver.FindElement(By.CssSelector("#singleframe")); //here forcly enter in here driver.SwitchTo().Frame(frame); Thread.Sleep(2000); //test field under frame path IWebElement testField = driver.FindElement(By.XPath("//html//body//section//div//div//div//input")); testField.SendKeys("Hello I am Amit"); Thread.Sleep(2000); //perform other task then out out from frame driver.SwitchTo().DefaultContent();// default content -->main window Thread.Sleep(2000); //Xpath of Iframe button IWebElement IframeButton = driver.FindElement(By.XPath("//a[contains(text(),'Iframe with in an Iframe')]")); //click on Iframe IframeButton.Click(); Thread.Sleep(2000); //Second method to enter in frame i.e index wise n privious is elements wise driver.SwitchTo().Frame(1); //frame under frame enter driver.SwitchTo().Frame(1); //enter xpath of test field under frame IWebElement Iframe1 = driver.FindElement(By.XPath("//html//body//section//div//div//div//input")); Iframe1.SendKeys("Hello Swaraj"); Thread.Sleep(2000); //here quit the driver driver.Quit(); } catch (NoSuchFrameException e) { Screenshot.Capture(driver, " No such frame exception"); } finally { driver.Quit(); } }
public static void DebugBottomRightSidePoints() { using (var bmp = Screenshot.Capture()) { using (var g = Graphics.FromImage(bmp)) { var y = GameGrid.DeployExtents.MinY; var x = 18; while (x >= -15) { Visualize.RectangleT(bmp, new RectangleT(x, y, 1, 1), new Pen(Color.Blue)); x--; } } var d = DateTime.UtcNow; Screenshot.Save(bmp, $"BottomRightPoints {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } }
/// <summary> /// Takes the screenshot of the current viewport. /// </summary> public void TakeScreenshot() { // Select task SceneRenderTask target = null; if (Editor.Windows.EditWin.IsSelected) { // Use editor window target = EditWin.Viewport.Task; } else { // Use game window GameWin.FocusOrShow(); } // Fire screenshot taking Screenshot.Capture(target); }
public static void DebugBottomRightSidePoints() { using (var bmp = Screenshot.Capture()) { foreach (var g in AllPoints) { DrawPoint(bmp, Color.GreenYellow, g); } DrawPoint(bmp, Color.Red, AllInOnePushDeploy.Origin); DrawPoint(bmp, Color.Blue, AllInOnePushDeploy.FirstFunnellingPoint); DrawPoint(bmp, Color.Blue, AllInOnePushDeploy.SecondFunnellingPoint); var d = DateTime.UtcNow; Screenshot.Save(bmp, $"BottomRightPoints {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } }
public void SetDateInFacebook() { try { driver.Url = "https://www.facebook.com/"; //Url of website driver.Manage().Window.Maximize(); //Maximize the windows driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); // implicit wait //In face we use single dropdown IWebElement day = driver.FindElement(By.Id("day")); SelectElement selectElement = new SelectElement(day); //Create select element Thread.Sleep(2000); selectElement.SelectByIndex(15); // here selected elements by index Thread.Sleep(2000); IWebElement month = driver.FindElement(By.Id("month")); Thread.Sleep(2000); SelectElement selectmonth = new SelectElement(month); selectmonth.SelectByText("Sept"); Thread.Sleep(2000); IWebElement year = driver.FindElement(By.Id("year")); SelectElement selectElements = new SelectElement(year); //Create select element Thread.Sleep(2000); selectElements.SelectByText("1997"); Thread.Sleep(2000); } catch (Exception exception) { Screenshot.Capture(driver, exception.Message); Console.WriteLine(exception.Message); Email.SendMailTest.SendEmail(exception.Message.Trim(), exception.StackTrace); } finally { driver.Quit(); } }
public static void DebugSpells() { using (var bmp = Screenshot.Capture()) { using (var g = Graphics.FromImage(bmp)) { g.DrawLine(new Pen(Color.FromArgb(192, Color.Orange)), AllInOnePushDeploy.FirstHasteLine.Item1.ToScreenAbsolute(), AllInOnePushDeploy.FirstHasteLine.Item2.ToScreenAbsolute()); g.DrawLine(new Pen(Color.FromArgb(192, Color.Orange)), AllInOnePushDeploy.FirstRageLine.Item1.ToScreenAbsolute(), AllInOnePushDeploy.FirstRageLine.Item2.ToScreenAbsolute()); g.DrawLine(new Pen(Color.FromArgb(192, Color.Orange)), AllInOnePushDeploy.SecondHasteLine.Item1.ToScreenAbsolute(), AllInOnePushDeploy.SecondHasteLine.Item2.ToScreenAbsolute()); Visualize.CircleT(bmp, AllInOnePushDeploy.FirstRagePoint, 5, Color.Magenta, 64, 0); Visualize.CircleT(bmp, AllInOnePushDeploy.SecondRagePoint, 5, Color.Magenta, 64, 0); Visualize.CircleT(bmp, AllInOnePushDeploy.FirstHealPoint, 5, Color.Yellow, 64, 0); Visualize.CircleT(bmp, AllInOnePushDeploy.FirstHastePoint, 5, Color.OrangeRed, 64, 0); } var d = DateTime.UtcNow; Screenshot.Save(bmp, $"{AllInOnePushDeploy.AttackName} Spells {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } }
// Update is called once per frame void Update() { if (isInGame) { PlayMusic(); if (FirebaseManager.user != null) { TimeSpan timePlayed = DateTime.Now - timeStarted; if (timePlayed.Minutes >= 5) { GooglePlayGames.PlayGamesPlatform.Instance.ReportProgress(GPGSIds.achievement_5_minute_man, 100.0, (bool success) => { }); } } } if (Input.GetKeyDown(KeyCode.Space)) { Texture2D goodPic = Screenshot.Capture(GameObject.Find("Main Camera").GetComponent <Camera>(), 512, 512); byte[] toSave = goodPic.EncodeToJPG(); File.WriteAllBytes(Application.persistentDataPath + "/screenshot.jpg", toSave); } }
public static bool IsAirDefenseExposed(int distance = 7) { var redPoints = GameGrid.RedPoints.Where( point => !(point.X > 18 && point.Y > 18 || point.X > 18 && point.Y < -18 || point.X < -18 && point.Y > 18 || point.X < -18 && point.Y < -18)); var ADs = AirDefense.Find().Where(c => c.Location.GetCenter() .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter())) .FirstOrDefault()) <= distance); if (ADs.Count() > 2) { using (Bitmap bmp = Screenshot.Capture()) { var d = DateTime.UtcNow; Screenshot.Save(bmp, "Exposed Air Defense {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } Log.Warning("This base hase exposed air defenses, we will skip that base."); return(true); } return(false); }
public static void DebugEQpells() { using (var bmp = Screenshot.Capture()) { using (var g = Graphics.FromImage(bmp)) { Visualize.RectangleT(bmp, new RectangleT((int)AllInOnePushDeploy.FirstFunnellingPoint.X, (int)AllInOnePushDeploy.FirstFunnellingPoint.Y, 1, 1), new Pen(Color.Blue)); Visualize.RectangleT(bmp, new RectangleT((int)AllInOnePushDeploy.SecondFunnellingPoint.X, (int)AllInOnePushDeploy.SecondFunnellingPoint.Y, 1, 1), new Pen(Color.Blue)); Visualize.RectangleT(bmp, new RectangleT((int)AllInOnePushDeploy.Origin.X, (int)AllInOnePushDeploy.Origin.Y, 1, 1), new Pen(Color.Red)); //draw rectangle around the target Visualize.RectangleT(bmp, new RectangleT((int)AllInOnePushDeploy.Target.X, (int)AllInOnePushDeploy.Target.Y, 3, 3), new Pen(Color.Blue)); Visualize.CircleT(bmp, AllInOnePushDeploy.FirstJumpPoint, 3.5f, Color.DarkGreen, 100, 0); Visualize.CircleT(bmp, AllInOnePushDeploy.EqPoint, 4, Color.SandyBrown, 100, 0); } var d = DateTime.UtcNow; Screenshot.Save(bmp, $"{AllInOnePushDeploy.AttackName} EQ Spells {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } }
public override IEnumerable <int> AttackRoutine() { Log.Debug("[Snipe Deploy] Getting the best townhall deploy point."); var snipePoint = new Container <PointFT> { Item = GetTownHallDeployPoint() }; Log.Debug($"[Snipe Deploy] Deploy point is ({snipePoint.Item})"); var troops = Deploy.GetTroops(); var hero = troops.GetQueen() ?? troops.GetKing() ?? troops.GetWarden(); if (hero != null) { Log.Info("[Snipe Deploy] Deploying the " + hero.PrettyName + " to snipe."); foreach (var t in Deploy.AtPoint(hero, snipePoint)) { yield return(t); } hero.Recount(); if (hero.Count > 0) { var th = TownHall.Find(); using (var bmp = Screenshot.Capture(true)) { Visualize.RectangleT(bmp, th.Location); Visualize.RectangleT(bmp, new RectangleT((int)snipePoint.Item.X, (int)snipePoint.Item.Y, 1, 1)); var d = DateTime.UtcNow; Screenshot.Save(bmp, $"Snipe Deploy_{d.Year}-{d.Month}-{d.Day}_{d.Hour}-{d.Minute}-{d.Second}"); } } yield return(5000); Deploy.WatchHeroes(new List <DeployElement> { hero }); var countdown = new Countdown(15.0); if (hero.Count < 1) { while (countdown.IsRunning) { if (Attack.SurrenderIfWeHaveAStar()) { yield break; } else { yield return(200); } } } else { Log.Info("[Snipe Deploy] Hero failed to deploy; trying to use troops"); } } var snipeTroops = troops.GetByAttackType(AttackType.Damage) .GetByType(DeployElementType.NormalUnit) .Where(u => u.UnitData?.TargetType == TargetType.Loot || u.UnitData?.TargetType == TargetType.None) .ToArray(); if (snipeTroops.Length > 0) { Log.Info("[Snipe Deploy] Deploying troops to snipe."); var countdown = new Countdown(15.0, true); var pt = new Container <PointFT> { Item = GetTownHallDeployPoint() }; while (true) { if (countdown.IsFinished) { foreach (var t in Deploy.AtPoint(snipeTroops, snipePoint)) { yield return(t); } snipeTroops.Recount(); if (snipeTroops.All(u => u.Count < 1)) { yield break; } countdown.Restart(); } if (Attack.SurrenderIfWeHaveAStar()) { yield break; } } } }
/// <summary> /// Check to see how many collector and mine near to the redline by user defined distance /// </summary> /// <param name="userDistance">Minimum distance for exposed colloctors and mines</param> /// <param name="minCollectors">minimum exposed collectors</param> /// <param name="minMines">minimum exposed mines</param> /// <param name="AttackName">Attack name for logs and debugging</param> /// <param name="debug">debug mode in advanced settings</param> /// <returns>true if matches user defined min collectores and mines</returns> public static bool IsBaseMinCollectorsAndMinesOutside(int userDistance, int minCollectors, int minMines, string AttackName, int debug) { var distance = userDistance * userDistance; var redPoints = GameGrid.RedPoints.Where( point => !(point.X > 18 && point.Y > 18 || point.X > 18 && point.Y < -18 || point.X < -18 && point.Y > 18 || point.X < -18 && point.Y < -18)); collectors = ElixirCollector.Find().Where(c => c.Location.GetCenter() .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter())) .FirstOrDefault()) <= distance); mines = GoldMine.Find().Where(c => c.Location.GetCenter() .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter())) .FirstOrDefault()) <= distance); drills = DarkElixirDrill.Find().Where(c => c.Location.GetCenter() .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter())) .FirstOrDefault()) <= distance); int collectorsCount = collectors != null?collectors.Count() : 0; int minesCount = mines != null?mines.Count() : 0; int drillsCount = drills != null?drills.Count() : 0; // Set total count of targets SmartFourFingersDeploy.TotalTargetsCount = collectorsCount + minesCount + drillsCount; // four corners var top = new PointFT((float)GameGrid.DeployExtents.MaxX + 1, GameGrid.DeployExtents.MaxY + 4); var right = new PointFT((float)GameGrid.DeployExtents.MaxX + 1, GameGrid.DeployExtents.MinY - 4); var bottom = new PointFT((float)GameGrid.DeployExtents.MinX - 1, GameGrid.DeployExtents.MinY - 4); var left = new PointFT((float)GameGrid.DeployExtents.MinX - 1, GameGrid.DeployExtents.MaxY + 4); SetCore(); var corners = new List <Tuple <PointFT, PointFT> > { new Tuple <PointFT, PointFT>(top, right), new Tuple <PointFT, PointFT>(bottom, right), new Tuple <PointFT, PointFT>(bottom, left), new Tuple <PointFT, PointFT>(top, left) }; // loop throw the 4 sides and count targets on each side var targetsAtLine = new List <int>(); foreach (var l in corners) { var colCount = collectors.Where(t => t.Location.GetCenter(). IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0; var minCount = mines.Where(t => t.Location.GetCenter(). IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0; var drillCount = drills.Where(t => t.Location.GetCenter(). IsInTri(SmartFourFingersDeploy.Core, l.Item1, l.Item2))?.Count() ?? 0; var total = colCount + minCount + drillCount; targetsAtLine.Add(total); } SmartFourFingersDeploy.TargetsAtLine = targetsAtLine; var op = new Opponent(0); //if (!op.IsForcedAttack ) { Log.Info($"{AttackName} NO. of Colloctors & mines near from red line:"); Log.Info($"elixir colloctors is {collectorsCount}"); Log.Info($"gold mines is {minesCount}"); Log.Info($"----------------------------"); Log.Info($"sum of all is {collectorsCount + minesCount}"); if (debug == 1) { using (Bitmap bmp = Screenshot.Capture()) { using (Graphics g = Graphics.FromImage(bmp)) { foreach (var c in collectors) { var point = c.Location.GetCenter(); Visualize.Target(bmp, point, 30, Color.Purple); } foreach (var c in mines) { var point = c.Location.GetCenter(); Visualize.Target(bmp, point, 30, Color.Gold); } foreach (var c in drills) { var point = c.Location.GetCenter(); Visualize.Target(bmp, point, 30, Color.Black); } DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, top); DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, right); DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, bottom); DrawLine(bmp, Color.Red, SmartFourFingersDeploy.Core, left); } var d = DateTime.UtcNow; Screenshot.Save(bmp, "Collectors and Mines {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } } } if (collectorsCount >= minCollectors && minesCount >= minMines) { return(true); } else { Log.Warning($"{AttackName} this base doesn't meets Collocetors & Mines requirements"); return(false); } }
/// <summary> /// Check to see how many collector and mine near to the redline by user defined distance /// </summary> /// <param name="userDistance">Minimum distance for exposed colloctors and mines</param> /// <param name="minCollectors">minimum exposed collectors</param> /// <param name="minMines">minimum exposed mines</param> /// <param name="AttackName">Attack name for logs and debugging</param> /// <param name="debug">debug mode in advanced settings</param> /// <returns>true if matches user defined min collectores and mines</returns> public static bool IsBaseMinCollectorsAndMinesOutside(int userDistance, int minCollectors, int minMines, string AttackName, int debug) { var distance = userDistance * userDistance; var redPoints = GameGrid.RedPoints.Where( point => !(point.X > 18 && point.Y > 18 || point.X > 18 && point.Y < -18 || point.X < -18 && point.Y > 18 || point.X < -18 && point.Y < -18)); var collectors = ElixirCollector.Find().Where(c => c.Location.GetCenter() .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter())) .FirstOrDefault()) <= distance); var mines = GoldMine.Find().Where(c => c.Location.GetCenter() .DistanceSq(redPoints.OrderBy(p => p.DistanceSq(c.Location.GetCenter())) .FirstOrDefault()) <= distance); int collectorsCount = collectors != null?collectors.Count() : 0; int minesCount = mines != null?mines.Count() : 0; Log.Info($"{AttackName} NO. of Colloctors & mines near from red line:"); Log.Info($"elixir colloctors is {collectorsCount}"); Log.Info($"gold mines is {minesCount}"); Log.Info($"----------------------------"); Log.Info($"sum of all is {collectorsCount + minesCount}"); if (debug == 1) { using (Bitmap bmp = Screenshot.Capture()) { using (Graphics g = Graphics.FromImage(bmp)) { foreach (var c in collectors) { var point = c.Location.GetCenter(); Visualize.RectangleT(bmp, new RectangleT((int)point.X, (int)point.Y, 2, 2), new Pen(Color.Blue)); } foreach (var c in mines) { var point = c.Location.GetCenter(); Visualize.RectangleT(bmp, new RectangleT((int)point.X, (int)point.Y, 2, 2), new Pen(Color.White)); } } var d = DateTime.UtcNow; Screenshot.Save(bmp, "Collectors and Mines {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"); } } if (collectorsCount >= minCollectors && minesCount >= minMines) { return(true); } else { Log.Warning($"{AttackName} this base doesn't meets Collocetors & Mines requirements"); return(false); } }
public override IEnumerable <int> AttackRoutine() { List <Point> deployPoints = new List <Point>(); Logger.Info("[Attack-DeadBase] Now deploying main attack wave."); var analysisPoints = new List <Point>(); var mineRects = new List <Rectangle>(); var fiber = new Fiber <int>(DeployHelper.GenerateDeployPointsFromMines(analysisPoints, RedPoints, mineRects)); while (fiber.Run()) { yield return(1); } deployPoints.AddRange(analysisPoints); // Debug: show deploy points using (var frame = Screenshot.Capture(true)) { using (var g = Graphics.FromImage(frame)) { foreach (var p in RedPoints) { g.RectWithOutline(p.ToRectangle(2, 2), Color.Red); } foreach (var m in mineRects) { g.RectWithOutline(m, Color.DarkOrange); } foreach (var p in deployPoints) { g.RectWithOutline(p.ToRectangle(4, 4), Color.White); } foreach (var m in mineRects) { var closure = m; foreach (var closest in deployPoints.OrderBy(p => p.DistanceSq(closure.GetCenter())).Take(2)) { g.DrawLine(Pens.Red, m.GetCenter(), closest); } } } if (UserSettings.SaveAttackAnalysisImage) { Screenshot.Save(frame, $"AttackAnalysis_Dead {deployPoints.Count} points {RedPoints.Count} red"); } if (UserSettings.DisplayAttackAnalysisImage) { Screenshot.Show(frame); } } _deployPoints = deployPoints.ToArray(); if (_deployPoints == null) { throw new ArgumentNullException("deployPoints"); } if (_deployPoints.Length == 0) { throw new ArgumentException("deployPoints must contain at least one point"); } // Get outer border to move ranges towards there if possible List <Point> outerBorderPoints = DeployHelper.GetRectPoints(15); if (surrenderOnFirstStar) { Logger.Info("[Deploy] Bot will surrender as soon as the first star is reached to save troops (Trophy Push Mode)"); } var allDeployElements = Deploy.GetTroops(); var heroes = allDeployElements .Where(u => (UserSettings.UseKing && u.ElementType == DeployElementType.HeroKing) || (UserSettings.UseQueen && u.ElementType == DeployElementType.HeroQueen) || (UserSettings.UseWarden && u.ElementType == DeployElementType.HeroWarden)) .ToList(); int deployPointCounter = 0; int waveLimit = UserSettings.WaveSize; double waitTimeSeconds = UserSettings.WaveDelay; Random rng = new Random(); while (true) { Logger.Debug("Scan Troops"); // Scan available troops var units = Deploy.GetTroops() .Where(u => u.ElementType == DeployElementType.NormalUnit || (UserSettings.UseKing && u.ElementType == DeployElementType.HeroKing) || (UserSettings.UseQueen && u.ElementType == DeployElementType.HeroQueen) || (UserSettings.UseWarden && u.ElementType == DeployElementType.HeroWarden) || (UserSettings.UseClanTroops && u.ElementType == DeployElementType.ClanTroops)) .ToList(); // Remove king/queen ExtractHeroes(units, heroes); Logger.DebugDev("Deployable Troops: " + ToUnitString(units)); // Break if we don't have any left if (units.Count == 0 || units.All(u => u.Count == 0)) { break; } // Order units by priority // Tank > Wallbreaker > Heal > Damage > Heroes Logger.Debug("OrderTroops"); units.OrderForDeploy(); int waveCounter = 0; foreach (var u in units) { if (u == null) { Logger.Info("Wave #{0} complete, short deploy delay now...", waveCounter); yield return(rng.Next(900, 2000)); continue; } if (u.Count == 0) { continue; } // Select unit Logger.Debug("[Deploy] Deploying '{0}'", u); u.Select(); // Deploy them while (true) { int unitCount = u.Count; int totalDeployedThisWave = 0; while (unitCount > 0) { //var line = deployLines[lineCounter++ % deployLines.Length]; // //DeployHelper.ClickAlongLine(line.Item1, line.Item2, deployCount, 10); var deployCount = Math.Min(u.Count, 4); Logger.Debug("Deploy Start"); for (int i = 0; i < deployCount; i++) { if (surrenderOnFirstStar) { if (SurrenderIfWeHaveAStar()) { yield return(500); yield break; } } if (deployPointCounter >= _deployPoints.Length) { deployPointCounter = 0; } Logger.Debug("deploy at point index {0} of {1}", deployPointCounter, _deployPoints.Length); var point = _deployPoints[deployPointCounter++]; // If this unit is ranged, we deploy further back if (u.IsRanged) { var borderPoint = outerBorderPoints.OrderBy(p => p.DistanceSq(point)).First(); var distance = (int)Math.Sqrt(borderPoint.DistanceSq(point)); if (distance > 10) { var maxMove = Math.Min(u.UnitData.Range * 16, distance); var dir = borderPoint.Normalize(); // Clamp the distance to the max move distance so we dont deploy too far behind borderPoint = new Point((int)(dir.Item1 * maxMove) + point.X, (int)(dir.Item2 * maxMove) + point.Y); var t = (float)rng.Range(0.85, 1.05); point = point.Lerp(borderPoint, t); } } // Modify this point a bit so its not too ovbious point.X += rng.Next(-12, 12); point.Y += rng.Next(-12, 12); Input.Click(point); totalDeployedThisWave++; if (totalDeployedThisWave >= waveLimit) { Logger.Info("WaveLimit {0} reached. Wait {1:0.0} sec.", waveLimit, waitTimeSeconds); yield return((int)(waitTimeSeconds * 1000)); totalDeployedThisWave = 0; } Thread.Sleep(10); Thread.Sleep(5); } Logger.Debug("Deploy End"); unitCount -= deployCount; } // Refresh unit count, if its really 0, break. Logger.Debug("RecountA"); int countA = u.Count; u.Recount(); int countB = u.Count; Logger.Debug("RecountB"); if (countA != countB) { Logger.Info("Recount of '{0}'. {1}->{2}", u.PrettyName, countA, countB); } if (u.Count <= 0) { Logger.Info("Unit '{0}' depleted. Break.", u.PrettyName); yield return(500); break; } } waveCounter++; } yield return(50); } if (heroes.Count > 0) { foreach (var y in DeployHeroes(heroes, _deployPoints)) { if (surrenderOnFirstStar) { if (SurrenderIfWeHaveAStar()) { break; } } yield return(y); } } Logger.Info("[Deploy] Deploy done."); }
void CreateDebugImages() { List <InfernoTower> infernos = InfernoTower.Find(CacheBehavior.Default).ToList(); List <WizardTower> wizTowers = WizardTower.Find(CacheBehavior.Default).ToList(); List <ArcherTower> archerTowers = ArcherTower.Find(CacheBehavior.Default).ToList(); List <ElixirStorage> elixirStorages = ElixirStorage.Find(CacheBehavior.Default).ToList(); EagleArtillery eagle = EagleArtillery.Find(CacheBehavior.Default); var d = DateTime.UtcNow; var debugFileName = $"Dragon Deploy {d.Year}-{d.Month}-{d.Day} {d.Hour}-{d.Minute}-{d.Second}-{d.Millisecond}"; using (Bitmap canvas = Screenshot.Capture()) { Screenshot.Save(canvas, $"{debugFileName}_1"); //Draw some stuff on it. Visualize.Axes(canvas); Visualize.Grid(canvas, redZone: true); Visualize.Target(canvas, mainTarget.Center, 40, Color.Red); Visualize.Target(canvas, deFunnelPoints[0], 40, Color.White); Visualize.Target(canvas, deFunnelPoints[1], 40, Color.White); Visualize.Target(canvas, balloonFunnelPoints[0], 40, Color.Pink); Visualize.Target(canvas, balloonFunnelPoints[1], 40, Color.Pink); for (int i = 0; i < infernos.Count(); i++) { Visualize.Target(canvas, infernos.ElementAt(i).Location.GetCenter(), 30, Color.Orange); } for (int i = 0; i < airDefenses.Count(); i++) { Visualize.Target(canvas, airDefenses.ElementAt(i).Location.GetCenter(), 30, Color.Cyan); } for (int i = 0; i < wizTowers.Count(); i++) { Visualize.Target(canvas, wizTowers.ElementAt(i).Location.GetCenter(), 30, Color.Purple); } for (int i = 0; i < archerTowers.Count(); i++) { Visualize.Target(canvas, archerTowers.ElementAt(i).Location.GetCenter(), 30, Color.RosyBrown); } if (eagle != null) { Visualize.Target(canvas, eagle.Location.GetCenter(), 30, Color.YellowGreen); } Visualize.Target(canvas, mainTarget.DeployGrunts, 40, Color.Beige); Screenshot.Save(canvas, $"{debugFileName}_2"); } //Write a text file that goes with all images that shows what is in the image. StringBuilder sb = new StringBuilder(); for (int i = 0; i < airDefenses.Count(); i++) { sb.AppendLine($"Air Defense {i + 1} - Level:{airDefenses.ElementAt(i).Level}"); } for (int i = 0; i < infernos.Count(); i++) { sb.AppendLine($"Inferno Tower {i + 1} - Level:{infernos.ElementAt(i).Level}"); } for (int i = 0; i < wizTowers.Count(); i++) { sb.AppendLine($"Wizard Tower {i + 1} - Level:{wizTowers.ElementAt(i).Level}"); } for (int i = 0; i < archerTowers.Count(); i++) { sb.AppendLine($"Archer Tower {i + 1} - Level:{archerTowers.ElementAt(i).Level}"); } if (eagle != null) { sb.AppendLine($"Eagle Artillery 1 - Level:{eagle.Level}"); } //System.IO.File.WriteAllText($@"C:\RaccoonBot\Debug Screenshots\{debugFileName}_3.txt", sb.ToString()); Log.Info($"{Tag} Deploy Debug Image Saved!"); }