public override void Tick(MegajewelForm form) { ticksMissed++; if (ticksMissed < 5) { return; } ticksMissed = 0; var grid = form.Processing.Grid; List <Gem> bestGems = new List <Gem>(); int bestPower = 1; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Gem gem = grid[x, y]; if (gem.SuggestedPower == bestPower) { bestGems.Add(gem); } else if (gem.SuggestedPower > bestPower) { bestPower = gem.SuggestedPower; bestGems.Clear(); bestGems.Add(gem); } } } if (bestGems.Count > 0) { Gem randomBestGem = bestGems[rgen.Next(bestGems.Count)]; Point from = new Point(randomBestGem.X, randomBestGem.Y); Point to = Predictor.MoveInDirection(from, randomBestGem.SuggestedDirection); Point fromReal = form.CurrentMode.GetGemCenter(from.X, from.Y); Point toReal = form.CurrentMode.GetGemCenter(to.X, to.Y); Controller.MoveTo(fromReal.X, fromReal.Y); Controller.HoldLeft(); Controller.MoveTo(toReal.X, toReal.Y); Controller.ReleaseLeft(); } }
public override void Tick(MegajewelForm form) { if (form.Processing.DiamondMineCleared) { return; } var grid = form.Processing.Grid; List <Gem> bestGems = new List <Gem>(); for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Gem gem = grid[x, y]; if (gem.SuggestedPower >= 3) { bestGems.Add(gem); } } } if (bestGems.Count > 0) { foreach (Gem randomBestGem in bestGems) { Point from = new Point(randomBestGem.X, randomBestGem.Y); Point to = Predictor.MoveInDirection(from, randomBestGem.SuggestedDirection); Point fromReal = form.CurrentMode.GetGemCenter(from.X, from.Y); Point toReal = form.CurrentMode.GetGemCenter(to.X, to.Y); Controller.MoveTo(fromReal.X, fromReal.Y); Controller.HoldLeft(); Controller.MoveTo(toReal.X, toReal.Y); Controller.ReleaseLeft(); } } }
public void Process(Bitmap fullScreenshot) { Mode mode = Form.CurrentMode; Bitmap field = fullScreenshot.Clone(mode.GetField(), fullScreenshot.PixelFormat); if (Form.CurrentMode.GetType() == typeof(DiamondMine)) { Bitmap cleared = fullScreenshot.Clone(new Rectangle(582, 788, 875, 6), fullScreenshot.PixelFormat); Color averageColor = Histograms.GetAverageColor(cleared); if (averageColor.R >= 200 && averageColor.G >= 200) { DiamondMineCleared = true; DiamondMineLastCleared = DateTime.Now; } else { if (DiamondMineLastCleared.AddSeconds(1) < DateTime.Now) { DiamondMineCleared = false; } } cleared.Dispose(); } // Update Grid from image for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Bitmap thisGem = field.Clone(new Rectangle(x * 112, y * 112, 112, 112), field.PixelFormat); Grid[x, y] = new Gem(GemColor.Unrecognized, thisGem, x, y); } } // Recognize for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { Grid[x, y].GemColor = Form.RecognitionStrategy.GetColor(Grid[x, y]); } } // Find options Predictor.Predict(Grid); // Update Field Image if (Form.pictureBoxField.Image != null) { Form.pictureBoxField.Image.Dispose(); } Form.pictureBoxField.Image = field; // Update Grid based on Grid Action a = () => { Form.pictureBoxGrid.Refresh(); }; Form.pictureBoxGrid.Invoke(a); }