Example #1
0
        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);
            
        }
 public override GemColor GetColor(Gem gem)
 {
     if (Database.Count == 0) return GemColor.Unrecognized;
     Gem nearestGem = Database[0];
     int smallestDistance = Int32.MaxValue;
     foreach (Gem datagem in Database)
     {
         int dist = Histograms.GetDistance(gem.Histograms, datagem.Histograms);
         if (dist < smallestDistance)
         {
             smallestDistance = dist;
             nearestGem = datagem;
         }
     }
     gem.Inaccuracy = smallestDistance;
     return nearestGem.GemColor;
 }
Example #3
0
        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);
        }
Example #4
0
        internal static void Predict(Gem[,] grid)
        {
            for (int x = 0; x < 8; x++)
            {
                for (int y= 0; y < 8; y++)
                {
                    Gem originalMe = grid[x, y];
                    originalMe.SuggestedDirection = Direction.None;
                    originalMe.SuggestedPower = 0;
                    if (originalMe.IsUnmovable()) continue;
                    Point source = new Point(x, y);
                    foreach (Direction direction in Directions)
                    {
                        Point target = MoveInDirection(source, direction);
                        if (target.X < 0 || target.Y < 0 || target.X >= 8 || target.Y >= 8) continue;
                        Gem originalHim = grid[target.X, target.Y];
                        if (originalHim.IsUnmovable()) continue;
                        if (originalHim.GemColor == GemColor.Hypercube)
                        {
                            originalMe.SuggestedDirection = direction;
                            originalMe.SuggestedPower = 3;
                            break;
                        }
                        
                        // Test switch
                        grid[x, y] = originalHim;
                        grid[target.X, target.Y] = originalMe;

                        int i = target.X - 1;
                        int j = target.Y;
                        int left = 0;
                        int right = 0;
                        int up = 0;
                        int down = 0;
                        while (i >= 0 && grid[i, j].GemColor == originalMe.GemColor) { i--; left++; }
                        i = target.X + 1;
                        while (i < 8 && grid[i, j].GemColor == originalMe.GemColor) { i++; right++; }

                        int leftRightPower = left + 1 + right;
                        if (leftRightPower >= 3 && leftRightPower > originalMe.SuggestedPower)
                        {
                            originalMe.SuggestedDirection = direction;
                            originalMe.SuggestedPower = leftRightPower;
                        }

                        i = target.X;
                        j = target.Y - 1;
                        while (j >= 0 && grid[i,j].GemColor == originalMe.GemColor) { j--; up++; }
                        j = target.Y + 1;
                        while (j < 8 && grid[i, j].GemColor == originalMe.GemColor) { j++; down++; }

                        int upDownpower = up + 1 + down;
                        if (upDownpower >= 3 && upDownpower > originalMe.SuggestedPower)
                        {
                            originalMe.SuggestedDirection = direction;
                            originalMe.SuggestedPower = upDownpower;
                        }

                        // Back to normal
                        grid[x, y] = originalMe;
                        grid[target.X, target.Y] = originalHim;
                    }
                }
            }
        }
Example #5
0
 private void TeachFirst()
 {
     if (KnowledgeBase.TeachingQueue.Count > 0)
     {
         TaughtGem = KnowledgeBase.TeachingQueue[0];
         UpdateUI();
     }
     else
     {
         TaughtGem = null;
         this.pictureboxTeaching.Image = new Bitmap(112, 112);
         UpdateUI();
     }
 }
 public override GemColor GetColor(Gem gem)
 {
     return GemColor.Unrecognized;
 }
 public abstract GemColor GetColor(Gem gem);